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.
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.
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
Install the nfa app.
go get github.com/robbiet480/nfa
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
Install the Notifications for Fire/Android TV app on your device.
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."
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
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