Skip to content

Instantly share code, notes, and snippets.

@thomaswitt
Created February 10, 2023 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaswitt/9aaf6a8b4b3e48535c2b1f5857bafc4e to your computer and use it in GitHub Desktop.
Save thomaswitt/9aaf6a8b4b3e48535c2b1f5857bafc4e to your computer and use it in GitHub Desktop.
Turn Sony Bravia TV on and off – To be used with EventScripts (https://www.mousedown.net/software/EventScripts.html)
#!/usr/bin/env bash
# Turn Sony Bravia TV on and off
# To be used with EventScripts (https://www.mousedown.net/software/EventScripts.html)
# Get Auth Cookie Script from https://github.com/breunigs/bravia-auth-and-remote.git
IP="0.0.0.0"
MACADDR="00:00:00:00:00:00"
COOKIE="output from https://github.com/breunigs/bravia-auth-and-remote/blob/master/auth_cookie_examples/auth.sh"
OWN_SSID="MY_SSID"
SSID=$(/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk -F' SSID: ' '/ SSID: / {print $2}')
if [ "${SSID}" = "${OWN_SSID}" ]; then
if [ "$1" = "Screen password unlocked" ]; then
echo "Switching on TV"
/opt/homebrew/bin/wakeonlan -i ${IP} ${MACADDR}
else
echo "Switching off TV"
curl -q --cookie "auth=${COOKIE}" -X POST http://${IP}/sony/system \
-d '{"id":55,"method":"setPowerStatus","version":"1.0","params":[{"status":false}]}'
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment