Skip to content

Instantly share code, notes, and snippets.

@hfreire
Last active December 24, 2017 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hfreire/fecd111c2e4a57c1839c to your computer and use it in GitHub Desktop.
Save hfreire/fecd111c2e4a57c1839c to your computer and use it in GitHub Desktop.
Power on/off your TV through your Raspberry PI
#!/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