Logitech Harmony Integration with @iandday's component

I’m using secret’s in mine as well. No issues here.

I was just reading on the OpenHAB forum that Logitech may have changed something in their API and it’s causing all sort of issues on install that’s not communicating with the hub directly (locally) My installation in OpenHab is not working either. I am considering doing an installation of Home Assistant to test and was just noticing some similar issues here.

They broke the authentication routine earlier this week, Wednesday or Thursday I think? I was able to get it working again with the remote component and harmony platform I wrote. The pull request is still outstanding so for the time being you’ll have to manually install it

I configured everything and it works pretty well except for the fact that when i trigger an activity through harmony it wont update the input select although i have set it up as an automation.

- alias: "Powered off from Harmony Hub"
  trigger:
    platform: state
    entity_id: remote.harmony
  condition:
    condition: template
    value_template: '{{ trigger.to_state.attributes.current_activity == "Tv Off" }}'
  action:
    service: input_select.select_option
    entity_id: input_select.activities
    data:
      option: "Tv Off"

Does it have to do with the condition not being met? Syntax error?

It most likely should be PowerOff, my hub’s current_activity attribute is listed as PowerOff when there are no active activities from the hub

1 Like

Now that the Harmony code has been merged into the HASS code for the next release I wanted to add an alternative to @BTallack 's great instruction on how to incorporate the Harmony hub into your HASS setup that involves the template feature. It results in less lines of code but isnt as extensible as BTallack’s method

the following script can replace the section of scripts to activate each activity

script:
  input_select_harmony
    alias: "Start activity from input select"
    sequence:
      - service: remote.turn_on
        data_template:
          entity_id: remote.living_room_tv
          activity: >
            {% if is_state("input_select.living_room_tv", "PowerOff") %}
                -1
            {% elif is_state("input_select.living_room_tv", "Xbox") %}
                20195208
            {% elif is_state("input_select.living_room_tv", "Playstation 3") %}
                19954855
            {% elif is_state("input_select.living_room_tv", "Steam Link") %}
                16602559
            {% elif is_state("input_select.living_room_tv", "Plex Media Player") %}
                19575995           
            {% elif is_state("input_select.living_room_tv", "Airplay") %}
                19292022
            {% elif is_state("input_select.living_room_tv", "Wii U") %}
                13677570                
            {% endif %} 

The following automation will update the input select when the activity is changed using the harmony remote or other device

- alias: 'Remote external update living room'
  trigger:
    platform: state
    entity_id: remote.living_room_tv
  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.living_room_tv
      option: >
        {{ states.remote.living_room_tv.attributes.current_activity }} 

The last automation will start an activity once it’s selected from the input select in the frontend

- alias: 'Remote start activity from input select living room tv'
  trigger:
    platform: state
    entity_id: input_select.living_room_tv
  action:
    service: script.turn_on
    entity_id: script.input_select_harmony
4 Likes

Great guide(s). Thanks!
I’m relatively new to HASS and am having some difficulties with this setup.

I have the input select configured, and its displaying on my HASS homescreen.
Switching the activity on the Harmony remote is updating HASS, but I’m unable to change the activity via HASS.
I can see in the logs that the state has been changed, but my hub doesn’t initiate the change

Any assistance is greatly appreciated.

I have three separate config files for this setup:
configuration.yaml
harmony_script.yaml
harmony_automation.yaml

I’m including harmony_script and harmony_automation using directory merging. They’re being loaded, because any config errors stop HASS from starting.

from config…

group: !include group.yaml
script: !include_dir_merge_list script
automation: !include_dir_merge_list automation

remote:
- platform: harmony
name: Living Room TV
host: harmonyhub.
port: 5222

input_select:
living_room_tv:
name: Living Room TV
options:
- PowerOff
- Watch TV
- Watch a Movie
- Play a Game
- Listen to Radio
- Listen to iPod
initial: PowerOff
icon: mdi:monitor

automation:

  • alias: ‘Remote external update living room’
    trigger:
    platform: state
    entity_id: remote.living_room_tv
    action:
    service: input_select.select_option
    data_template:
    entity_id: input_select.living_room_tv
    option: >
    {{ states.remote.living_room_tv.attributes.current_activity }}

The last automation will start an activity once it’s selected from the input select in the frontend

  • alias: ‘Remote start activity from input select living room tv’
    trigger:
    platform: state
    entity_id: input_select.living_room_tv
    action:
    service: script.turn_on
    entity_id: script.input_select_harmony

script:

input_select_harmony:
alias: "Start activity from input select"
sequence:
  - service: remote.turn_on
    data_template:
      entity_id: remote.living_room_tv
      activity: >
        {% if is_state("input_select.living_room_tv", "PowerOff") %}
            -1
        {% elif is_state("input_select.living_room_tv", "Watch TV") %}
            9815799
        {% elif is_state("input_select.living_room_tv", "Watch a Movie") %}
            9816132
        {% elif is_state("input_select.living_room_tv", "Play a Game") %}
            9825015
        {% elif is_state("input_select.living_room_tv", "Listen to Radio") %}
            9816180         
        {% elif is_state("input_select.living_room_tv", "Listen to iPod") %}
            9816227             
        {% endif %}

