Trying to get Harmony working

When I try to verify my config I get the following error:
expected a dictionary for dictionary value @ data[‘packages’][‘sensor’]

I am new to this, but tried to modify the original authors .yaml file to work with my configuration. Running Hass.io on a Raspberry Pi.

Original file by Trent Stanton (had to remove header since I am a new user)

group:
harmonytv:
control: hidden
name: Harmony Remote
entities:
- sensor.harmony_activity
- input_select.harmony

input_select:
harmony:
name: Harmony Control
options:
- Select Input
- DirectTV
- AppleTV
- DVR
- Power Off
initial: Select Input
icon: mdi:remote

sensor:

  • platform: template
    sensors:
    harmony_activity:
    friendly_name: ‘Harmony Activity’
    value_template: ‘{{ states.remote.living_room_harmony.attributes.current_activity }}’
    icon_template: >-
    {% if is_state(“sensor.harmony_activity”, “DirectTV”) %}
    mdi:television-box
    {% elif is_state(“sensor.harmony_activity”, “AppleTV”) %}
    mdi:plex
    {% elif is_state(“sensor.harmony_activity”, “DVR”) %}
    mdi:google-chrome
    {% else %}
    mdi:monitor
    {% endif %}
    ###############################################################################

Automations

###############################################################################
automation:

  • alias: Start Harmony Activity
    hide_entity: True
    trigger:

    • platform: state
      entity_id: input_select.harmony
      from: ‘Select Input’
      action:
    • service: remote.turn_on
      entity_id: remote.living_room_harmony
      data_template:
      activity: >
      {% if is_state(“input_select.harmony”, “DirectTV”) %}
      32552301
      {% elif is_state(“input_select.harmony”, “AppleTV”) %}
      32552494
      {% elif is_state(“input_select.harmony”, “DVR”) %}
      33082025
      {% else %}
      {% endif %}
    • service: input_select.select_option
      entity_id: input_select.harmony
      data_template:
      option: “Select Input”
  • alias: Stop Harmony Activity
    hide_entity: True
    trigger:

    • platform: state
      entity_id: input_select.harmony
      to: ‘Power Off’
      action:
    • service: remote.turn_off
      entity_id: remote.living_room_harmony
    • service: input_select.select_option
      entity_id: input_select.harmony
      data_template:
      option: “Select Input”

Realized I didn’t follow instructions

group:
harmonytv:
control: hidden
name: Harmony Remote
entities:
- sensor.harmony_activity
- input_select.harmony

input_select:
harmony:
name: Harmony Control
options:
- Select Input
- DirectTV
- AppleTV
- DVR
- Power Off
initial: Select Input
icon: mdi:remote

sensor:

  • platform: template
    sensors:
    harmony_activity:
    friendly_name: ‘Harmony Activity’
    value_template: ‘{{ states.remote.living_room_harmony.attributes.current_activity }}’
    icon_template: >-
    {% if is_state(“sensor.harmony_activity”, “DirectTV”) %}
    mdi:television-box
    {% elif is_state(“sensor.harmony_activity”, “AppleTV”) %}
    mdi:plex
    {% elif is_state(“sensor.harmony_activity”, “DVR”) %}
    mdi:google-chrome
    {% else %}
    mdi:monitor
    {% endif %}
    ###############################################################################

Automations

###############################################################################
automation:

  • alias: Start Harmony Activity
    hide_entity: True
    trigger:

    • platform: state
      entity_id: input_select.harmony
      from: ‘Select Input’
      action:
    • service: remote.turn_on
      entity_id: remote.living_room_harmony
      data_template:
      activity: >
      {% if is_state(“input_select.harmony”, “DirectTV”) %}
      32552301
      {% elif is_state(“input_select.harmony”, “AppleTV”) %}
      32552494
      {% elif is_state(“input_select.harmony”, “DVR”) %}
      33082025
      {% else %}
      {% endif %}
    • service: input_select.select_option
      entity_id: input_select.harmony
      data_template:
      option: “Select Input”
  • alias: Stop Harmony Activity
    hide_entity: True
    trigger:

    • platform: state
      entity_id: input_select.harmony
      to: ‘Power Off’
      action:
    • service: remote.turn_off
      entity_id: remote.living_room_harmony
    • service: input_select.select_option
      entity_id: input_select.harmony
      data_template:
      option: “Select Input”

I experienced the same difficulty with posting the code, make sure you indent it by 4 spaces in the forum reply box, it will then look fine in the preview on the right.

As for Harmony, I see no place where you inputted the IP address of your hub, I believe it only works on the remotes with a Harmony Hub, otherwise how will you connect to it?

    remote:
      - platform: harmony
        name: Bedroom
        host: 10.168.1.13

