Setting slider to manual volume change

I have set up a slider to contro volume of myAVR with a slider. How do I get the slider to update if the volume is adjusted manually. In other words trigger an automation to set the value of the slider. My config for the slider control is as follows:

media_player:
platform: denon_avr
host: 192.168.1.101
name: Denon AVR

input_slider:
denon_volume:
name: Volume
initial: 0.3
min: 0
max: 1
step: 0.01
automation 4:

  • alias: Denon - Adjust Volume
    trigger:
    platform: state
    entity_id: input_slider.denon_volume
    action:
    • service: media_player.volume_set
      data_template:
      entity_id: media_player.denon_avr
      volume_level: ‘{{ trigger.to_state.state }}’
1 Like

Please post your code properly so that any issues with formatting can be ruled out.

To post code with formatting intact, highlight the code blocks and then press the preformatted text option button as indicated in the image below.

Thanks…completely new to this. Formatted code below. As I said, the code is working fine. It sthe next step of feeding back information to the slider where I don’t know where to begin.

media_player:
platform: denon_avr
host: 192.168.1.101
name: Denon AVR

media_player:
  platform: denon_avr
  host: 192.168.1.101
  name: Denon AVR

input_slider:
  denon_volume:
    name: Volume
    initial: 0.3
    min: 0
    max: 1
    step: 0.01

automation 4:
  - alias: Denon - Adjust Volume
    trigger:
      platform: state
      entity_id: input_slider.denon_volume
    action:
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.denon_avr
          volume_level: '{{ trigger.to_state.state }}'

Any luck implementing the volume feedback to slider ?
Exactly trying to do this, but unable to find a suitable trigger.

- alias: Music Volume Select
  trigger:
    platform: state
    entity_id: media_player.music
  action:
    service: input_slider.select_value
    data_template:
      entity_id: input_slider.music
      value: >
        {{ states.media_player.music.attributes.volume_level }}
1 Like

Thanks, this works!

Has anyone had any luck getting this working with Sonos?

I have set it up but it will only update the volume at 1… and go back to 0, nothing in between (e.g. 0.1 - 0.3 etc where sonos needs the volume set)

volume:
  name: Volume
  initial: .2
  min: 0
  max: 1
  step: 0.01


- alias: Kitchen Sonos Volume Slider
  trigger:
    platform: state
    entity_id: input_slider.volume
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.kitchen
        volume_level: '{{ trigger.to_state.state | int }}'

I also tried it the way mentioned above but that didn’t work at all :frowning: for me.

- alias: Kitchen Music Volume Select
  trigger:
    platform: state
    entity_id: media_player.kitchen
  action:
    service: input_slider.select_value
    data_template:
      entity_id: input_slider.music
      value: >
        {{ states.media_player.kitchen.attributes.volume_level }} 

input slider:

music:
  name: Sonos Volume
  initial: .2
  min: 0
  max: 1
  step: 0.01

Hi @Stewface

I think you use the wrong trigger for your automation.

Your Automation must run, when the Volume is changed.

I’m using for my denon:

- alias: Denon Volume
  trigger:
    platform: state
    entity_id: input_slider.volume_setpoint
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.denon
        volume_level: '{{ states.input_slider.volume_setpoint.state}}'

So for you it should like:

- alias: Kitchen Music Volume Select
  trigger:
    platform: state
    entity_id: input_slider.sonos_volume
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.kitchen
        volume_level: '{{ states.input_slider.sonos_volume.state }}'

This is untested and maybe don’t work. But it should be something in this direction.

2 Likes

input_slider.yaml

living_room:
  name: Living Room
  initial: 0.3
  min: 0
  max: 1
  step: 0.01
kitchen:
  name: Kitchen
  initial: 0.3
  min: 0
  max: 1
  step: 0.01

Automation.yaml

- alias: living_room - Adjust Volume
  trigger:
    platform: state
    entity_id: input_slider.living_room
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.living_room_speakers
        volume_level: '{{ trigger.to_state.state }}'

- alias: kitchen - Adjust Volume
  trigger:
    platform: state
    entity_id: input_slider.kitchen
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.kitchen_speakers
        volume_level: '{{ trigger.to_state.state }}'

# second part of volume

- alias: kitchen - Volume
  trigger:
    platform: state
    entity_id: media_player.kitchen_speakers
  action:
    - service: input_slider.select_value
      data_template:
        entity_id: input_slider.kitchen
        value: '{{ states.media_player.kitchen_speakers.attributes.volume_level }}'

