Harmony Hub Activities and Homekit Switches

I’ve been reading posts about integrating Harmony Hub Activities into my new Home Assistant installation (MacOS Python), and have tried a bunch of suggestions but can’t seem to get it right. I’m still very new at this language. I would like to add three Harmony Activities as switches to Home Assistant, and see them in HomeKit so I can trigger them by voice using my phone.

Any help would be greatly appreciated!

Here is my configuration.yaml:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: xxxxx
  longitude: -xxxx
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 14
  # metric for Metric, imperial for Imperial
  unit_system: imperial
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: America/New_York
  # Customization file
  customize: !include customize.yaml

# Show links to resources in log and frontend
introduction:

# Enables the frontend
frontend:

# Enables configuration UI
config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
updater:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time
history:

# View all events in a logbook
logbook:

# Enables a map showing the location of tracked devices
map:

# Track the sun
sun:

# Weather prediction
sensor:
  - platform: yr

# Text to speech
tts:
  - platform: google

# Cloud
cloud:

# Homekit
homekit:


#Climate
climate:
  - platform: radiotherm


#Weather
sensor:
  - platform: darksky
    api_key: xxxxxxxxx
    monitored_conditions:
      - temperature
      - apparent_temperature
      - wind_speed
      - precip_type

#Harmony
remote:
  - platform: harmony
    name: livingroom
    host: 192.168.1.10

#Switch
switch:
- platform: template
  switches:
    # apple tv activity
    apple_tv:
      value_template: "{{ is_state_attr('remote.livingroom', 'current_activity', ‘APPLE TV’) }}"
      turn_on:
        service: remote.turn_on
        data:
          entity_id: remote.livingroom
          activity: ‘APPLE TV’
       turn_off:
         service: remote.turn_on
         data:
           entity_id: remote.livingroom
           activity: 'PowerOff'
        
    # digital music activity
    music:
      value_template: "{{ is_state_attr('remote.livingroom', 'current_activity', 'Listen to Digital Music') }}"
      turn_on:
        service: remote.turn_on
        data:
          entity_id: remote.livingroom
          activity: 'Listen to Digital Music'
       turn_off:
         service: remote.turn_on
         data:
           entity_id: remote.livingroom
           activity: 'PowerOff'
        
    # radio activity
    radio:
      value_template: "{{ is_state_attr('remote.livingroom', 'current_activity', 'Listen to Radio') }}"
      turn_on:
        service: remote.turn_on
        data:
          entity_id: remote.livingroom
          activity: 'Listen to Radio'
      turn_off:
         service: remote.turn_on
         data:
          entity_id: remote.livingroom
          activity: 'PowerOff'


#Weather
sensor:
  - platform: yweather
    monitored-conditions:
      - weather
      - weather-current
      - temp-min
      - temp-max
      - wind-speed
      - pressure
      - visibility
      - humidity
      - temperature

#Garage
cover:
  - platform: myq
    username: xxxxxxxxx
    password: xxxxxxx
    type: chamberlain

Here’s a few observations:

  1. The service: remote.turn_on under the turn_off: section should be service: remote.turn_off(for apple_tv, music and radio).
  2. Try using the activity ID number where it says activity:. This can be found in the same directory as your configuration.yaml file, in a file called “harmony_harmony_hub.conf”. Open this up and you’ll see your activities listed at the top with a series of numbers (i.e. 2543934 - AppleTV). You would set activity: 2543934 in this example. For PowerOff, you’ll see it listed as -1 so you would set activity: -1
  3. The Harmony Hub is automatically discoverable by the discovery: feature of Home Assistant so it’s not required to use remote: with your harmony info. It shouldn’t matter though.

Can you see the Harmony Hub from the “States” page under “Developer tools”? It should say remote.livingroom in your case.

I did some more searching and found some other examples to try and copy. I’m still getting errors when I check the config and I can’t figure out what is going wrong. I appreciate any help, thanks!

remote:
  - platform: harmony
    name: Harmony Hub
    host: 10.0.1.253 
    activity: 17928684

group:
  harmony_hub:
    name: Harmony
    control: hidden
    entities:
      - switch.watch_tv
      - switch.play_music
      - switch.play_radio

switch:
  - platform: template
switches:
  watch_tv:
    friendly_name: Watch TV
    value_template: "{{ is_state_attr('remote.harmony_hub', 'current_activity', ‘PowerOn’) }}"
    turn_on:
      service: remote.turn_on
      data:
        entity_id: remote.harmony_hub
        activity: “19727717”
    turn_off:
       service: remote.turn_on
       data:
         entity_id: remote.harmony_hub
         activity: “-1”
  - platform: template
