Hi!
i want to sync volume between two different media_player.
Volume is an attribute for both entity.
When i change the volume on media player A i want that media_player B change too.
Is it possible to create an automation ?
Hi!
i want to sync volume between two different media_player.
Volume is an attribute for both entity.
When i change the volume on media player A i want that media_player B change too.
Is it possible to create an automation ?
It is possible. You have to create trigger base on entity attribute.
Here is the example:
automation:
trigger:
platform: numeric_state
entity_id: sensor.temperature
# Optional
value_template: "{{ state.attributes.battery }}"
# At least one of the following required
above: 17
below: 25
# If given, will trigger when condition has been for X time, can also use days and milliseconds.
for:
hours: 1
minutes: 10
seconds: 5
Then you have to call a service to set a volume on another media_player entity.
Thanks for your help.
I 'll try this:
- alias: 'manage volume'
trigger:
- platform: numeric_state
entity_id: media_player.salon
value_template: "{{ state.attributes.volume_level }}"
above: 0
condition: []
action:
- service: media_player.volume_set
data:
entity_id: media_player.cuisine
volume_level: ??
For āvolume_levelā how can i call the volume level attribute of the media_player.salon?
{{ state_attr('media_player.salon', 'volume_level') }}
Great thanks, almost!
- alias: 'manage volume'
trigger:
- platform: numeric_state
entity_id: media_player.salon
value_template: "{{ state.attributes.volume_level }}"
above: 0
condition: []
action:
- service: media_player.volume_set
data_template:
entity_id: media_player.cuisine
volume_level: "{{ state_attr('media_player.salon', 'volume_level') }}"
It works the first time i change the volume on media_player.salon, they are sync. But it only works one timeā¦? strange. Any idea?
I can set a trigger every seconde but itās not very smartā¦
Maybe HA is preventing a loop here. You could also just have a trigger listen for any state change with a sensor
#sensor:
- platform: template
sensors:
salon_volume:
value_template: >
{{ state_attr('media_player.salon', 'volume_level') }}
#automation:
- alias: manage volume
trigger:
- platform: state
entity_id: sensor.salon_volume
action:
- service: media_player.volume_set
data_template:
entity_id: media_player.cuisine
volume_level: "{{ states('sensor.salon_volume') }}"
Yes! Thank you @Mattias_Persson!! Youāre the best!
this automation works as intended. all you need to do is add the following at the end
service: automation.reload
reason is firs trigger happens when value moves above zero, after that any other movements wont trigger.
reloading the automation, starts the process all over.
Thanks for the thread! Got my volume syncing.
Anyone know how I can subtract so the volumes are pegged but not the same.
I tried
volume_level: "{{ state_attr('media_player.salon', 'volume_level') - 10 }}"
and
volume_level: "{{ state_attr('media_player.salon', 'volume_level') }} - 10"
and
volume_level: "{{ state_attr('media_player.salon', 'volume_level') }}" - 10
and one or two of those saved, but did not work.
Thanks.
Well, obviously none of those would work. The last one is not a even valid template. The second one is, but would result in a string that literally prints out āX.XX - 10ā where X.XX is the current volume.
The first one would perform a calculation alright, but end up with a value somewhere between -10 and -9. The range of the volume_level
attribute is not an integer 0ā100 but a float 0ā1.
Thus the way to do it would be this:
volume_level: "{{ state_attr('media_player.salon', 'volume_level') - 0.1 }}
Tried that too, but without the ā0ā.
Thank you. It works
Hi all,
New to the community and fairly new to building automations.
Iām trying to do exactly this, sync volums between 2 media players.
For my case itās the main zone and zone 2 of my Denon AVR.
Main zone is at the TV and Zone 2 is the additional speakers at the other side of the room in the kitchen area.
I managed to make automations so Zone 2 switches on when I switch to Spotify or Tuner and it switches back to main zone (zone 2 switches off again) only when I switch to my TV input again.
All good.
Now I want to sync the volume of the main zone and zone 2. When I change the volume of the main zone, zone 2 changes accordingly (but with an offset of + 0.05)
Iām terrible at this YAML code stuff (trying hard to learn) so Iām getting stuck.
Seems like the YAML code has changed slightly since the posts from 2020?
I made this part:
description: Sync volume Main zone and zone2
platform: template
sensors:
mainzone_volume:
value_template:
{{ state_attr('media_player.denon_avr_x1800h', 'volume_level') }}
But when I lookup entity āsensor.mainzone_volumeā in the developer tools > states it says āstate unknownā
so this first step isnāt working for me.
@danieljbrennan would you mind sharing the code you are using? As Iām expecting itās slightly nupdated from the 2020 version above?
Thanks for the help, appreciated!