Fire TV Status
Posted: Tuesday 08 May 2018 14:44
Hi,
Figured I'd share my fireTV status script. To run the script you need ADB tools installed as this is how the pi connects to the stick. It triggers a selector switch via curl so you need to alter the urls and the device IDs etc to make it work.
Figured I'd share my fireTV status script. To run the script you need ADB tools installed as this is how the pi connects to the stick. It triggers a selector switch via curl so you need to alter the urls and the device IDs etc to make it work.
Code: Select all
#!/bin/bash
adb kill-server
adb start-server
adb connect IP_OF_FIRETV
#I like to see the output when I run from the command line, helps to identify the IDs of new apps.
adb shell dumpsys activity recents |grep "Recent #0"
playing="$(adb shell dumpsys activity recents |grep "Recent #0")"
if [[ $playing = *"iplayer"* ]]; then
state="STATE_ON_IPLAYER"
fi
if [[ $playing = *"kodi"* ]]; then
state="STATE_ON_KODI"
fi
if [[ $playing = *"netflix"* ]]; then
state="STATE_ON_NETFLIX"
fi
if [[ $playing = *"disney"* ]]; then
state="STATE_ON_DISNEY"
fi
if [[ $playing = *"amazon.avod"* ]]; then
state="STATE_ON_AMAZON"
fi
if [[ $playing = *"launcher"* ]]; then
state="STATE_ON_LAUNCHER"
fi
adb shell dumpsys power | grep "Display Power"
playing="$(adb shell dumpsys power | grep "Display Power")"
if [[ $playing = *"state=OFF"* ]]; then
state="STATE_OFF"
fi
#This echo isnt needed but useful to keep track when running from command line.
echo $state
#Splitting the script into two like this doesnt do much in this implementation. It is done this way because I feed in other devices (such as the actual television power status) and have more complex logic than shown below.
case $state in
"STATE_ON_NETFLIX")
curl 'http://192.168.0.1:8080/json.htm?type=command¶m=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
"STATE_ON_LAUNCHER")
curl 'http://192.168.0.1:8080/json.htm?type=command¶m=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
"STATE_ON_AMAZON")
curl 'http://192.168.0.1:8080/json.htm?type=command¶m=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
"STATE_OFF")
curl 'http://192.168.0.1:8080/json.htm?type=command¶m=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
"STATE_ON_KODI")
curl 'http://192.168.0.1:8080/json.htm?type=command¶m=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
"STATE_ON_DISNEY")
curl 'http://192.168.0.1:8080/json.htm?type=command¶m=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
"STATE_ON_IPLAYER")
curl 'http://192.168.0.1:8080/json.htm?type=command¶m=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
esac
adb disconnect