Harmony Activities, Volume Slider, and Lovelace

Thanks for posting that, Tom! When I saw that you also have an NR626 and had switched the divide and multiplication between the two automations, I had hoped that was my issue. Unfortunately, I still get a negative feedback loop that I don’t understand.

I’ve even pulled out all of my volume control and monitoring portions of my Lovelace cards on the off chance that I had created something bad there, but it still exists, so I just don’t know where else it could be coming from… :roll_eyes:

Maybe one of these months I’ll track it down.

Thanks!

Hmmm… I just noticed this in my logs. I don’t know what this means.

Onkyo Volume (Slider to Media): Error executing script. Invalid data for call_service at pos 1: value must be at most 1 for dictionary value @ data['volume_level']
Successfully saved

Edit- Does anybody know how to look at the code the built in Onkyo media player uses? The volume slider there functions perfectly bidirectional.

1 Like

0.113 is a bit faster at updating state.

If you were doing something like this https://github.com/home-assistant/core/issues/37905#issuecomment-659526200

You may need to adjust to something like this instead: https://github.com/home-assistant/core/issues/37905#issuecomment-660286573.

I managed to get my Harmony activities working, thanks to petro and his thread here, but now I cannot figure out how to add more actions to those switches, or how should I approach this. For example, my Harmony activity switch that turns on TV and Nvidia Shield is like this (based on petro’s switch):

    # SHIELD+TV
    shield_tv:
      friendly_name: 'Shield+TV'
      value_template: "{{ is_state_attr('remote.harmony_hubi', 'current_activity', 'Shield+TV') }}"
      turn_on:
        service: remote.turn_on
        data:
          entity_id: remote.harmony_hubi
          activity: 'Shield+TV'
      turn_off:
        service: remote.turn_on
        data:
          entity_id: remote.harmony_hubi
          activity: 'PowerOff'

My TV is plugged in Sonoff S20 plug, so I have power off when TV is not in use. So, I would like to add a sequence that when “Shield+TV” -activivity switch is pressed in HA UI, it first turns on switch.sonoffs202 , then 0,5 second delay, and then start the activity. Same thing, when activity is turned off, sonoff is also powered off in the end, after suitable delay.

Also, I would like to check if some device is in use in the next activity I am switching in to, so that I don’t have to switch sonoffs off and on all the time. For example, if I switch from Shield+TV to Blu-Ray+TV, then sonoffs202 switch stays on, but if I switch from Shield+TV to BluRay+Projector, then it switches off sonoffs202 (and naturally switches on other needed sonoffs).

What would be the easiest solution for adding these extra sequences in the switch in your opinion?

So just add the service and delay to turn on

      turn_on:
      - service: switch.turn_on
        entity_id: switch.sonoffs202
      - delay:
          seconds: 0.5
      - service: remote.turn_on
        data:
          entity_id: remote.harmony_hubi
          activity: 'Shield+TV'
1 Like

if you want that, you need to make a separate script that turns on the sonoff202 with a condition at the start. The condition checks to see if the sonoff is off. Then have the turnon, and delay.

Thank you! Turns out I had written pretty much the same code already, but did not have “-” characters in front of services and delays, but now that I think of it, of course, that’s how it works :slight_smile: As in your original code, there was only one service, and now in this, there are several. That’s one PITA thing in Home Assistant: even the slightest error in syntax just return some error message where you need to guess if your code is wrong, or is it basically just the syntax…

But now it works, and based on your example, I naturally did the same thing with turn_off service: first turn off the activity, then delay, then switch off sonoff :slight_smile:

The error messages try to clue you to the correct area. But if you don’t know the lingo, it won’t be helpful.

EDIT: I’m assuming you got ‘extra keys not allowed’, or something abotu ‘delay not having service as a valid key’ or vice versa.

Hmm. So in this case, I would need to approach these activities different way, not as separate on-off switches, but separate buttons that only start the activity (with suitable sonoffs) when pressed, and also check if those sonoffs that belong to that activity are already switched on, right? And then one button (maybe called “End current activity” that just turns off everything, including sonoffs. I could send all possible PowerOffs and switch all sonoffs off as well with that one button. Could that work? :slight_smile:

Yah, there’s a number of ways to do this. You could even write a single script to handle this and just pass a different entity_id to it. In 0.113, scripts can run concurrently so it will always work properly. Personally, I’d go that route. 2 scripts, 1 for on, 1 for off.

EDIT: There’s also going to be a number of other changes too. Like a choose option. So you may be able to do this with 2 total scripts and pass in the activity and switch entity.

Sounds efficient! Could you give an example how to do this? :slight_smile:

Although if I understood right, it doesn’t work yet? My HASS is version 0.112.4 and seems to be the latest at the moment…

It’ll be in the release which should be wednesday. I don’t know the current syntax because it’s changed so many times. We’ll have to wait til the docs are updated, which should also be wednesday.

1 Like

I have got switches to work for start activities but how do I control the devices? I would like to get an D-Pad and home buttons etc. Anyone got any lovelace UI that I can get inspiration from.

That’s a rabbit hole. Basically, you need to make a script for each d-pad direction. The script itself will have a template that properly places the correct device id based on the current activity. I made an appdaemon app to do this for me, but I haven’t released it to the public because it’s rather complicated to set up.

Yes that will be a lot of scripts since a remote use many buttons. Can you just show a script for 2 buttons on a device? I would probably figure out the rest after that.

In Lovelace you can call remote.send_command as a tap_action. You can also pass variables to a script so you can reuse it.

Thanks for your answer. Yes, I did create buttons using that method.

Hey Petro, thanks for your patience on this matter, maybe you can help one more person haha, here is my issue, the picture will load in the off state but not for when an activity is actually on. Any ideas?

Would only let me post one photo, I’m positive my directories are correct because it is working for the off image

Playstation

     - type: vertical-stack
       cards:
         - type: picture-glance
           title: Living Room TV
           entities:
             - switch.tanners_ps4
             - switch.marshalls_ps4
             - switch.apple_tv
           state_image:
             "PowerOff": /local/images/off.png
             "Tanners PS4": /local/images/tanners_ps4.png
             "44550360": /local/images/marshalls_ps4.png
             "Watch Apple TV": /local/images/apple_tv.png
           tap_action:
             action: toggle
           entity: sensor.harmony_activity

verify that the sensor.harmony_activity has the correct state. Could be a spelling error.

Thanks for the quick reply, i cant find anything wrong with the sensor.

sensor:
  - platform: template
    sensors:
      harmony_activity:
        value_template: >
          {% if is_state("remote.Bedroom", 'on') %}
            {{ states.remote.Bedroom.attributes.current_activity }}
          {% else %}
            PowerOff
          {% endif %}

yeah but what’s the name of the current_activity when the image doesn’t work