Bidirectional input slider fo media player

Went throught the examples page but it’s not clear for me how to trigger on volume change

This is the code to pass slider value to media player volume

  - alias: Zal Onkyo Volume Slider
    trigger:
      platform: state
      entity_id: input_slider.zal_onkyo_volume
    action:
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.onkyo
          volume_level: '{{ trigger.to_state.state | int }}'

But how to do the vice versa and change slider value based on volume? What to input for the trigger

 - alias: Zal Onkyo Volume Slider Set
    trigger:
      platform: state
      entity_id: media_player.zal_onkyo (where to put the volume attribute????!)
   action:
     service: input_slider.select_value
     data_template:
      entity_id: input_slider.zal_onkyo_volume
      value: '{{ trigger.payload}}'

Ok managed it like this. Surprisingly didn’t find the solution int the first forum search

- alias: Zal Onkyo Volume Slider Set
  trigger:
    platform: state
    entity_id: media_player.onkyo
  action:
    service: input_slider.select_value
    data_template:
      entity_id: input_slider.zal_onkyo_volume
      value: >
        {{ states.media_player.onkyo.attributes.volume_level }}
1 Like

Thanks for posting!! Huge help for a problem that i’ve been trying to solve for months!

I spoke to soon… it works only with volume of 0 or 1… as sonos does .1 . 4 volumes etc. doesn’t seem to send volume to these.

Anyone else had this issue?

Here is the code i used.

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 guess i was too early to celebrate…
This code doesn’t seem to work

- alias: Zal Onkyo Volume Slider Set
  trigger:
    platform: state
    entity_id: media_player.onkyo
  action:
    service: input_slider.select_value
    data_template:
      entity_id: input_slider.zal_onkyo_volume
      value: >
        {{ states.media_player.onkyo.attributes.volume_level }}

neither this

- alias: Zal Onkyo Volume Slider Set
  trigger:
    platform: state
    entity_id: media_player.onkyo
  action:
    service: input_slider.select_value
    data_template:
      entity_id: input_slider.zal_onkyo_volume
      value: '{{ trigger.to_state.state | float }}'

I believe it’s due that trigger is not correct. But than - this one won’t work either

entity_id: media_player.onkyo.attributes.volume_level

This is working for me:

  - alias: "Denon Get Volume"
    trigger:
      platform: state
      entity_id: media_player.denonamp
    action:
      - service: input_slider.select_value
        data_template:
          entity_id: input_slider.denon_volume
          value: '{{ trigger.to_state.attributes.volume_level }}'

  - alias: "Denon Set Volume"
    trigger:
      platform: state
      entity_id: input_slider.denon_volume
    action:
      service: media_player.volume_set
      data_template:
        entity_id: media_player.denonamp
        volume_level: '{{ trigger.to_state.state }}'

not sure but believe get the following error with this code

ERROR (MainThread) [homeassistant.core] Invalid service data for input_slider.select_value: expected float for dictionary value @ data[‘value’]. Got ‘’

There are some issues with getting the initial value, since there is no volume value when the receiver is off. This can be solved using a sensor. I am still working on it, but this is my work in progress:

  - platform: template
sensors:
  harmonystue:
    value_template: '{{ states.remote.harmonystue.attributes.current_activity }}'
  denon_volume:
    value_template: >
      {% if is_state('media_player.denonamp', 'on')  %}
        {{ (states.media_player.denonamp.attributes.volume_level * 100 - 80) | round(2) }}
      {% else %}
        0.0
      {% endif %}
    unit_of_measurement: 'dB'

Yes that’s the main problem. But still seems the slider is not updated when the volume on onkyo is changed

Did anyone get this finished in the end?

Still struggling to get the slider to update when something else changes the media_player volume. I’m on Chromecast in this case.

“Invalid service data for input_slider.select_value: expected float for dictionary value @ data[‘value’]. Got “‘0.47999998927116394’”” is the error I’m getting, but I’m guessing this is data type error?

Hello,

Did you get an answer? Here’s my automation for Chromecast that work for me. Most of the time:

- id: myID13
  alias: Playroom Chromecast Audio - Adjust volume
  trigger:
    platform: state
    entity_id: input_number.playroom_volume
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.playroom
        volume_level: '{{ states.input_number.playroom_volume.state | multiply(0.01) }}'    

- id: myID16
  alias: Set Playroom CC volume slider
  hide_entity: True
  trigger:
    platform: state
    entity_id: media_player.playroom
  action:
    service: input_number.select_value
    data_template:
      entity_id: input_number.playroom_volume
      value: "{{states.media_player.playroom.attributes.volume_level | multiply (100) | int}}"
2 Likes

This is great, thanks for sharing. Looks like this was designed to be used with a 0-100 slider with 10-step increments. Works well for me with the below in my config:

input_number:
  kitchen_volume:
    name: Speaker Volume
    initial: 40
    min: 0
    max: 100
    step: 10

I moved from Github to Gitlab, so the above link no longer works, now hosted here:

Chromecast volume update control