Last active
December 24, 2017 13:20
-
-
Save hfreire/fecd111c2e4a57c1839c to your computer and use it in GitHub Desktop.
Power on/off your TV through your Raspberry PI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CECCLIENT=$(which cec-client) | |
power_on () { | |
echo "on 0" | $CECCLIENT -s -d 1 >/dev/null | |
} | |
power_off () { | |
echo "standby 0" | $CECCLIENT -s -d 1 >/dev/null | |
} | |
is_powered_on () | |
{ | |
echo "pow 0" | $CECCLIENT -s | grep "TV (0): power status changed from 'unknown' to 'on'" >/dev/null | |
} | |
case $1 in | |
stop) | |
power_off | |
;; | |
start) | |
is_powered_on || power_on | |
;; | |
status) | |
if is_powered_on | |
then | |
echo "TV is powered on" | |
else | |
echo "TV is powered off" | |
fi | |
;; | |
*) | |
echo "Usage: $0 start|stop|status" >&2 && exit 2 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment