Input Number/Volume Slider for Yamaha Receiver & Google home

Also, there are no errors related to the sliders in the log, that error calls out the custom ui html doc

ok i didnt know.

wait i will retry

Petro thank you very much it Works but partialy.

Google home perfect!

Yamaha the volume is truning down to 0 by itself if i move the slider

No automation errors on the log but the yamaha slider is broken

Thanks

not sure, they should work the same. Check for typos in the code i pasted. For your information, the code I posted is not bullet proof. Home assistant will error if you move the slider when the media_player is off.

Thanks petro i doubled checked the typo and everything seems correct.

I don’t understand.

follow the code, something is setting the value to zero. Do you have old automations in your automation section?

No i just checked again, i have nothing that could make the volume of the receiver going down to 0.

It’s crazy because the code you posted works fine excepted this

works fantastic, also in hadashboard. Thanks!!!

2 Likes

I know this is an old post, but is there a good solution to avoiding the error?

what’s the error exactly, word for word

I have a couple of problems.
I am using the Yamaha TSR7850. When I just implement your code from:

I get the following error:
Error during template condition: UndefinedError: 'mappingproxy object' has no attribute 'volume_level'
Also, my receiver has the following states: off, idle & playing, so your code didn’t function as intended out of the box. The state buttons didn’t show when the receiver was on. I have tried to change the code to the following:
- platform: template
switches:

    # 
- platform: template
  switches:
    # ZONE 1 MEDIA SWITCH
    zone_1:
      value_template: "{{ not is_state('media_player.yamaha_receiver', 'off') }}"
      turn_on:
        service: media_player.turn_on
        entity_id: media_player.yamaha_receiver
      turn_off:
        service: media_player.turn_off
        entity_id: media_player.yamaha_receiver
    # ZONE 2 MEDIA SWITCH
    zone_2:
      value_template: "{{ not is_state('media_player.yamaha_receiver_zone_2', 'off') }}"
      turn_on:
        service: media_player.turn_on
        entity_id: media_player.yamaha_receiver_zone_2
      turn_off:
        service: media_player.turn_off
        entity_id: media_player.yamaha_receiver_zone_2

That made the state switches work, but nothing happens when I move the volume sliders.It moves but doesn’t change the volume.

Any ideas?

Here is the rest of my code:

input_number:
  yamaha_receiver:
    name: Zone 1 Volume
    initial: -80
    min: -80
    max: 0
    step: 5
    unit_of_measurement: dB
    
  yamaha_receiver_zone_2:
    name: Zone 2 Volume
    initial: -80
    min: -80
    max: 0
    step: 5
    unit_of_measurement: dB

- alias: Zone 1 Volume (Media to Slider)
  trigger:
    - platform: state
      entity_id: media_player.yamaha_receiver
  condition:
    - condition: template
      value_template: >
        # convert to decibel.
        {% set converted = ( -1.0 + trigger.to_state.attributes.volume_level | float ) * 100.0 | round(0.0) %}
        # Removes feedback loop
        {{ converted != states('input_number.yamaha_receiver') | float }}
  action:
     service: input_number.set_value
     data_template:
       entity_id: input_number.yamaha_receiver
       value: >
          {{ ( ( -1.0 + trigger.to_state.attributes.volume_level | float ) * 100.0 ) | round(0.0) }}

- alias: Zone 1 Volume (Slider to Media)
  trigger:
    - platform: state
      entity_id: input_number.yamaha_receiver
  condition:
    - condition: template
      value_template: >
        # convert from decibel.
        {% set converted = (1.0 - trigger.to_state.state | float / 100.0) | round(2) %}
        # Removes feedback loop
        {{ converted != state_attr('media_player.yamaha_receiver','volume_level') | float }}
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.yamaha_receiver
        volume_level: >
          {{ (1.0 - trigger.to_state.state | float / 100.0) | round(2) }}

- alias: Zone 2 Volume (Media to Slider)
  trigger:
    - platform: state
      entity_id: media_player.yamaha_receiver_zone_2
  condition:
    - condition: template
      value_template: >
        # convert to decibel.
        {% set converted = ( -1.0 + trigger.to_state.attributes.volume_level | float ) * 100.0 | round(0.0) %}
        # Removes feedback loop
        {{ converted != states('input_number.yamaha_receiver_zone_2') | float }}
  action:
     service: input_number.set_value
     data_template:
       entity_id: input_number.yamaha_receiver_zone_2
       value: >
          {{ ( ( -1.0 + trigger.to_state.attributes.volume_level | float ) * 100.0 ) | round(0.0) }}

- alias: Zone 2 Volume (Slider to Media)
  trigger:
    - platform: state
      entity_id: input_number.yamaha_receiver_zone_2
  condition:
    - condition: template
      value_template: >
        # convert from decibel.
        {% set converted = (1.0 - trigger.to_state.state | float / 100.0) | round(2) %}
        # Removes feedback loop
        {{ converted != state_attr('media_player.yamaha_receiver_zone_2','volume_level') | float }}
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.yamaha_receiver_zone_2
        volume_level: >
          {{ (1.0 - trigger.to_state.state | float / 100.0) | round(2) }}

for this error add a condition in the volume automations that verifies that the state isn’t off.

I just threw those equations together for that post. I actually don’t use it, I use appdeamon. Someone else came accross my post recently and I had found errors in the equations.

These are the updated equations and they should work. You may need to remove the condition.

- id: denon_media_to_slider
  alias: Zone 1 Volume (Media to Slider)
  trigger:
    - platform: state
      entity_id: media_player.denon_avr_3310
  condition:
    - condition: template
      value_template: >
        # convert to decibel.
        {% set converted = ( -1.0 + trigger.to_state.attributes.volume_level | float ) * 100.0 | round(0) %}
        # Removes feedback loop
        {{ converted != states('input_number.denon1_receiver') | float }}
  action:
     service: input_number.set_value
     data_template:
       entity_id: input_number.denon1_receiver
       value: >
          {{ ( (-1.0 + trigger.to_state.attributes.volume_level | float ) * 100 ) | round(0) }}

- id: denon_slider_to_media
  alias: Zone 1 Volume (Slider to Media)
  trigger:
    - platform: state
      entity_id: input_number.denon1_receiver
  condition:
    - condition: template
      value_template: >
        # convert from decibel.
        {% set converted = (1.0 + trigger.to_state.state | float / 100) | round(2) %}
        # Removes feedback loop
        {{ converted != state_attr('media_player.denon_avr_3310','volume_level') | float }}
  action:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.denon_avr_3310
        volume_level: >
          {{ (1.0 + trigger.to_state.state | float / 100) | round(2) }}

Thanks,

Got rid of the error, but couldn’t quite get the Conditions to work, so I removed them.

I had this working perfectly but since updating my hassio to the latest version it doesn’t work anymore. Any idea what I have to change? I had it working perfectly from the initial instructions.

Cheers.

is there an example for this condition available? i have this too :slight_smile:

edit:
nl, added below, and error gone

  condition:
    - condition: template
      value_template: '{{ not is_state("media_player.denon_avrx4000", "off") }}'

Yep, that’s the condition that I would have used.