Skip to content

Instantly share code, notes, and snippets.

@henrik
Last active August 6, 2023 23:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrik/7d8123d8fe0a84fa7f69cbc5a90574a6 to your computer and use it in GitHub Desktop.
Save henrik/7d8123d8fe0a84fa7f69cbc5a90574a6 to your computer and use it in GitHub Desktop.

Example of toggling between two inputs on a Sony Bravia TV.

E.g. a Mac Mini HTPC on HDMI 1 and a Nintendo Switch on HDMI 2.

You're assumed to have set up a pre-shared key (PSK) per https://github.com/breunigs/bravia-auth-and-remote/.

It assumes it can call send_sony_tv_command.sh. Change the path if needed.

Example usage:

~/Library/Scripts/sony_tv_toggle_input.sh 192.168.0.131 0000
#!/bin/sh
set -e
if [ "$1" = "" ] || [ "$2" = "" ] ; then
echo "Usage: $0 <TV_IP> <PSK>"
exit 1
fi
# https://gist.github.com/henrik/32bb3b037b728b81a560d3676c7cfcf7
hdmi1="AAAAAgAAABoAAABaAw=="
hdmi2="AAAAAgAAABoAAABbAw=="
# https://pro-bravia.sony.net/develop/integrate/rest-api/spec/service/avcontent/v1_0/getPlayingContentInfo/index.html
status=$(curl --silent -H "X-Auth-PSK: $2" -XPOST http://$1/sony/avContent -d '{"method": "getPlayingContentInfo","id": 1, "params": [],"version": "1.0"}')
if [[ "$status" == *"hdmi?port=1"* ]]; then
~/Library/Scripts/send_sony_tv_command.sh "$1" "$hdmi2"
else
~/Library/Scripts/send_sony_tv_command.sh "$1" "$hdmi1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment