Logitech Harmony Integration with @iandday's component

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

Does anyone have example code of a switch for say controlling just the device power on the tv?

service: remote.send_command
data_template:
  command: PowerOn
  device: 37313947
  entity_id: remote.livingroom

I am getting error - ( homeassistant.bootstrap: Invalid config for [automation]: expected a dictionary. Got OrderedDict([(‘homeassistant’,) …See /home/hass/.homeassistant/automation.yaml:1

My configuration is -
For Sensor.yaml -

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

input_select.yaml -

harmony:
  name: Harmony
  options:
   - Select Input 
   - Watch TV
   - cartoon
   - Aquarium
   - Xbox
   - PowerOff
  icon: mdi:monitor

Automation file : 1living_room.yaml-

- alias: Harmony
  hide_entity: True
  trigger:
    platform: state
    entity_id: input_select.harmony
    from: 'Select Activity'
  action:
    - service: remote.turn_on
      entity_id: remote.living_room
      data_template:
        activity: >
          {% if is_state("input_select.harmony", "Watch Tv") %}
            23029785
          {% elif is_state("input_select.harmony", "cartoon") %}
            23029465
          {% elif is_state("input_select.harmony", "Aquarium") %}
            20252019
          {% elif is_state("input_select.harmony", "Xbox") %}
            20639029
          {% elif is_state("input_select.harmony", "PowerOff") %}
            -1
          {% else %}
          {% endif %}
    - service: input_select.select_option
      entity_id: input_select.harmony
      data:
        option: "Select Activity"

automation.yaml -

####MEDIA BASED####
- !include automation/media_playing_day.yaml
- !include automation/media_stopped_day.yaml
- !include automation/say_weather.yaml
- !include automation/1living_room.yaml

The select activities doesn’t work]

Use preformatted text to post (makes it easier for helpers to repost with corrections).

Your error is in the automation: block - I don’t think we can see the cause from what you’ve posted. Make sure that under “automation:”, you only have groupings that start with “- alias: …” Does the error include a line number?

I have updated the post with original formatting. I don’t get any line number in log file but if i remove the 1living_room.yaml from automation then error goes away but my harmony select input also doesn’t work.

how are your other automations formated? I’m wondering if it’s an indentation issue.

I tried following your github page but stuck at this error.