Control your Amazon Fire TV (or every Android Device) from openHAB

my firetv/kodi command/notification implementation in jsr223




This seems to be working for me for the most part, however, I am trying to setup a rule to automatically show my ring doorbell feed on my firetv when the doorbell is pressed.

So far, I figured that com.amazon.cardinal seems to be the process used on the firetv but not sure how to launch this with my ring feed automatically. Any ideas?

Perfect - thanks

Written a script that does keycodes and app launching combining concepts from posts 5

and 16
Control your Amazon Fire TV (or every Android Device) from openHAB - #16 by patrikpatrik2.

FireTV_ADB.sh:

#!/bin/bash

# Concept From: https://community.openhab.org/t/control-your-amazon-fire-tv-or-every-android-device-from-openhab/17259/5
# and https://community.openhab.org/t/control-your-amazon-fire-tv-or-every-android-device-from-openhab/17259/16
# Can be called like so with any keycode you fancy, multiple keycodes work too:
# executeCommandLine("/etc/openhab2/scripts/FireTV_ADB.sh 85") //85=code for play/pause
# and to start app:
# executeCommandLine("/etc/openhab2/scripts/FireTV_ADB.sh com.simplona.vpn.proxy.server.fire.tablets.tv 1"
#
# DPAD_CENTER:          23
# DPAD_DOWN:            20
# DPAD_LEFT:            21
# DPAD_RIGHT:           22
# DPAD_UP:              19
# BACK:                 4
# MENU:                 82
# MEDIA_REWIND:         89
# MEDIA_PLAY_PAUSE:     85
# MEDIA_FAST_FORWARD:   90
# MUTE:                 91
# PAIRING:              225
# HOME:                 3

device="192.168.XXX.XXX:5555"

if [[ -z $1 ]]; then
        echo "Need Arguments to Function"
else
        adb connect ${device} >/dev/null 2>&1
fi

length=${#1}
sleep 1
if [[ ${length} -lt 5 ]]; then
        adb shell input keyevent $@ >/dev/null 2>&1
elif [[ ${length} -ge 5 ]]; then
        adb shell monkey -p $1 1 >/dev/null 2>&1
fi

adb disconnect >/dev/null 2>&1

and a rule to start my vpn for example:

rule "ADB VPN Start"
    when
        Item adb_VPN received update ON
    then
        var cmnd = "com.simplona.vpn.proxy.server.fire.tablets.tv"
        executeCommandLine("/etc/openhab2/scripts/FireTV_ADB.sh " + cmnd,3000)
        Thread::sleep(3000)
// down, enter and back.
        cmnd = "20 23 4"
        executeCommandLine("/etc/openhab2/scripts/FireTV_ADB.sh " + cmnd)
        adb_VPN.postUpdate("OFF")
end

Item definition:

Switch adb_VPN          "FireTV Start VPN [%s]"                         (fireTV)

I know Thread::sleep is not recommended, but I have so few rules it makes little difference to me. I will implement a proper timer when I get time. Hope this routine is helpful for others.

1 Like

Ok, added timer to the rule now, you might need to adjust the timeout length depending on how long the app takes to startup.

rule "ADB VPN Start"
    when
        Item adb_VPN received update ON
    then
        var cmnd = "com.simplona.vpn.proxy.server.fire.tablets.tv"
        executeCommandLine("/etc/openhab2/scripts/FireTV_ADB.sh " + cmnd)
        createTimer(now.plusSeconds(4), [|
                cmnd = "20 23 4"
                executeCommandLine("/etc/openhab2/scripts/FireTV_ADB.sh " + cmnd)
                adb_VPN.postUpdate("OFF")
        ])
end

Hey all you cool cats and kittens!
This has been a very useful thread. I have installed ADB on openhabian and connected to my fire stick. I can run several commands successfully from putty. I haven’t tried writing these into a script yet but that will come soon.

The power commands won’t turn it off (or standby or whatever it’s called when the remote powers off the screen)
adb shell input keyevent KEYCODE_POWER
adb shell input keyevent 26
Like I mentioned, other commands work fine including KEYCODE_SLEEP but that just turns the screen black, doesn’t turn it off.

If I press the power button on the remote to turn off the screen manually, I can later send other commands that will bring it back on, adb shell input keyevent 3 will power up and go to the home screen. KEYCODE_POWER will not turn it on.

Any reason why only the power commands don’t work? Any log for adb I can go look at? The putty command shows nothing.

As far as I’m aware the Fire TV/sticks don’t turn on or off, they just sleep? (not 100% sure on this?)

I’m also assuming that you have the fire stick with the power button and volume controls on the remote? Aren’t these just IR from the remote to the TV?

Powering the TV back on and to the correct channel should work because of CEC over the HDMI.

Some kind of smart IR blaster would allow you to send the power commands straight to the TV such as a Harmony Hub or a Broadlink RM Pro.

True it isn’t a full power off, but I don’t need that. Under settings there is a “sleep” that turns the screen black but the TV stays fully powered on. Pressing the “power” button on the remote powers off the TV. That’s what I am looking for.

Sending a adb shell input keyevent 3 will power on the TV and go to home. Just looking for a way to do the opposite, hopefully without more hardware.
Thanks!