The docs say it will be discovered on the network.

The docs also say that even via discovery, you should have this in the configuration file, I see nothing like it in the OPs code:

# Example configuration.yaml entry with discovery
  - platform: harmony
    name: Living Room 
    activity: Watch TV

I have that entry in my configuration.yaml. The yaml I listed is specific to harmony in the packages directory.

That’s only if you want to override the values from discovery. It is not needed.

The yaml you listed is impossible to read and debug because you didn’t follow the directions at the top of the forum when posting code.

Are you actually having issues still or has your issue been resolved?

It is still an issue. I have formatted, hopefully, correctly. Thanks for taking a look.
###############################################################################
#
# @package : Harmony TV Activity Control
###############################################################################

group:
  harmonytv:
   control: hidden
    name: Harmony Remote
    entities:
      - sensor.harmony_activity
      - input_select.harmony

input_select:
  harmony:
    name: Harmony Control
    options:
      - Select Input
      - DirectTV
      - AppleTV
      - DVR
      - Power Off
    initial: Select Input
    icon: mdi:remote

sensor:
  -  platform: template
     sensors:
     harmony_activity:
     friendly_name: 'Harmony Activity'
     value_template: '{{ states.remote.living_room_harmony.attributes.current_activity }}'
     icon_template: >-
        {% if is_state("sensor.harmony_activity", "DirectTV") %}
          mdi:television-box
        {% elif is_state("sensor.harmony_activity", "AppleTV") %}
            mdi:plex
        {% elif is_state("sensor.harmony_activity", "DVR") %}
            mdi:google-chrome
        {% else %}
            mdi:monitor
        {% endif %}
###############################################################################
#                               Automations
###############################################################################
automation:
  - alias: Start Harmony Activity
    hide_entity: True
    trigger:
    - platform: state
  entity_id: input_select.harmony
      from: 'Select Input'
    action:
    - service: remote.turn_on
      entity_id: remote.living_room_harmony
      data_template:
        activity: >
          {% if is_state("input_select.harmony", "DirectTV") %}
            32552301
          {% elif is_state("input_select.harmony", "AppleTV") %}
            32552494
          {% elif is_state("input_select.harmony", "DVR") %}
            33082025
          {% else %}
          {% endif %}
    - service: input_select.select_option
      entity_id: input_select.harmony
      data_template:
        option: "Select Input"

  - alias: Stop Harmony Activity
    hide_entity: True
    trigger:
    - platform: state
       entity_id: input_select.harmony
      to: 'Power Off'
    action:
    - service: remote.turn_off
      entity_id: remote.living_room_harmony
    - service: input_select.select_option
      entity_id: input_select.harmony
      data_template:
        option: "Select Input"
  1. Your yaml spacing is all over the place. You need to make sure your indents are 2 for each level and you also need to make sure your attributes are at the correct indent.
  2. All harmony activities require you to use remote.turn_on, including turning it off. The activity for turning off harmony is called “PowerOff”.
  3. (Not a deal breaker) You incorrectly use data and data_template. The idea behind these is simple. If your data section contains a template, use data_template. If it doesn’t use data. Templates are this stuff: {{}} or {%%}, etc.
group:
  harmonytv:
    control: hidden #THIS WAS AT WRONG INDENT
    name: Harmony Remote
    entities:
      - sensor.harmony_activity
      - input_select.harmony

input_select:
  harmony:
    name: Harmony Control
    options:
      - Select Input
      - DirectTV
      - AppleTV
      - DVR
      - Power Off
    initial: Select Input
    icon: mdi:remote

sensor:
    # This whole section had the wrong indent
  - platform: template
    sensors:
      harmony_activity: #MISSING INDENT HERE
        friendly_name: 'Harmony Activity' #MISSING 2 INDENTS HERE DOWN
        value_template: '{{ states.remote.living_room_harmony.attributes.current_activity }}'
        icon_template: >-
          {% if is_state("sensor.harmony_activity", "DirectTV") %}
            mdi:television-box
          {% elif is_state("sensor.harmony_activity", "AppleTV") %}
              mdi:plex
          {% elif is_state("sensor.harmony_activity", "DVR") %}
              mdi:google-chrome
          {% else %}
              mdi:monitor
          {% endif %}
