Logitech Harmony Integration with @iandday's component

Yes superfluous, but it doesn’t break syntax.

Only benefit would be to save you a few seconds adding the hyphen if you ever added any more steps in that sequence. I don’t know of any drawbacks.

Hi @iandday,

I have strange but reproducible side-effects using your script and automation examples. My Harmony Ultimate remote now (after configuring it in HASS) often performs synchronization without apparent reason, does not enter screensaver after changing activities, starts a single device after PowerOff activity etc.

Has someone had similar problems?

As soon as I remove the ‘Remote external update living room’ automation from your example, the Harmony (outside of HASS) works as expected again.

Maybe my Hub is unable to cope with two activity commands at the same time:
When I hit the PowerOff button on the actual Ultimate remote, the HASS remote component state is updated. Then the ‘Remote external update living room’ automation sets the new value in the input select and the ‘Remote start activity from input select living room tv’ automation immediately triggers the very same activity as received from the state update (which might still be in progress)…?

I wondered about that as I was reading this. My first thought was to put a condition on the update automation so that it doesn’t send the command to the Harmony unless the new state (from the input_select) is different than the current state (from the remote). I haven’t actually tested that yet, but I’m guessing it should be possible.

I have been trying to set this new component up but it is not working correctly so looking for some help. The input select is displayed in the UI with all activities but they do not update when changing an activity on the remote and also do not change the activity if I select the activity from the HA input select. Here is my config.

configuration.yaml

remote:
  - platform: harmony
    name: Living Room Hub
    host: 192.168.1.xxx
    port: 5222
    activity: Watch TV

input_select:
  harmony_remote:
    name: Harmony Remote
    options:
      - PowerOff
      - Watch Amazon
      - Watch Plex
      - Watch Smart TV
      - Watch DVD
      - Watch PC
      - Watch TV
    initial: PowerOff
    icon: mdi:television

scripts.yaml file

input_select_harmony:
    alias: "Start activity from input select"
    sequence:
      - service: remote.turn_on
        data_template:
          entity_id: remote.living_room_hub
          activity: >
            {% if is_state("input_select.living_room_hub", "PowerOff") %}
                -1
            {% elif is_state("input_select.living_room_hub", "Watch Amazon") %}
                16657231
            {% elif is_state("input_select.living_room_hub", "Watch Plex") %}
                16537386
            {% elif is_state("input_select.living_room_hub", "Watch Smart TV") %}
                16657221
            {% elif is_state("input_select.living_room_hub", "Watch DVD") %}
                16537438
            {% elif is_state("input_select.living_room_hub", "Watch PC") %}
                22222835
            {% elif is_state("input_select.living_room_hub", "Watch TV") %}
                16537371
            {% endif %}

and my automations.yaml file

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

- alias: 'Remote start activity from input select living room hub'
  trigger:
    platform: state
    entity_id: input_select.living_room_hub
  action:
  - service: script.turn_on
    entity_id: script.input_select_harmony

I am seeing the following error in the log if this helps
18:55:38 homeassistant.components.sensor.template: UndefinedError: ‘None’ has no attribute ‘attributes’

Would appreciate any help anyone could give.

Your input select is called harmony_remote but you call input_select.living_room_hub in the entity_id part of both of your automations

Tried adding a condition to the script. But from the HASS log I can see it is still executed if I switch activities from the Ultimate. The problem with my PS3 switched on when I PowerOff still persists… :smiley:

script:
  input_select_harmony:
    alias: 'Logitech Harmony (Wohnzimmer): Input Select - Ausgewählte Aktivität starten (Script)'
    sequence:
      - condition: template
        value_template: '{{ states.remote.wohnzimmer.attributes.current_activity != states.input_select.wohnzimmer }}'
      - service: remote.turn_on
        data_template:
          entity_id: remote.wohnzimmer
          activity: >
            {% if is_state("input_select.wohnzimmer", "PowerOff") %}
                -1
            {% elif is_state("input_select.wohnzimmer", "Apple TV sehen") %}
                14431475
            {% elif is_state("input_select.wohnzimmer", "Fernsehen") %}
                14431436
            {% elif is_state("input_select.wohnzimmer", "Wiedergabe PS3") %}
                14431521
            {% elif is_state("input_select.wohnzimmer", "Musik hören") %}
                14431578
            {% elif is_state("input_select.wohnzimmer", "Spotify") %}
                16371284
            {% elif is_state("input_select.wohnzimmer", "iPod hören") %}
                14431550
            {% elif is_state("input_select.wohnzimmer", "Fire TV sehen") %}
                14431499
            {% endif %}

