Fire TV Status

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
DanM
Posts: 79
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Fire TV Status

Post 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

Loky31
Posts: 40
Joined: Monday 11 March 2019 13:46
Target OS: -
Domoticz version:
Contact:

Re: Fire TV Status

Post 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
alanlsmith
Posts: 132
Joined: Monday 07 August 2017 17:17
Target OS: Linux
Domoticz version: Latest β
Location: Near London (Saaarf!)
Contact:

Re: Fire TV Status

Post 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
Domoticz Latest β, RPi 4B with 110Gb SSD for Domoticz, RPi 4B with 110Gb SSD for Node-Red & a RPi 2B for logging / IP addressing. RFXCOM, PiZiGate, Z-Wave, Harmony, Hue lamps and a bit of Broadlink.
Loky31
Posts: 40
Joined: Monday 11 March 2019 13:46
Target OS: -
Domoticz version:
Contact:

Re: Fire TV Status

Post 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 :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest