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.
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) }}
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) }}
```
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…
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.
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'
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 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
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?
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?
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.
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.