Thanks @mrtips sometimes you can’t see the obvious so appreciate your help with this. It is working OK now on an initial test but I will test some more later. Many thanks.

No worries, I actually did the same thing with the script part of the config and scratched my head for a day before seeing it.

Setting this up is actually non-trivial, could be good to have the default component make all the activities available as individual switches. I wonder if that’s possible, @iandday may know?

Perhaps that’ll be my Christmas project and first home assistant pull request if people think it would be a good idea?

Is there anything else on your network that can interact with the harmony hub or is it just HASS and the hub? This sounds like a feedback loop.

Also try putting the condition on the ‘Remote start activity from input select’ automation rather then the script itself so the script never gets launched if the input select is the same as the current activity.

It’s completely possible, during component setup you can loop through the list of detected activities and create a switch for each one. I didn’t want to clutter up the front-end with a large number of switches when they might not all be used. It’s on my to-do list and to create a variable that will be placed in the harmony section of the config.yaml to control if the individual switches are created

1 Like

I moved the condition to the automation. And then I found an error in my condition… :blush: I compared to the input_select state object instead of the state string. Here is the correct condition:

- condition: template
  value_template: '{{ states.remote.wohnzimmer.attributes.current_activity != states.input_select.wohnzimmer.state }}'

Now my strange behaviors disappeared. All working as expected. So if someone else also encounters problems, here is the complete automation (as per iandday’s example) including the condition suppressing the feedback loop:

- alias: 'Remote start activity from input select living room tv'
  trigger:
    platform: state
    entity_id: input_select.living_room_tv
  condition:
    condition: template
    value_template: '{{ states.remote.living_room_tv.attributes.current_activity != states.input_select.living_room_tv.state }}'
  action:
    service: script.turn_on
    entity_id: script.input_select_harmony
2 Likes

I had feedback loop issues on my RPi3 with the auto-correcting input_select and ended up going another route. Here’s what I have:

The majority of the code is the same, but rather than trying to correct the input_select anytime it changes, I instead directly display the current activity using a template sensor and have the input_select revert to Select Input after sending the start activity command to the harmony hub.

input_select:
  harmony:
    name: Harmony Control
    options:
### DO NOT REMOVE 'SELECT INPUT'
      - Select Input
      - Watch DirecTV
      - Watch Plex
      - Watch Netflix
      - Watch Hulu
      - Watch Prime Video
      - Watch Chromecast
      - Watch Smart TV
      - Power Off
    icon: mdi:monitor

sensor:
  - platform: template
    sensors:
      current_activity:
        friendly_name: 'Current Activity'
        value_template: '{{ states.remote.living_room.attributes.current_activity }}'

- alias: Harmony
  hide_entity: True
  trigger:
    platform: state
    entity_id: input_select.harmony
    from: 'Select Input'
  action:
    - service: remote.turn_on
      entity_id: remote.living_room
      data_template:
        activity: >
          {% if is_state("input_select.harmony", "Watch DirecTV") %}
            19594181
          {% elif is_state("input_select.harmony", "Watch Plex") %}
            19755764
          {% elif is_state("input_select.harmony", "Watch Netflix") %}
            23422788
          {% elif is_state("input_select.harmony", "Watch Hulu") %}
            20619552
          {% elif is_state("input_select.harmony", "Watch Prime Video") %}
            19752038
          {% elif is_state("input_select.harmony", "Watch Chromecast") %}
            19938341
          {% else %}
          {% endif %}
    - service: input_select.select_option
      entity_id: input_select.harmony
      data_template:
        option: "Select Input"

- alias: Harmony Off
  hide_entity: True
  trigger:
    platform: state
    entity_id: input_select.harmony
    to: 'Power Off'
  action:
    - service: remote.turn_off
      entity_id: remote.living_room
    - service: input_select.select_option
      entity_id: input_select.harmony
      data_template:
        option: "Select Input"
5 Likes

Yeah that’s what I had in mind.

Be aware that that code will only work if your input select state names are identical to your harmony remote activity names. If you customise them you will have to do a bit more logic in that template.

This is a nice solution too.

Hi Bahnburner, i have adpated your implementation and i get the following error:

16-12-26 12:03:13 homeassistant.bootstrap: Invalid config for [automation]: [data template] is an invalid option for [automation]. Check: automation->action->0->data template. (See /home/hass/.homeassistant/automation.yaml:6). Please check the docs at https://home-assistant.io/components/automation/

What am i missing?

- alias: Harmony Set Input Select On Start
  hide_entity: True
  trigger:
    platform: state
    entity_id: input_select.activities
    from: 'Select Activity'
  action:
    - service: remote.turn_on
      entity_id: remote.harmony
      data template:
        activity: >
          {% if is_state("input_select.activities", "Watch Tv") %}
            16944634
          {% elif is_state("input_select.activities", "Listen to Music") %}
            17396725
          {% elif is_state("input_select.activities", "Movie Lights") %}
            19022343
          {% elif is_state("input_select.activities", "Elena Zen") %}
            18733635
          {% elif is_state("input_select.activities", "Tv Off") %}
            -1
          {% else %}
          {% endif %}
    - service: input_select.select_option
      entity_id: input_select.activities
      data:
        option: "Select Activity"

Change data template to data_template. That one’s my fault. I’ll update my OP.

1 Like

Thx, i was killing myself for not seeing that.
Please put also the sign > after activity, that i figured it my self :slight_smile:

Woops. That too.

There’s a fully working version on my GitHub here: https://github.com/Bahnburner/Home-Assistant-Config/blob/master/automation/remote/living_room.yaml

2 Likes

This component is fantastic - finally allows me to interface quickly with my harmony hub when the wife has the remote!

The discussion here is mostly around using input_select to set or mirror activities set on the harmony hub.

I wanted an automation to allow me to send a ‘Pause’ command using the send_command service to whatever relevant device was active - you need to specify the device to sent the command as the component does not seem to know what the ‘Pause’ button is programmed for in each activity scenario. The use case is that my wife walks away and the remote is next to her. I can push a flic button (or do whatever to trigger an automation) and the relevant device will pause until she returns.

I used the template scenarios as mentioned in this discussion and others. Sharing it here as it took a while to get going and I hope it adds to the knowledge base. Also added the example as a PR to the documentation FWIW.

Phil

automation:
  - alias: Harmony Pause contextual for activity
    trigger:
    # trigger happens to be from a flic button - could be any valid event
      platform: event
      event_type: flic_click
      event_data:
        button_name: flic_80e4da70bbb1
        click_type: double
    action:
      service: remote.send_command
      data_template:
      # using a data template to have if brances for relavant device
        # Always the same entity_id - the harmony hub
        entity_id: remote.bedroom 
        # Always the same command - the Pause key
        command: Pause
        # select device based upon the activity being undertaken.
        device: >
          # when in WATCH TV activity, the pause key relates to a TiVo, which is device 22987101 
          {% if is_state("sensor.bedroom", "WATCH TV") %}
            22987101
          # when in WATCH APPLE TV activity, the pause key relates to an Apple TV, which is device 23002316
          {% elif is_state("sensor.bedroom", "WATCH APPLE TV") %}
            23002316
          {% elif is_state("sensor.bedroom", "PLEX") %}
            23048786
          {% elif is_state("sensor.bedroom", "WATCH BLU RAY") %}
            23043122
          {% endif %}
2 Likes