Example Custom Commands #194
joshuar
started this conversation in
Show and tell
Replies: 2 comments
-
|
Here is a example script that can create a swich in Home Assistant that turns on or off a service in the user's session. Requires systemd configured with the linger option (see the FAQ for how to enable lingering). The script: #!/bin/bash
if [ "$1" = "ON" ]; then
systemctl --user start tmux
fi
if [ "$1" = "OFF" ]; then
systemctl --user stop tmux
fi
if [ "$(systemctl --user is-active tmux)" = "active" ]; then
echo ON
else
echo OFF
fiThe configuration in [[switch]]
name = "Toggle Tmux Service"
exec = "/path/to/toggle-tmux.sh" |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Here's one I just put together. It's a command to turn on/off an HDMI display with CEC. #!/bin/env bash
# Usage:
# - cec_swich.sh on # Turn on the HDMI display
# - cec_swich.sh off # Turn on the HDMI display
set -e
# To find the device id, run `echo 'scan' | cec-client -s -d 1`
DEVICE="0"
ACTION="$(echo $1 | tr '[:upper:]' '[:lower:]')"
send () {
echo "$1" | cec-client -s -d 1
}
STATE="$(send "pow $DEVICE" | grep "power status" | awk '{ print $3 }')"
if [[ "$ACTION" == "on" ]]; then
echo "Turning display on..."
if [[ "$STATE" != "$ACTION" ]]; then
send "on $DEVICE" # turn on
sleep 7 # cope with the device coming back form standby
fi
send "as" # set active source
elif [[ "$ACTION" == "off" ]]; then
if [[ "$STATE" == "off" ]]; then
echo "Display is already off."
else
echo "Turning display off..."
send "standby $DEVICE" # go into standby
fi
else
echo "Unknown action"
exit 1
fi
echo "$ACTION"
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey folks,
Use this topic to share examples of custom commands you have configured in the agent!
Beta Was this translation helpful? Give feedback.
All reactions