Input Number/Volume Slider for Yamaha Receiver & Google home

I pasted your code without the home assistant start trigger and having the same error.

I’m triyng to understand.

I can verify entity_id from dev tools states, how can check the trigger keys list?

Thanks.

I’m not sure then, I’ll try to implement your code with my yamaha reciever when I get home.

Thanks petro.

@Romquenin
Hmm…I’ll check and see if I also get the same error tonight in my logs. But at least it’s working for now. I think that error might just be on start-up if it hasn’t yet loaded the media_player component so it’s taking a bit longer waiting for it to load. But let me do some digging. How much longer does start up take? Is it really noticeable? Try disabling the automations temporarily and see if that impacts it.

The boot time is more due to the custom UI i just installed.

I’m waiting for your update.

Thank you Jer78

Ok, I made this alittle less convoluted. You should only need 2 sliders and 4 automations. You won’t need any sensors.

These are your sliders:

  google_home:
    name: Goggle Home Volume
    initial: 40
    min: 0
    max: 100
    step: 1
    
  home_cinema_main:
    name: Cinema Volume
    initial: 40
    min: 0
    max: 100
    step: 1

These are you automations:

- alias: Set Goggle Home Slider Position
  trigger:
    - platform: state
      entity_id: media_player.google_home
  condition:
    - condition: template
      value_template: "{{ not is_state_attr('media_player.google_home', 'volume_level', states('input_number.google_home') | int / 100) }}"
  action:
    - service: input_number.set_value
      entity_id: input_number.google_home
      data_template:
        value: "{{ trigger.to_state.attributes.volume_level | multiply(100) | int }}"

- alias: Set Goggle Home Volume
  trigger:
    - platform: state
      entity_id: input_number.google_home
  condition:
    - condition: template
      value_template: "{{ not is_state_attr('media_player.google_home', 'volume_level', states('input_number.google_home') | int / 100) }}"
  action:
    - service: media_player.volume_set
      entity_id: media_player.google_home
      data_template:
        volume_level: "{{ states('input_number.google_home') | int / 100 }}"

- alias: Set Home Cinema Main Slider Position
  trigger:
    - platform: state
      entity_id: media_player.home_cinema_main
  condition:
    - condition: template
      value_template: "{{ not is_state_attr('media_player.home_cinema_main', 'volume_level', states('input_number.home_cinema_main') | int / 100) }}"
  action:
    - service: input_number.set_value
      entity_id: input_number.home_cinema_main
      data_template:
        value: "{{ trigger.to_state.attributes.volume_level | multiply(100) | int }}"

- alias: Set Home Cinema Main Volume
  trigger:
    - platform: state
      entity_id: input_number.home_cinema_main
  condition:
    - condition: template
      value_template: "{{ not is_state_attr('media_player.home_cinema_main', 'volume_level', states('input_number.home_cinema_main') | int / 100) }}"
  action:
    - service: media_player.volume_set
      entity_id: media_player.home_cinema_main
      data_template:
        volume_level: "{{ states('input_number.home_cinema_main') | int / 100 }}"

This should be easier to read and has less listeners. You can keep your sensors if you want, but they aren’t needed at this point.

Also, your sliders should react immediately instead of having a 2 second delay.

1 Like

check my last message, I accidentally replied to myself.

hello, i just pasted your code and it breaks the sliders, i still have some errors also

I willl revert back to the previous config.

Thanks anyway.

2018-01-20 00:33:42 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
2018-01-20 00:33:43 WARNING (MainThread) [homeassistant.setup] Setup of media_player is taking over 10 seconds.
2018-01-20 00:33:43 WARNING (MainThread) [homeassistant.setup] Setup of remote is taking over 10 seconds.
2018-01-20 00:33:43 WARNING (MainThread) [homeassistant.setup] Setup of device_tracker is taking over 10 seconds.
2018-01-20 00:33:43 WARNING (MainThread) [homeassistant.setup] Setup of switch is taking over 10 seconds.
2018-01-20 00:33:47 WARNING (MainThread) [homeassistant.setup] Setup of tts is taking over 10 seconds.
2018-01-20 00:34:02 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
2018-01-20 00:34:11 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 182, in _step
    result = coro.throw(exc)
  File "/usr/src/app/homeassistant/setup.py", line 60, in async_setup_component
    return (yield from task)
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 327, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 243, in result
    raise self._exception
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/src/app/homeassistant/setup.py", line 144, in _async_setup_component
    component = loader.get_component(domain)
  File "/usr/src/app/homeassistant/loader.py", line 142, in get_component
    module = importlib.import_module(path)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 674, in exec_module
  File "<frozen importlib._bootstrap_external>", line 781, in get_code
  File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/customizer/__init__.py", line 7
    <!DOCTYPE html>
    ^
SyntaxError: invalid syntax

did you rename your sliders? The sliders in the pasted code go with the sliders I created in my last post. They do not work with your sliders with _volume at the end

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) }}