Skip to content

Instantly share code, notes, and snippets.

@mfakane
Last active February 13, 2020 15:21
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 mfakane/fa577cb351e1b4d1cf4a29b63c1f3ea2 to your computer and use it in GitHub Desktop.
Save mfakane/fa577cb351e1b4d1cf4a29b63c1f3ea2 to your computer and use it in GitHub Desktop.
BRAVIA の HTTP API を使って外部信号入力がないときに自動電源オフ (HDMI 以外のことは全く考慮してないので注意)
#!/bin/sh
# Get external input states
input_statuses=$(./bravia-cmd.sh avContent getCurrentExternalInputsStatus 105 '[]' 1.1 | jq -c '.result[][]')
while IFS= read -r input; do
if [[ $(echo $input | jq -r '.status') = 'true' ]]; then
# When input signal is detected
uri=$(echo $input | jq -r '.uri')
current_input=$(./bravia-cmd.sh avContent getPlayingContentInfo 103 '[]' 1.0)
# Do nothing when any app is active
[[ $(echo $current_input | jq 'has("error")') = 'true' ]] && exit
# Do nothing when this input is active
[[ $(echo $current_input | jq ".result[].uri | contains(\"$uri\")") != 'false' ]] && exit
# Switch to this input
./bravia-cmd.sh avContent setPlayContent 101 "[{\"uri\": \"$uri\"}]" 1.0
exit
fi
done <<< "$input_statuses"
# Shutdown the TV when no signals are detected
./bravia-cmd.sh system setPowerStatus 55 '[{ "status": false }]' 1.0 > /dev/null
#!/bin/sh
bravia="192.168.0.7"
psk="0000"
json=$(cat << EOS
{
"method": "$2",
"id": $3,
"params": $4,
"version": "$5"
}
EOS
)
curl \
-H "X-Auth-PSK: $psk" \
-H 'Content-Type: application/json' \
-d "$json" \
-sS "http://$bravia/sony/$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment