Hey all!
I wanted to share with you my goals and setup attempts and what I ended up with. I got an Echo Dot for Christmas and as a result I’ve been having fun with Alexa commands and what I can get away with doing hands-free. This lead me to purchase a Harmony Hub and trying to tie the Harmony skill together with Alexa. I should have known better, given prior experience with Harmony remotes forcing me to use “Activities” and the limited customization options you have in their app. Its seemed that not much has changed with the Hub, but nonetheless, I’ve overcome some limitations.
One limitation was I hated that I could not say “Alexa, pause the TV.” I know I could do simple ones like “Alexa, turn on/off the TV” but beyond those, you’d have to say “Alexa, ask Harmony to X/Y/Z/”. To me, that’s clunky and it was a bit sluggish.
Also, Harmony activities get easily out of sync when Televisions get turned off manually, or when they go into standby mode on their own. Because Harmony app will not let me add/remove certain power on/off device commands in an attempt to use it, I abandoned using Harmony App to control TV state or input state, and pushing down simple commands to HA. I’ve also managed to solve my TV state issue along the way.
My environment:
- HA running in a Ubuntu Server VM hosted in ESXi.
- Raspberry Pi 3 purchased later running Retro Pie connected to my TV (important in a moment)
- Harmony Hub
My goal was to remove the harmony remote platform from my HA config and instead, find a way to make command line switches to Turn on or off the TV, regardless of what state Harmony “thought” the TV was in.
I ended up downloading a node package called harmonyHubCLI that did just that
(https://www.npmjs.com/package/harmonyHubCLI)
switch:
back_room_tv:
friendly_name: Back Room TV
command_on: "node /usr/lib/node_modules/harmonyHubCLI/harmonyHubCli.js -l 192.168.1.20 -d 'Vizio TV' -c 'PowerOn'"
command_off: "node /usr/lib/node_modules/harmonyHubCLI/harmonyHubCli.js -l 192.168.1.20 -d 'Vizio TV' -c 'PowerOff'"
As you can discern, this package can support multiple harmony hubs via IP address and send specific commands to the device of your choosing. So while I could have gotten an IR blaster and scrounged up IR Codes, since I’d already bought this thing, I’m able to still use the “good” parts of the Harmony Hub…
This left me with a switch that I could always hit “on” or always hit “off” to send the codes. However, I was unable to determine state reliably, but at least send the commands. Around that time is then when I grabbed a Raspberry Pi 3 for fun and hooked it up to the same thing. I started reading about hdmi_cec on HA, and while I could technically run that on the Pi instead of my VM, I didn’t feel like migrating everything over, and would rather the Pi just be an emulator appliance… This meant I couldn’t natively use the hdmi_cec, however I ended up writing a ssh script:
#!/bin/bash
status=`ssh [email protected] "echo 'pow 0' | cec-client -s -d 1" | grep "power status"`
echo "$status"
if [ "$status" == "power status: on" ]; then
exit 0
else
exit 1
fi
The only configuration I had to do on the Pi, was to install cec-client, and establish trusted ssh between my HA Ubuntu instance and the Pi. This quick and dirty script basically asks the Pi for the Power Status of the TV on the CEC chain so that it can determine state which I added to my yaml like this:
command_state: /home/mike/checkCec.sh
I should add that in conjunction with the Phillips Hue Emulator, I’m able to completely remove the Harmony Skill, and still be able to say “Alexa, turn off Back Room TV” just fine.
So I took this a step further, and wanted to be able to pause TV when I ran in the kitchen, so I made a switch called “Pause Den” so I can say “Alexa, turn on Pause Den” or “Alexa, turn off Pause Den”. The commands are similar to power on and off:
pause_den:
friendly_name: Pause Den TV
command_on: "node /usr/lib/node_modules/harmonyHubCLI/harmonyHubCli.js -l 192.168.1.26 -d 'Xfinity DVR' -c 'Pause'"
command_off: "node /usr/lib/node_modules/harmonyHubCLI/harmonyHubCli.js -l 192.168.1.26 -d 'Xfinity DVR' -c 'Play'"
Finally, I wanted to be able to tune to certain channels without using the Harmony skill or App, so I toyed with the input_select options and came up with this:
input_select:
back_room_channels:
name: Channels
options:
- -- Select --
- NBC
- CNN
- ABC
- TMC
initial: -- Select --
den_channels:
name: Channels
options:
- -- Select --
- NBC
- CNN
- ABC
- TMC
initial: -- Select --
Next, I made 2 shell_commands:
back_room_channel: "/home/mike/changeChannel.sh {{states('input_select.back_room_channels')}} 192.168.1.20"
den_channel: "/home/mike/changeChannel.sh {{states('input_select.den_channels')}} 192.168.1.26"
I then made an automation to fire the commands based on input selects changing:
- alias: Change Channel Back Room
trigger:
- platform: state
entity_id: input_select.back_room_channels
action:
service: shell_command.back_room_channel
- alias: Change Channel Den
trigger:
- platform: state
entity_id: input_select.den_channels
action:
service: shell_command.den_channel
And this is what my amateur shell script looks like:
#!/bin/bash
channel=$1
hub=$2
commands=[
if [ "$channel" == "NBC" ]; then channel=805; fi
if [ "$channel" == "ABC" ]; then channel=803; fi
if [ "$channel" == "CNN" ]; then channel=849; fi
if [ "$channel" == "AMC" ]; then channel=825; fi
for (( i=0; i<${#channel}; i++ )); do
digit="${channel:$i:1}"
commands=$commands$sep\"$digit\"
sep=,
done
commands=$commands]
if [ "$channel" != "-- Select --" ]; then
echo $commands
echo "Switching to channel $channel"
# node /usr/lib/node_modules/harmonyHubCLI/harmonyHubCli.js -l "$hub" -d 'Xfinity DVR' -c 'Exit'
node /usr/lib/node_modules/harmonyHubCLI/harmonyHubCli.js -l "$hub" -d 'Xfinity DVR' -c "$commands" -m >> /home/mike/channelLog.txt
node /usr/lib/node_modules/harmonyHubCLI/harmonyHubCli.js -l "$hub" -d 'Xfinity DVR' -c 'OK' >> /home/mike/channelLog.txt
echo Channel:$1 Host:$2 \
>> /home/mike/channelLog.txt
fi
So if you made it this far and wondered what the completed product looks like (along with some other junk), here’s what it looks like in HA, now:
PS, there’s a lot of other stuff going on in this tabs like Activating the HDMI inputs etc, but the concept is the same.
Hope this is helpful to folks!