###############################################################################
#                               Automations
###############################################################################
automation:
  - alias: Start Harmony Activity
    hide_entity: True
    trigger:
      - platform: state
        entity_id: input_select.harmony
        from: 'Select Input'
    action:
      - service: remote.turn_on
        entity_id: remote.living_room_harmony
        data_template:
          activity: >
            {% if is_state("input_select.harmony", "DirectTV") %}
              32552301
            {% elif is_state("input_select.harmony", "AppleTV") %}
              32552494
            {% elif is_state("input_select.harmony", "DVR") %}
              33082025
            {% else %}
            {% endif %}
      - service: input_select.select_option
        entity_id: input_select.harmony
        data:
          option: "Select Input"

  - alias: Stop Harmony Activity
    hide_entity: True
    trigger:
      - platform: state
        entity_id: input_select.harmony
        to: 'Power Off'
    action:
      - service: remote.turn_on
        entity_id: remote.living_room_harmony
        data:
          activity: "PowerOff"
      - service: input_select.select_option
        entity_id: input_select.harmony
        data:
          option: "Select Input"

I have a package here that works with my Harmony Hub remote. Just change the Entity ID, names and activity ID’s. https://gist.github.com/xbmcnut/31132db324e9032710bb4ac6c165100e

The only problem I get with that is an error in the logs stating:

ERROR (MainThread) [homeassistant.components.switch.template] UndefinedError: 'None' has no attribute 'attributes'

which I haven’t been able to figure out yet. Otherwise it works great!

EDIT: Bug removed and GIST updated thanks to @petro

change all these lines

"{{ states.remote.poaka_lounge.attributes.current_activity == 'Watch Kodi' }}"

to this

"{{ is_state_attr('remote.poaka_lounge', 'current_activity', 'Watch Kodi') }}"

also change this line

        option: "{{ states.remote.poaka_lounge.attributes.current_activity }}"

to this

        option: "{{ state_attr('remote.poaka_lounge', 'current_activity') }}"

1 Like

You Sir are a legend, thank you! Worked a treat. Been bugging me for months!

1 Like

@petro Wondering if you’ve seen this error?

2019-03-23 14:59:15 WARNING (MainThread) [homeassistant.components.input_select] Invalid option: None (possible options: PowerOff, Watch Kodi, Watch Magic TV, Watch Sky, Watch TV)

The full Harmony package code is here https://gist.github.com/xbmcnut/31132db324e9032710bb4ac6c165100e

That error is causing the hassio component not to load under 0.90.0/1 so I’ve had to disable the package completely for now.

Any thoughts?

try adding this condition:

automation:
  - alias: Update Harmony input_select
    hide_entity: True
    trigger:
      platform: state
      entity_id: remote.poaka_lounge
    condition:
      condition: template
      value_template:  "{{ trigger.to_state.attributes.current_activity in state_attr('input_select.harmony', 'options') }}"
    action:
      service: input_select.select_option
      data_template:
        entity_id: input_select.harmony
        option: "{{ state_attr('remote.poaka_lounge', 'current_activity') }}"
1 Like

Thank you! Seems to have done the trick. No idea how you come up with this complex magic :wink:

1 Like

Thank you so much @petro, you are the one :bowing_man:

I was fighting with this error since so long, and again your magic coding solved it.

Thanks for your sharing and for the countless times you helped me and others.

1 Like

I too am having problems with Harmony integration and am hoping someone can help.

First off, auto-discovery correctly identifies 3 Harmony Hubs in the house. All I want to do is switch one of them off at 3 am via automation for reasons that are unimportant.

I added the following to my configuration.yaml (note there is a harmony_lounge.conf, but the hub name is configured as Lounge with a capital L, and as the instructions say to match the hub name, that is what I used below):

remote:
  - platform: harmony
    name: Lounge

and according to the instructions on this page I added an automation call to invoke an action type of Call service, with the service specified as remote.turn_off and service data as follows:

{
“entity_id”: “remote.Lounge”
}

It doesn’t work. Nor do ANY entries for remote.anything appear in the states page in the HA GUI

Earlier in this topic I saw someone post that you have to use remote.turn_on, with an activity of Power Off, but this contradicts the instructions on the page I linked to above.

I did wonder if the XMPP withdrawal by Logitech was intruding, but my Hub is running firmware 4.15.250 and my HA version is 0.90.1, so my understanding is it should be using the WebAPI with no problems. I just checked the hub and XMPP is currently disabled.

So as it seems HA can ‘see’ my hubs, my assumption is that I have either made some basic error in the tiny bit of config I supplied. Any advice or suggestions for diagnostics would be gratefully received.

You’re contradicting yourself here. You say auto discovery finds 3 remotes but then you say you don’t have 3 remotes in your states page. So what’s correct?

Auto-discovery works, as it creates three conf files - one for each of the hubs that I have called harmony_hubname.conf, and they appear to be correct and complete - yet NO remotes are shown in the states page.