Harmony Activities, Volume Slider, and Lovelace

You’re in a situation where harmony does not report a devices status through the API. In my opinion, this is a major design flaw of harmony (Not home assistant). Harmony just doesn’t give that information out which is kind of counter intuitive for any device automating harmony.

So with that being said, you really only have 1 option.

Create an input boolean that represents the state of your device.

input_boolean:
  device_64156777:

Then use that input boolean to represent the state of your switch, while also toggling the input boolean.

- platform: template
  switches:
    remote:
      value_template: "{{ is_state('input_boolean.device_64156777', 'on') }}"
      turn_on:
      - service: input_boolean.turn_on
        entity_id: input_boolean.device_64156777
      - service: remote.send_command
        data:
          entity_id: remote.harmonyhub
          command:
            - PowerOn
          device: 64156777
      turn_off:
      - service: input_boolean.turn_off
        entity_id: input_boolean.device_64156777
      - service: remote.send_command
        data:
          entity_id: remote.harmonyhub
          command:
            - PowerOff
          device: 64156777

You may need to separate turn_on and turn_off into their own scripts. if the turn_on section does not allow multiple actions. A generic script for all devices that power on and power off would look like this:

script:
  power_harmony_device:
    sequence:
      - service_template: input_boolean.turn_{{ command.lower().replace('power','') }}
        data_template:
          entity_id: input_boolean.device_{{ device }}"
      - service: remote.send_command
        data_template:
          entity_id: remote.harmonyhub
          command:
            - "{{ command }}"
          device: "{{ device }}"
- platform: template
  switches:
    remote:
      value_template: "{{ is_state('input_boolean.device_64156777', 'on') }}"
      turn_on:
        service: script.power_harmony_device
        data:
          device: 64156777
          command: PowerOn
      turn_off:
        service: script.power_harmony_device
        data:
          device: 64156777
          command: PowerOff

Keep in mind, if you go the script route, you need to name all input booleans: input_boolean.device_<device_number>, e.g. input_boolean.device_64156777

1 Like

Thank you, I like the idea, but how do I create such script, where do I put it?
ConfigurationScripts complains on

Message malformed: extra keys not allowed @ data[‘sequence’][0][‘script’]

when I edit script as YAML and pasting your code into /config/scripts.yaml fails configuration check with

Error loading /config/configuration.yaml: invalid key: “OrderedDict([(‘command’, None)])”
in “/config/scripts.yaml”, line 11, column 0

I’m sorry for having presumably dumb questions - I’m trying to grasp HA coding concept :confused:

you place it in scripts but omit the scripts section header if you use the gui

1 Like

I prefer config files whenever possible, but still config check doesn’t like “OrderedDict([(‘command’, None)])”, which is the “- {{ command }}” part.

script: !include scripts.yaml

or a merged list, omit the script: field inside the scripts.yaml file or the named yaml file.

Also, I made a mistake in the script, needs quotes around command and device. I edited the previous post.

1 Like

OK, it passed config check now. Also it needed to loose “device_” part and a quote in the end in the line

entity_id: input_boolean.device_{{ device }}"