can you post your configs properly formatted? It’ll make it much easier to assist

Can do. Thanks for the assistance.

Here are the three files. I’ve removed my local IPs and GPS co-ordinates.

try this, it looks like your spacing was off

input_select_harmony:
  alias: "Start activity from input select"
  sequence:
    - service: remote.turn_on
      data_template:
        entity_id: remote.living_room_tv
        activity: >
          {% if is_state("input_select.living_room_tv", "PowerOff") %}
              -1
          {% elif is_state("input_select.living_room_tv", "Watch TV") %}
              9815799
          {% elif is_state("input_select.living_room_tv", "Watch a Movie") %}
              9816132
          {% elif is_state("input_select.living_room_tv", "Play a Game") %}
              9825015
          {% elif is_state("input_select.living_room_tv", "Listen to Radio") %}
              9816180        
          {% elif is_state("input_select.living_room_tv", "Listen to iPod") %}
              9816227             
          {% endif %}

I have some additional remote automations in my repository that may be helpful.

Huge thanks to @iandday and the testers.
With the introduction of the new component I can finally be rid of one of my biggest frustrations with the Harmony Hub; it’s activities not being synced up with everything else.

I am using the below automation for my Xbox One activity on my Harmony Hub that makes use of the Xbox Live component and the status of my TV. It will trigger when either of the TV turns on/off and if my Xbox Profile is online/offline; then check to make sure that both the TV and Xbox Profile are (on/online)/(off/offline); then will activate/deactivate the ‘Play Xbox One’ activity on the harmony hub.

Note: After playing around a bit I realised I had to add the multiple triggers along with the AND conditions due to timings of devices being registered as on/off within Home Assistant, whilst also making sure that the devices associated with the Activity are both in the correct state.

## Activate Xbox One Activity on Harmony if Xbox is Online and TV is on

- alias: Activate Xbox One Activity on Harmony
  trigger:
    - platform: state
      entity_id: sensor.pawnynz
      state: 'Online'
    - platform: state
      entity_id: media_player.loungetv
      state: 'on'

  condition:
    condition: and
    conditions: 
    - condition: state
      entity_id: media_player.loungetv
      state: 'on'
    - condition: state
      entity_id: sensor.pawnynz
      state: 'Online'

  action:
    service: remote.turn_on
    data:
      activity: 21515412
      entity_id: remote.lounge_harmony

## Deactivate Xbox One Activity on Harmony if Xbox is Offline and TV is off

- alias: Deactivate Xbox One Activity on Harmony
  trigger:
    - platform: state
      entity_id: sensor.pawnynz
      state: 'Offline'
    - platform: state
      entity_id: media_player.loungetv
      state: 'off'

  condition:
    condition: and
    conditions: 
    - condition: state
      entity_id: media_player.loungetv
      state: 'off'
    - condition: state
      entity_id: sensor.pawnynz
      state: 'Offline'

  action:
    service: remote.turn_off
    data:
      entity_id: remote.lounge_harmony
1 Like

That’s really clever! I hadn’t actually thought of using an Xbox Live component to track the power state of an Xbox to control my Harmony hub. You could conceivably do the same with the NMAP tracker component as well.

Cheers, I had been doing tracking similar to that previously but kept getting into issues. As my Xbox is in ‘Instant On’ mode it is always waking up the network connection every few minutes to pole the internet.

Thanks iandday. Unfortunately still no luck.

Appreciate your assistance.

Will have a play around with it over the weekend and see what I can break/fix.

Try editing your host under your remote config

remote:
host: HARMONY_IP_ADDRESS

The one thing that is bugging me about this is that the state change in the input select only happens when there is an actual state change in the activity, so when I restart HASS it’s usually out of sync since it starts at “Powered Off”. Would there be a way to write an automation that would do a quick check of the currently active activity and change (if necessary) when the HASS service is restarted?

I tried to fix that by writing a value template for the initial value in the input_select but couldn’t get it to work, (I’m not sure if it’s even a valid thing for that field).

You should be able to use the event trigger. You may have to delay the action by 30s or so to ensure that pyharmony has pulled the current activity first, but that’s not a huge issue.

automation:
  trigger:
    platform: event
    event_type: homeassistant_start
1 Like

Yeah as @Bahnburner says use the start event with a delay, this works for me.

automation:
  - alias: Harmony Set Input Select On Start
    hide_entity: true
    trigger:
      platform: event
      event_type: homeassistant_start
    action:
      - delay:
          seconds: 30
      - service: input_select.select_option
        data_template:
          entity_id: input_select.living_room_tv
          option: '{{ states.remote.homehub.attributes.current_activity }}'
1 Like