Page 1 of 1

Fire TV Status

Posted: Tuesday 08 May 2018 14:44
by DanM
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.

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&param=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
"STATE_ON_LAUNCHER")
curl 'http://192.168.0.1:8080/json.htm?type=command&param=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
"STATE_ON_AMAZON")
curl 'http://192.168.0.1:8080/json.htm?type=command&param=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
"STATE_OFF")
curl 'http://192.168.0.1:8080/json.htm?type=command&param=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
"STATE_ON_KODI")
curl 'http://192.168.0.1:8080/json.htm?type=command&param=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
"STATE_ON_DISNEY")
curl 'http://192.168.0.1:8080/json.htm?type=command&param=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;
"STATE_ON_IPLAYER")
curl 'http://192.168.0.1:8080/json.htm?type=command&param=switchlight&idx=XXXXX&switchcmd=Set%20Level&level=XXX'
;;

esac

adb disconnect


Re: Fire TV Status

Posted: Sunday 22 September 2019 10:35
by Loky31
Hello,

Nice script to reflect firetv statuts 😉

Looking at thé script i guess it Is not intended to Control firetv, By any chance would you be able to show à command line that can Control thé firetv ?

What I'm Looking for Is à Way to wake it up and at least make a pause/play command on it.
It would be really great if you can give me a hand on that 😁
Many Thanks in avance

Re: Fire TV Status

Posted: Thursday 26 September 2019 10:43
by alanlsmith
This bash script will start a Fire TV box. 'keyevent' 26 is the command to wake it up. and the next line starts the BBC iPlayer (so can be ignored or changed to an app of your choice.

Code: Select all

#!/bin/bash

adb start-server && \
adb connect <IP address of Fire TV> && \
sleep 0.5 && \
adb shell input keyevent 26 && \
adb shell am start -n uk.co.bbc.iplayer/.BBCIPlayerActivity
sleep 0.5 && \
adb disconnect || exit 0
This one will put it into standby.

Code: Select all

#!/bin/bash

adb start-server && \
adb connect <IP address of Fire TV> && \
sleep 0.5
adb shell input keyevent 26 && \
sleep 0.5 && \
adb disconnect || exit 0
Here are some other commands:

UP = adb shell input keyevent 19
DOWN = adb shell input keyevent 20
LEFT = adb shell input keyevent 21
RIGHT = adb shell input keyevent 22
ENTER = adb shell input keyevent 66
BACK = adb shell input keyevent 4
HOME = adb shell input keyevent 3
MENU = adb shell input keyevent 1
MEDIA PLAY/PAUSE = adb shell input keyevent 85
MEDIA PREVIOUS = adb shell input keyevent 88
MEDIA NEXT = adb shell input keyevent 87

Re: Fire TV Status

Posted: Wednesday 30 October 2019 19:24
by Loky31
OMFG I din't saw your answer!!!!

Thank you so much! it just works like charm!!!
I was trying to use an addon since quite some time with no success ( :https://github.com/happyleavesaoc/python-firetv), you really got me where I needed :)