Now TV turns on (I labeled boolean as “device_tv”, but toggle is not working again :smiley:
scripts.yaml

# Power a Harmony device
power_harmony_device:
  sequence:
    - service_template: input_boolean.turn_{{ command.lower().replace('power','') }}
      data_template:
        entity_id: input_boolean.{{ device }}
    - service: remote.send_command
      data_template:
        entity_id: remote.harmonyhub
        command:
          - "{{ command }}"
        device: "{{ device }}"

switches.yaml

- platform: template
  switches:
    remote:
      value_template: "{{ is_state('input_boolean.device_tv', 'on') }}"
      turn_on:
        service: script.power_harmony_device
        data:
          device: 64156777
          command: PowerOn
      turn_off:
        service: script.power_harmony_device
        data:
          device: 64156777
          command: PowerOff

A little update: configuration before is again working one-way, like before if TV is off, it turns it on and slider goes back to “OFF” position. I’m stuck :frowning:
And another question: how do I rename my switch, because configuration fails if I change “remote” to something else?

You can’t lose device. Do not name your input booleans starting with a number. You’ll have nothing but problems.

You can’t use these buttons if you don’t follow the naming convention laid out. Naming it device_tv will cause it to break. It needs to be named device_64156777. Or the template needs to change drastically.

So your options are:

Name your input_boolean entity_id’s device_<number> and use the original script that I created

of

Come up with a new template that satisfies your current need, mapping tv to the number 64156777.

1 Like

Device is used in this template

      entity_id: input_boolean.device_{{ device }}"

and this template

      device: "{{ device }}"

If you call the script like this:

        service: script.power_harmony_device
        data:
          device: 64156777
          command: PowerOn

This input_boolean.device_{{ device }} template resolves to input_boolean.device_64156777. Not input_boolean.device_tv. Which is your problem.

1 Like

Okay, I got the dea now, thanks alot, mate! But still,

have to loose ending quote, the " symbol, otherwise it’s not working. I renamed switches to my liking and next stop is volume control in HA, but I want to do it myself. Thank you again for your guidance!

1 Like

Your problem is you’re not using Activities properly, unless it’s things like a light you may or may not want on during a particular activity. Devices like a TV should only be switched as part of an activity start or stop.

Assume you mean it doesn’t report what it thinks the state is as Harmony doesn’t know for sure, it just assumes it has turned something on or off. If using Activities as intended it’s not a big deal to let HA use the Activity status to come to the same conclusion.

Right but if you just want to have a device with an on/off state and no activity (which is what he is doing), it’s not possible with harmonys api. Even if the device reports a state. For example, I have network receivers that report states. Harmony does not report this to home assistant.

Like I said though, it doesn’t report it’s state to Harmony, Harmony just assumes based on the buttons you’ve pressed as it is really just a glorified IR remote which is one way by definition.

If the device does report a state you can use that directly with HA. For example, I have several lights and a fan switched by Harmony but I control them via the emulated Roku component in HA so their state is registered fine. I also have things like my AVR and TV controlled directly by Harmony but they also have their own integration within HA so again you can get real reports of state change directly to use in automations.

I don’t know why this is even a debate… the poster asking the question has only mentioned harmony without an activity and just a device. Therefore, to make a switch work you have to assume a state, which is what was done.

1 Like

Thank you for this guide, I was able to setup my harmony remote and my denon receiver. I just had to remove a couple of lines from the automation to make the volume slider work since denon now uses 0-100 for its volume and no longer dB. Just figured I would post the code in case it might help out someone else.

- alias: Zone 1 Volume (Media to Slider)
  trigger:
    - platform: state
      entity_id: media_player.denon_avr
  action:
      service: input_number.set_value
      data_template:
        entity_id: input_number.denon_receiver
        value: >
          {{ ( ( trigger.to_state.attributes.volume_level | float ) * 100.0 ) }}

- alias: Zone 1 Volume (Slider to Media)
  trigger:
    - platform: state
      entity_id: input_number.denon_receiver
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.denon_avr
        volume_level: >
          {{ ( trigger.to_state.state | float / 100.0) }}
2 Likes

I’m sorry, couldn’t answer right away. What do you mean “should”, why can’t I choose how to control devices? I would very much like having actual state in realtime, but I am yet to test integration possibilities for everything I need. Plus, during activties I have to account for several devices controls, which has same buttons with different actions for each device, like red/yellow/blue/green buttons, for instance. I need those button for media player and receiver both, but there is only a one set of them on Harmony Remote, thus I have to switch to “Devices” mode, choose needed, perform required action and switch back to the current activity mode. So, yes, I do have need for individual commands use.
And as for individual integration, it works well if all components have corresponded integrations up and running, which is hardly ever the case, compromises are everywhere.

Hi HeffeD
Thanks for sharing your way of doing it with an Onkyo reciever.
I have the same issue than you with the volume slider (kind of works but go down to 0 after 1 second)
Did you find a solution ? Could you please share ?
Thanks in advance
(and thanks petro for the work done!!)

Edit: Adapting code from Mar16 is working (22nd of May post). Thanks everyone

Hi Tom!

Would you mind sharing your adaptations? I’ve tried using that code and still have the same issue as before.

Thanks!

This is what i have for an Onkyo NR626.
Min Volume:0 (0 as well on hassio)
Max Volume: 78 (0.975 in hassio)
so Step = 0.0125
(sometimes on the sliders it shows 23.9999999 instead of 24 but not going back to 0)

- alias: Onkyo Volume (Media to Slider)
  initial_state: on
  trigger:
    - platform: state
      entity_id: media_player.AmpliHC
  action:
     service: input_number.set_value
     data_template:
       entity_id: input_number.harmony_my_volume
       value: >
          {{ ( ( trigger.to_state.attributes.volume_level | float ) / 0.0125 ) }}


- alias: Onkyo Volume (Slider to Media)
  initial_state: on
  trigger:
    - platform: state
      entity_id: input_number.harmony_my_volume
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.AmpliHC
        volume_level: >
          {{ ( trigger.to_state.state | float * 0.0125) }}

```
1 Like