- alias: living room - Volume
  trigger:
    platform: state
    entity_id: media_player.living_room_speakers
  action:
    - service: input_slider.select_value
      data_template:
        entity_id: input_slider.living_room
        value: '{{ states.media_player.living_room_speakers.attributes.volume_level }}'

this is working fine for me. Check the spaces though because I dont think im using the </> thing correctly.

3 Likes

@benjimatt - WORKING!!! WAHOOOO!!

I’ve been wanting to get this working for so long… THIS IS AMAZING!

2 Likes

It works perfect for Sonos… thank you so much…

Any ideas why the same script might not work with my sony bravia TV?

Interestingly I noticed even the volume control slider on the pop up dialog doesn’t work (only the clicking the volume icons will adjust the volume)

Hi… Looking good but seems not working in Version 47?

Output looks good but nothing happens.

Sven

  • alias: wohnzimmer - Adjust Volume
    trigger:
    platform: state
    entity_id: input_slider.sonos_lautstaerke_wohnzimmer
    action:

    • service: media_player.volume_set
      data_template:
      entity_id: media_player.wohnzimmer
      volume_level: ‘{{ trigger.to_state.state }}’
  • alias: wohnzimmer room - Volume
    trigger:
    platform: state
    entity_id: media_player.wohnzimmer
    action:

    • service: input_slider.select_value
      data_template:
      entity_id: media_player.wohnzimmer
      value: ‘{{ states.media_player.wohnzimmer.attributes.volume_level }}’

input_slider:
sonos_lautstaerke_wohnzimmer:
name: Vol. Wohnzimmer
initial: 0.2
min: 0
max: 1
step: 0.01

good evening,

i try this in the HA v. 0.57.2

my Code work with 3x Sonos:

Input_number.yaml

sonos_lautstaerke:
    name: Lautstärke
    initial: 6
    min: 1
    max: 20
    step: 1

automation.yaml

#### Sonos-Lautstärke
  - alias: Sonos Lautstärke
    trigger:
      platform: state
      entity_id: input_number.sonos_lautstaerke
    action:
      - service: media_player.volume_set
        data_template:
          entity_id:
           - media_player.schlafzimmer
           - media_player.wohnzimmer
           - media_player.kueche
          volume_level: '{{ trigger.to_state.state | multiply(0.1) }}'
                    
  - alias: living room - Volume
    trigger:
      platform: state
      entity_id: media_player.schlafzimmer
    action:
      - service: input_number.set_value
        data_template:
          entity_id: input_number.sonos_lautstaerke
          value: '{{ states.media_player.schlafzimmer.attributes.volume_level }}'

And this work, the volume change if i switch the slider… but one Problem:

the log say:

WARNING (MainThread) [homeassistant.components.input_number] Invalid value: 0.09 (range 1.0 - 20.0)

someone has an idea?

What if you set the input_number min value to 0?

it’s change automatic to 0, when i change the volume…

With this works now perfect!

input_number.yaml

sonos_lautstaerke:
name: Lautstärke
initial: 0.14
min: 0.01
max: 0.2
step: 0.01

automation.yaml

#### Sonos-Lautstärke
  - alias: Sonos Lautstärke
    trigger:
      platform: state
      entity_id: input_number.sonos_lautstaerke
    action:
      - service: media_player.volume_set
        data_template:
          entity_id:
           - media_player.schlafzimmer
           - media_player.wohnzimmer
           - media_player.kueche
          volume_level: '{{ trigger.to_state.state }}'
          #volume_level: '{{ trigger.to_state.state | multiply(0.1) }}'
          
  - alias: living room - Volume
    trigger:
      platform: state
      entity_id: media_player.schlafzimmer
    action:
      - service: input_number.set_value
        data_template:
          entity_id: input_number.sonos_lautstaerke
          value: '{{ states.media_player.schlafzimmer.attributes.volume_level }}'
2 Likes

Thanks for these two automations. However, I guess they sometimes can end up in some kind of feedback loop, where one automation is triggered since the other changed the slider. Whenever I change the volume from outside of HASS, I will get this feedback loop. Is there any way to not have the set volume automation triggered if the input_number was updated by the second automation?

1 Like

Just an FYI on Input_Number. When you look at the examples at the componants page you will see that the automations use "data_template: rather than “data:”. Hassio users like myself, will have to open your automations.conf file and manually edit the entry, changing “data:” to “data_template:” I beat my head against the wall for quite some time before I realized that.