Sending Notifications to Fire TV/Android TV

For a while I’ve been trying to find a way to send notifications to my Fire TV devices. Kodi is not always open, so that is not a good option. The best I found is an app, Notifications for Fire TV/Notifications for Android TV. It’s primary purpose is to mirror notifications received on an Android phone. I thought this was out as well since it would be a kludgy solution requiring extra hardware. Then I stumbled upon this Go command line app made to do exactly what I wanted.

This was tested with on Ubuntu 16.04 with a 1st and 2nd gen Fire TV box.

  1. Install Go. I used this guide with the latest stable version of Go. Only complete the first step at this point. We will set up the paths a little different.

  2. Rather than setting the Go path in my local ~/.profile, I set them in a new file at /etc/profile.d/nfa.sh so they would be available for all users. This is probably not necessary because OpenHAB still does not pick up the path and we will have to use the full path to the executable. We will need to use a different path for the workspace, however, due to where the nfa app expects the workspace to be.

    Set the paths as follows. You will need to log out and back in to pick up the changes.

    export GOPATH=$HOME/go
    PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
    
  3. Install the nfa app.

    go get github.com/robbiet480/nfa
    
  4. Copy the Go folder from your users home directory to the openhab home directory and fix the permissions.

    sudo cp -R ~/go /var/lib/openhab2/
    sudo chown -R openhab:openhab /var/lib/openhab2/go
    
  5. Install the Notifications for Fire/Android TV app on your device.

  6. At this point you can try sending a test notification from your shell.

    nfa notify -a <device ip> -t "OpenHAB" -m "This is a test."
    
  7. If the notification was successful, we can set up OH. Create a shell script to be called by OH.

    #!/bin/bash
    ~/go/bin/nfa notify -a 10.0.0.90 -t "OpenHAB" -m "$1" -d 5s -o top-right
    ~/go/bin/nfa notify -a 10.0.0.91 -t "OpenHAB" -m "$1" -d 5s -o top-right
    
  8. To send a notification from OH.

    executeCommandLine("/path/to/script/notifyFireTv.sh 'You're message here.'")
    

I would recommend pairing this with the separation of behaviors design pattern. I will update this post when I get that set up.

You can also parameterize more of the flags if you wish, but you will need to be careful since shell scripts take parameters based on position rather than name.

executeCommandLine("/path/to/script/notifyFireTv.sh 'Your message.' '10s'")
#!/bin/bash

# default message time if none is specified
time=5s
# if a time is specified, override the default
if [ ! -z "$2" ]
  then
    time="$2"
fi
~/go/bin/nfa notify -a 10.0.0.90 -t "OpenHAB" -m "$1" -d $time -o top-right
~/go/bin/nfa notify -a 10.0.0.91 -t "OpenHAB" -m "$1" -d $time -o top-right
6 Likes

Just wanted to say thanks a bunch for your detailed write up. I spent a good few hours tonight getting this to work on nub synology NAS with a Nvidia Shield, but wouldn’t have been that quick without this article.

Internet gold!

ftr, firetv/kodi command/notification implementation in jsr223




This works awesome, I am using it on a Windows box.
Thanks for the great instructions!

Hi,

thanks for this great tutorial. I’ve set it up quite easily with that. It also works quite well if I execute the notification via terminal but not in openhab.

my script at /etc/openhab2/scripts/sh/notifyAndroitTV_2.sh:

#!/bin/bash
~/go/bin/nfa notify -a 192.168.0.24 -t "SmartHome" -m "$1" -d 10s -o top-right

If I simply run it from terminal:

/etc/openhab2/scripts/sh/notifyAndroitTV_2.sh "Word1 Word2"

Everything works as expected. But if I want to run it via openhab, the second word seems to be passed as a second argument and i also see the ". I just see this on the Shield TV:

"Word1

This is my rules file:

rule "Test"
when
    Item CC_JBL_Mute changed from OFF to ON 
then
    executeCommandLine("/etc/openhab2/scripts/sh/notifyAndroitTV_2.sh 'Word1 Word2' ")
end

The Log shows this:

2019-04-06 15:06:40.895 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '/etc/openhab2/scripts/sh/notifyAndroitTV_2.sh 'Word1 Word2' '

I also tried this more direct rule line:

executeCommandLine("/home/openhabian/go/bin/nfa notify -a 192.168.0.24 -t \"SmartHome\" -m \"Word1 Word2\" -d 10s -o top-right")

This is the log:

2019-04-06 15:20:38.107 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '/home/openhabian/go/bin/nfa notify -a 192.168.0.24 -t "SmartHome" -m "Word1 Word2" -d 10s -o top-right'

But this leads to the wrong notifaction also. I use latest openhabian with openhab 2.4.0. Hope somebody can help me with this.

Thanks!

Hey,

unfortunatley I have the same issue.

In the terminal it works perfect, the rule or the execute binding will not trigger this. I really tried everything incl. start openhab as root.

Nothing works, that’s why I skipped this task.

I’m in OH2.4 with openhabian.

Jan

The issue reported here where people can make the notifications work from the command line but not from their rule has to do with how the the “executeCommandline” command needs to separate the command from its arguments. If you see here, you need to place @@ in place of spaces:

So when passing the command as originally in this tutorial, it will never work because OH is trying to execute the whole thing as a command.

If you take the original:

executeCommandLine("/path/to/script/notifyFireTv.sh 'Your message.' '10s'")

and modify it to pass the last two bits as arguments:

executeCommandLine("/path/to/script/notifyFireTv.sh@@Your message.@@10s")

this should work. I have a working example:

in my .rules:

executeCommandLine("/path/to/script/notifyFireTv.sh 'Your message.' '10s'")

my script

#!/bin/bash
# default message time if none is specified
time=10s
# if a time is specified, override the default
if [ ! -z "$2" ]
        then
                time="$2"
fi
 
/home/openhabian//work/bin/nfa notify -a 192.168.1.x -i /etc/openhab2/icons/classic/oh.jpg -o top-right -t "OpenHAB" -m "$1" -d "$time"

Really - if you look on this forum - there are tons of times where people can execute from command line and not from the rule. It is almost always either a permission issue or this @@ nomenclature. I’ve known this for a long time and I still get it wrong all the time. It always takes some playing with it to get it right.