switches:
  play_music:
    friendly_name: Play Music
    value_template: "{{ is_state_attr('remote.harmony_hub', 'current_activity', 'PowerOn’) }}"
    turn_on:
      service: remote.turn_on
      data:
        entity_id: remote.harmony_hub
        activity: “16598998”
    turn_off:
      service: remote.turn_on
      data:
        entity_id: remote.harmony_hub
        activity: “-1”
  - platform: template
switches:
  play_radio:
    friendly_name: Play Radio
    value_template: "{{ is_state_attr('remote.harmony_hub', 'current_activity', 'PowerOn’) }}"
    turn_on:
      service: remote.turn_on
      data:
        entity_id: remote.harmony_hub
        activity: “16598999”
    turn_off:
      service: remote.turn_on
      data:
        entity_id: remote.harmony_hub
        activity: “-1”
1 Like

What errors are you seeing?

Your YAML file formatting has several errors. I’ve tried to fix most of them:

remote:
  - platform: harmony
    name: Harmony Hub
    host: 10.0.1.253 
    activity: 17928684

group:
  harmony_hub:
    name: Harmony
    control: hidden
    entities:
      - switch.watch_tv
      - switch.play_music
      - switch.play_radio

switch:
  - platform: template
  switches:
    watch_tv:
      friendly_name: Watch TV
      value_template: "{{ is_state_attr('remote.harmony_hub', 'current_activity', ‘?????’) }}"
      turn_on:
        service: remote.turn_on
        data:
          entity_id: remote.harmony_hub
          activity: 19727717
      turn_off:
         service: remote.turn_off
         data:
           entity_id: remote.harmony_hub
           activity: -1
    play_music:
      friendly_name: Play Music
      value_template: "{{ is_state_attr('remote.harmony_hub', 'current_activity', '?????’) }}"
      turn_on:
        service: remote.turn_on
        data:
          entity_id: remote.harmony_hub
          activity: 16598998
      turn_off:
        service: remote.turn_off
        data:
          entity_id: remote.harmony_hub
          activity: -1
    play_radio:
      friendly_name: Play Radio
      value_template: "{{ is_state_attr('remote.harmony_hub', 'current_activity', '?????’) }}"
      turn_on:
        service: remote.turn_on
        data:
          entity_id: remote.harmony_hub
          activity: 16598999
      turn_off:
        service: remote.turn_off
        data:
          entity_id: remote.harmony_hub
          activity: -1

You need to replace the ??? in the value_template: field with the actual name of the activity in the harmony_hub.conf file.

Are you sure the name: field under remote: matches what your actual Harmony Hub is called? It has to be exact.

By default, you should have group: !include groups.yaml near the top of your configuration.yaml file. This means anything related to groups should go in the groups.yaml file and not your configuration.yaml file like you have.

As I mentioned before, are you seeing the Harmony Hub actually show up in Home Assistant? You can check this in the “States” page under “Developer tools” from the HA web UI. Usually the first step when I add anything new is to add just the component first to make sure it shows up in HA before I start adding switches or anything.

Your problem is that you have crap characters that encapsolate your strings on the value template line.

you have:

      value_template: "{{ is_state_attr('remote.harmony_hub', 'current_activity', ‘?????’) }}"

but they should be:

      value_template: "{{ is_state_attr('remote.harmony_hub', 'current_activity', '?????') }}"

And you’re probably saying “But petro, they look the same”. And the answer is no, they aren’t. Take a look at your question marks. Look in the ‘bad’ example, and look at the quotes. Now look at the second example. Do the quotes look the same? No they don’t. You cannot use ‘Microsoft word’ quotes as characters for encapsulating strings.

So in the end, your switch catagory should look like this:

#Switch
switch:
- platform: template
  switches:
    # apple tv activity
    apple_tv:
      value_template: "{{ is_state_attr('remote.livingroom', 'current_activity', 'APPLE TV') }}"
      turn_on:
        service: remote.turn_on
        data:
          entity_id: remote.livingroom
          activity: 'APPLE TV'
       turn_off:
         service: remote.turn_on
         data:
           entity_id: remote.livingroom
           activity: 'PowerOff'
        
    # digital music activity
    music:
      value_template: "{{ is_state_attr('remote.livingroom', 'current_activity', 'Listen to Digital Music') }}"
      turn_on:
        service: remote.turn_on
        data:
          entity_id: remote.livingroom
          activity: 'Listen to Digital Music'
       turn_off:
         service: remote.turn_on
         data:
           entity_id: remote.livingroom
           activity: 'PowerOff'
        
    # radio activity
    radio:
      value_template: "{{ is_state_attr('remote.livingroom', 'current_activity', 'Listen to Radio') }}"
      turn_on:
        service: remote.turn_on
        data:
          entity_id: remote.livingroom
          activity: 'Listen to Radio'
      turn_off:
         service: remote.turn_on
         data:
          entity_id: remote.livingroom
          activity: 'PowerOff'

Word of advice. Never copy from unformatted code. These quotes are a byproduct of that. Use a text editor and never place your code into Microsoft word or any word like editor. I recommend using notepad++.

1 Like

Great catch! I just copied @travtufts YAML and tried to fix most of the errors I saw (I use Atom) - definitely missed that one. Hopefully he’s able to get this to work now.

Thank you, thank you thank you both!

Thanks for the tips, shred, and thank you for the explanation on syntax and proper formatting, petro! I installed ATOM with the yaml linter plugin, and after tweaking some indentations and other stuff I have it all working.

Thank you again!

One last question for you HA gurus: If I have Harmony Activities in separate rooms that I want to be able to run at the same time, what do I need to change in the code? I only entered in a few activities to start, but now that it works I’d like to be able to have the stereo or A/C on in another room while also having the “Apple TV” activity in the main room.

The way it’s set up now only one activity can be active at any time through Home Assistant.

I believe harmony is the limitation here. My harmony remote does not allow more than 1 activity at a time.

Ah, good catch. Seems pretty silly on their part, but you’re right. Thank you again.

You can use device commands to ‘make an activity’ essentially. But you’ll have to do extra leg work to know when it’s on/off.

Did you ever manage to get HA to support the same HomeKit statefulness as Homebridge with the Harmony remote?

There is a work around, if you add buttons to a existing device and use the remote to program commands from the new device you could place multiple devices on one activity without going over the device limit of the harmony hub.

For example I can control my Tv, av switch box, fireplace and a 2nd tv all from my “Vizio” remote in the harmony app. This way I can create one activity and have multiple buttons control multiple devices just from the one harmony “remote” I hope this makes sense to you!

1 Like

Also would like to if anyone got activities states to report properly in HomeKit. Currently Homebridge is running flawlessly for me but I would like to have everything in Home Assistant rather than running Homebridge on the side. If it requires a ton of custom setup and fooling around though it may not be worth my time since Homebridge just works out of the box with very little setup.

Hi Everyone

New HA user. Thanks for the suggestions above. I now have my Harmony Hub activities showing on my Apple Home app and have been using my HomePod with Siri for flawless voice control.

If possible, I would like to add a few more functions to this setup where I can ask Siri to pause/play and mute/unmute through Harmony Hub, but I can’t get it to work. The component itself—a receiver— is old school with no internet access, so I am stuck using Harmony for control. I have tried altering the switch template platform to send commands, but this does not work, or probably I am doing something wrong.

Has anyone been able to do this? Thank you

#Harmony Hub
  - platform: template
    lights:
      theater_volume:
        friendly_name: "Receiver Volume"
        value_template: >-
          {% if is_state('remote.harmony_hub', 'on') %}
            {% if states.remote.harmony_hub.attributes.is_volume_muted %}
              off
            {% else %}
              on
            {% endif %}
          {% else %}
            off
          {% endif %}
        turn_on:
          service: remote.volume_mute
          data:
            entity_id: remote.harmony_hub
            device: 'AV Receiver'
            is_volume_muted: false
        turn_off:
          service: remote.volume_mute
          data:
            entity_id: remote.harmony_hub
            device: 'AV Receiver'
            is_volume_muted: true
        set_level:
          service: remote.volume_set
          data_template:
            entity_id: remote.harmony_hub
            device: 'AV Receiver'
            volume_level: "{{ (brightness / 255 * 100)|int / 100 }}"
        level_template: >-
          {% if is_state('remote.harmony_hub', 'on') %}
            {{ (states.remote.harmony_hub.attributes.volume_level|float * 255)|int }}
          {% else %}
            0
          {% endif %}

Here is my attempt at getting this to work. It shows up in the Home App, but it does nothing.