Logitech Harmony Integration with @iandday's component

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.

21 Likes

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.

When i put this in my config file HA wont boot, and i dont get any error logs in the log file.
Any ideas?

Can you paste the remote config again using the preformatted text (</>) option?

Did you make sure to install at the /remote folder from github to your components folder?

Here is my remote config, which currently works…

remote:
  platform: harmony
  name: Living Room
  username: !secret harmony_user
  password: !secret harmony_pass
  host: 10.0.0.209
  port: 5222
  activity: Watch DirecTV

Since i am using the all in one installer i manually copied the 3 files in my components folder. i could not get the copy command working (thats why i did it manually).

/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/remote.

I still dont see the .conf file in my home assistant folder.

Hrm… I’m running the same setup and don’t have any issues. You did add an entry into your secrets.yaml folder with your harmony email and password, right?

I know the first run can take an extra couple minutes since it has to build your .conf file.

would it be possible for you to restart the hass service with everything in place, wait a couple minutes until is has for sure frozen and then run:

systemctl status home-assistant@hass -l (or whatever your service name is called)

I can get this working if I select the script but not when I use input_select. I’m not sure I have understood the last step where you say to set up two sets of automations, I can only see one set in your example. Is this why? I assume you need another triggger when input_select is changed or am I being dumb??? Cheers

1 Like

You’re absolutely right! I forgot the last set of automations. I’ll add them now. My apologies!

Edit - I’ve updated my original post with the last set of automations you’ll need.

No worries and thanks for sorting! I’ve been trying to get this to work for last few days and finally cracked it with your guide, cheers

1 Like

That’s excellent to hear. I’m happy I was able to help.

@ianddayhas the PR ready in the official repo https://github.com/home-assistant/home-assistant/pull/4254. Hopefully, it will be approved soon.

I’m running Hass in docker.

If I followed the directions I got:
root@localhost:/config/temp# cp -TRv ./remote /usr/src/app/homeassistant/components
‘./remote/init.py’ -> ‘/usr/src/app/homeassistant/components/init.py’
‘./remote/harmony.py’ -> ‘/usr/src/app/homeassistant/components/harmony.py’
‘./remote/services.yaml’ -> ‘/usr/src/app/homeassistant/components/services.yaml’

By replacing my current services.yaml it breaks Hass from starting up.

To make it work I had to:
root@localhost:/config/temp# wget https://github.com/iandday/pyharmony/archive/master.zip
root@localhost:/config/temp# sudo pip install master.zip
mkdir /usr/src/app/homeassistant/components/remote
cd /config/temp/remote
cp * /usr/src/app/homeassistant/components/remote/

I think next I’m going to try running my container with a -v /config/temp/remote:/usr/src/app/homeassistant/components/remote

Pyharmony doesn’t seem to work. Android app and HarmonyHubControl works.
Tried entering username and password with and without quotation marks, in secrets.yaml and directly in config.yaml.
Pyharmony is version 1.0.10.
Error message:
pyharmony.auth: Malformed JSON (GetUserAuthTokenResult): {‘GetUserAuthTokenResult’: None}

I wrote a simple script to test the login and I always get " b'' " as a result. (using resp.raw.data)
I don’t know if that’s the corrent method to get the response. What should I try next?

It looks like something on Logitech’s end broke pyharmony earlier today. Hopefully @iandday can take a look at things when he has time.

Ha bridge is also broken I think, can’t get either to work just failed logins. Android app and My harmony are fine

@iandday Not sure how else to communicate to you since issues are disabled on your git but currently getting this error on your latest code.

16-11-20 17:39:00 homeassistant.components.remote: Error while setting up platform harmony
Traceback (most recent call last):
File “/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity_component.py”, line 150, in _async_setup_platform
entity_platform.add_entities, discovery_info
File “/usr/lib/python3.5/asyncio/futures.py”, line 361, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 296, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 274, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/local/lib/python3.5/dist-packages/homeassistant/components/remote/harmony.py”, line 51, in setup_platform
token = urllib.parse.quote_plus(pyharmony.ha_get_token(user, passw))
File “/usr/local/lib/python3.5/dist-packages/pyharmony/main.py”, line 72, in ha_get_token
token = harmony_auth.login(username, password)
File “/usr/local/lib/python3.5/dist-packages/pyharmony/auth.py”, line 46, in login
id_token = resp_dict[‘id_token’]
TypeError: ‘int’ object is not subscriptable

strange, it’s working for others. Can you enable debug logging for the remote component and copy the output? your credentials will be logged in the output to make sure they’re getting pullled correctly from the config.yaml

Oh huh, I remember an offhand comment I saw somewhere and tried without using !secret for my username and password and it seems to have not thrown that error anymore. Any idea about that?

not really sure, I’m using secrets in my config

remote:
  - platform: harmony
    name: Bedroom
    username: !secret username
    password: !secret password
    host: 10.168.1.13
    port: 5222
    activity: BedroomTV
  - platform: harmony
    name: Family Room
    username: !secret username
    password: !secret password
    host: 10.168.1.16
    port: 5222
    activity: Kodi

Strange its only failing when i use secret. I’ll look into it more. Im running hass version 0.33.1.

does your password have any special characters in it?