As I just have the Amazon FireTV as my Only Media Player in my House I got the need of controlling this device from openHAB. As it turns out, this isn’t as difficult as it seems.
Interesting: when I execute the shell script via Putty, the command line says that it can connect to the FireTV. But thats all, nothing happens! I’m also confused about the different behaviour when I execute these commands directly via Putty:
first command: sudo adb connect firetv-office:5555
after connect: sudo adb shell input keyevent KEYCODE_POWER
After that my FireTV responds. What the hell is going on here?
If entries like that are there, maybe i would start with with a command that is easier to track. Like start a stream and use keyevent 85 to pause the stream.
BTW here is the script “fire-control.sh” i use that can be fed parameters:
#!/bin/bash
#works without next line, dunno what it's good for
#adb tcpip 5555
adb connect YOUR-FIRETV-IP-OR-DNSNAME-HERE:5555
adb shell input keyevent $1
adb disconnect
can be called like so with any keycode you fancy:
executeCommandLine("/etc/openhab2/scripts/fire-control.sh 85")//85=code for play/pause
I have a guess. Ive been tinkering alot with android devices, and i would suspect that you need to install ADB drivers for windows to recognize the adb command. You can either get it official or the easy way by downloading adb drivers
I dont know if this is the issue but hey, it might
I figured this one out - just navigate to the folder of you.sh file and execute
sudo chmod +x fire-control.sh (or whatever your file name is), to grant execute rights.
My problem is that navigation is ppiiiiiiig slow
The server component provides a rest interface for controlling as well as getting the state. The state portion seems to be broken on my version of Fire OS as it will only return “play” unless I am sitting at the home screen, then it will return “standby”.
I did that and it did not resolve it. I ran sudo visudo and added some privileges to the openhab user, rebooted and it worked!
I don’t have too many speed issues, it’s not very snappy, but very tolerable. I’m using a fireTV connected via Ethernet, not wifi. Maybe that helps. Maybe it has to do with the script making a connection each time it’s called. Maybe there’s a way to test if there is a connection and then send the command? If no connection, then connect and keep the connection.
@BulletProofFool1 try this script and see if it speeds up your commands. It checks for a connection based on the name of the firetv connection string($2) and establishes a connection if it doesn’t exist. I don’t know if there is a downside to maintaining the connection between OH and the firetv. Maybe someone else can comment on that.
#!/bin/bash
#adb tcpip 5555
#echo $1 the command
#echo $2 the connection string
con=$(adb devices | grep $2 -c -i)
#echo "con count" $con
if [ "$con" = "0" ]
then
adb connect $2
fi
adb shell input keyevent $1
Here’s a modified version of the shell script if you have more than one firetv/adb connection:
is now returning the proper case of the connection name(prior ADB seemed to convert connection names to lowercase regardless of input string), so feeding the correct case for the connection name is required when sending a command.
I tested it on windows, no problems at all. But I am running OpenHAB on a synology NAS, where adb is not available. I tried to install it with ipkg, but there is no package for adb. Does anyone run adb with openhab on a NAS?
I try to open kodi in a script. It works if I execute the line
[12:10:13] openhabian@openHABianPi:~$ adb shell am start -n org.xbmc.kodi/.Splash
but when I put in a shell:
adb connect 192.168.2.34:5555
adb shell am start -n org.xbmc.kodi/.Splash
adb disconnect
I get the error
[12:09:57] openhabian@openHABianPi:~$ /etc/openhab2/scripts/StartFireTV2.sh
connected to 192.168.2.34:5555
}arting: Intent { cmp=org.xbmc.kodi/.Splash
Error type 3
} does not exist.lass {org.xbmc.kodi/org.xbmc.kodi.Splash
I found that it was possible to start what ever application by first running
adb shell pm list packages -f
and search for the app and launch it by
shell monkey -p com.spotify.tv.android 1
however, if I use a shell
adb connect 192.168.2.34:5555
adb shell monkey -p org.xbmc.kodi 1
adb disconnect
I just get an error
[18:03:12] openhabian@openHABianPi:~$ /etc/openhab2/scripts/StartFireTV2.sh
connected to 192.168.2.34:5555
** Error: Count is not a number
My problems was cause by me using notepad as text editor. By using Notepad++ and doing
settings->preferences
new document / default directory tab
select the format as unix and close
create a new document and enter the script
Very interesting post.
Originally I was looking for a way to get the currently playing video on the fire stick, but with these commands doesn’t seem to possible.
Do you know a different way to let OH know what the fire stick is currently playing?