Sync volume

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') }}"
3 Likes

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.