I’ve been testing the fantastic Harmony component put together by @iandday and I felt I should put together a post explaining how to get started (please keep in mind that this component is still in beta) and how to configure it for a nice clean drop down menu to view and select your activity as well as use your activities in Automation.
Step 1:
Installation:
Install the required software:
(find the latest version of this software here: https://github.com/iandday/pyharmony/)
Create a temp folder on your HASS computer and download pyharmony.
wget https://github.com/iandday/pyharmony/archive/master.zip
Install this software using pip
sudo pip install master.zip
Download the latest copy of the component (requires subversion to be installed)
svn export https://github.com/iandday/home-assistant/trunk/homeassistant/components/remote
Copy this folder into your HASS components folder
cp -TRv ./remote /usr/local/lib/python3.4/dist-packages/homeassistant/components
Please note, this is the default path for components on a linux install. If you’re running in docker, HASSbian, or on a different OS, the path could be different.
Add the Remote Component into your configuration.yaml file using the following style (note, you can add multiple hubs but for now let’s just start with one)
remote:
- platform: harmony
name: Living Room TV
username: !secret email # The email address associated with your Harmony hub account
password: !secret pass # Your password
host: 192.168.1.127 #replace with the IP of your Hub. This can be found in the Harmony app under About, Versions.
port: 5222 # Default is 5222
activity: Plex Media Player # Optional, This is the name of the activity that will launch if you just power on the remote using the default device created in HASS.
Step 2
Configuration:
From here, go ahead and fire up Home Assistant. Assuming we’ve set up everything correctly, HASS should launch, and a new file should be created in your .homeassistant folder with the settings required for the next step of configuration. For me that file was ‘harmony_living_room_tv.conf’ as I named my hub ‘Living Room TV’. Go ahead and open that file. We need the activities section from the top specifically. Here’s what mine looks like:
Activities
20195208 - Xbox
19954855 - Playstation 3
-1 - PowerOff
16602559 - Steam Link
19575995 - Plex Media Player
19292022 - Airplay
13677570 - Wii U
Now let’s create an input_select to reflect these same options. You’ll want to ensure that every possible option is on your input_select.
input_select:
living_room_tv:
name: Living Room TV
options:
- Powered Off
- Plex Media Player
- Steam Link
- AirPlay
- Wii U
- Playstation 3
- Xbox
initial: Powered Off
icon: mdi:monitor
Next, we need to create a script for each of these activities to activate them.
script:
plex:
sequence:
- service: remote.turn_on
entity_id: remote.living_room_tv
data:
activity: "19575995"
steam:
sequence:
- service: remote.turn_on
entity_id: remote.living_room_tv
data:
activity: "16602559"
ps3:
sequence:
- service: remote.turn_on
entity_id: remote.living_room_tv
data:
activity: "19954855"
wiiu:
sequence:
- service: remote.turn_on
entity_id: remote.living_room_tv
data:
activity: "13677570"
xbox:
sequence:
- service: remote.turn_on
entity_id: remote.living_room_tv
data:
activity: "20195208"
airplay:
sequence:
- service: remote.turn_on
entity_id: remote.living_room_tv
data:
activity: "19292022"
tvoff:
sequence:
- service: remote.turn_off
entity_id: remote.living_room_tv
The scripts are quite straight forward. The service calls the specific hub to activate the activity by the number shown in the activities list in ‘harmony_living_room_tv.conf’. You can also use the name of the activity but the hub will be slower to respond. The only script that varies at all is ‘tvoff’ as that calls ‘remote.turn_off’ for obvious reasons.
Next we need to set up two sets of automations. The first set changes what is shown on the Input select when you change the activity using the Harmony Remote or other device. This simply watches for a state changes and updates the input_select. This technique can of course can be used in other automations as well, for example you could have HASS dim the lights when you start a specific activity
automation:
- alias: "Powered off from Harmony Hub"
trigger:
platform: state
entity_id: remote.living_room_tv
condition:
condition: template
value_template: '{{ trigger.to_state.attributes.current_activity == "PowerOff" }}'
action:
service: input_select.select_option
entity_id: input_select.living_room_tv
data:
option: "Powered Off"
- alias: "Plex started from Harmony Hub"
trigger:
platform: state
entity_id: remote.living_room_tv
condition:
condition: template
value_template: '{{ trigger.to_state.attributes.current_activity == "Plex Media Player" }}'
action:
service: input_select.select_option
entity_id: input_select.living_room_tv
data:
option: "Plex Media Player"
- alias: "Steam Link started from Harmony Hub"
trigger:
platform: state
entity_id: remote.living_room_tv
condition:
condition: template
value_template: '{{ trigger.to_state.attributes.current_activity == "Steam Link" }}'
action:
service: input_select.select_option
entity_id: input_select.living_room_tv
data:
option: "Steam Link"
- alias: "Wii U started from Harmony Hub"
trigger:
platform: state
entity_id: remote.living_room_tv
condition:
condition: template
value_template: '{{ trigger.to_state.attributes.current_activity == "Wii U" }}'
action:
service: input_select.select_option
entity_id: input_select.living_room_tv
data:
option: "Wii U"
- alias: "Airplay started from Harmony Hub"
trigger:
platform: state
entity_id: remote.living_room_tv
condition:
condition: template
value_template: '{{ trigger.to_state.attributes.current_activity == "Airplay" }}'
action:
service: input_select.select_option
entity_id: input_select.living_room_tv
data:
option: "AirPlay"
- alias: "Xbox started from Harmony Hub"
trigger:
platform: state
entity_id: remote.living_room_tv
condition:
condition: template
value_template: '{{ trigger.to_state.attributes.current_activity == "Xbox" }}'
action:
service: input_select.select_option
entity_id: input_select.living_room_tv
data:
option: "Xbox"
- alias: "PS3 started from Harmony Hub"
trigger:
platform: state
entity_id: remote.living_room_tv
condition:
condition: template
value_template: '{{ trigger.to_state.attributes.current_activity == "Playstation 3" }}'
action:
service: input_select.select_option
entity_id: input_select.living_room_tv
data:
option: "Playstation 3"
This last set will also trigger the automation even when selected from the input select which is good for automation. Selecting the same activity that’s already active on the Harmony Hub does not interrupt the activity and will allow you to add additional actions.
- alias: "Plex started from HASS"
trigger:
platform: state
entity_id: input_select.living_room_tv
to: 'Plex Media Player'
action:
service: script.turn_on
entity_id: script.plex
- alias: "Airplay started from HASS"
trigger:
platform: state
entity_id: input_select.living_room_tv
to: 'Airplay'
action:
service: script.turn_on
entity_id: script.airplay
- alias: "PS3 started from HASS"
trigger:
platform: state
entity_id: input_select.living_room_tv
to: 'Playstation 3'
action:
service: script.turn_on
entity_id: script.ps3
- alias: "Xbox started from HASS"
trigger:
platform: state
entity_id: input_select.living_room_tv
to: 'Xbox'
action:
service: script.turn_on
entity_id: script.xbox
- alias: "Wii U started from HASS"
trigger:
platform: state
entity_id: input_select.living_room_tv
to: 'Wii U'
action:
service: script.turn_on
entity_id: script.wiiu
- alias: "Steam Link started from HASS"
trigger:
platform: state
entity_id: input_select.living_room_tv
to: 'Steam Link'
action:
service: script.turn_on
entity_id: script.steam
- alias: "TV turned off from HASS"
trigger:
platform: state
entity_id: input_select.living_room_tv
to: 'Powered Off'
action:
service: script.turn_on
entity_id: script.tvoff
The final step is to simply add the input select to your groups. If everything has gone smoothly, you should have a drop down menu that looks and works like what I posted at the top of this post.
input_select.living_room_tv
Edit: Added the last set of automations required to make the input select work.