Input Number/Volume Slider for Yamaha Receiver & Google home

Ok

Making sure that the configuration has set_value in the right place, restart HA.

Then click on the little i symbol in the panel to go to the log. Click clear so it’s empty if it isn’t already.

Go to the page with your sliders on, note the time, and drag both sliders to about 75%

Go back to the logs, press refresh. Are there any errors?

If so, click on them to get the full messages and post them here.

If not, go to the logbook and look for the time you dragged the sliders. Does it show the automation being triggered?

Thanks i will do that.

Here are the errors

Error doing job: Task exception was never retrieved
‎02‎:‎13 helpers/template.py (ERROR)
Error doing job: Task exception was never retrieved
‎02‎:‎13 helpers/template.py (ERROR)
Error doing job: Task exception was never retrieved
‎02‎:‎13 helpers/template.py (ERROR)
Error doing job: Task exception was never retrieved

Maybe more relevant like this:

2018-01-19 02:09:38 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
2018-01-19 02:09:38 WARNING (MainThread) [homeassistant.setup] Setup of media_player is taking over 10 seconds.
2018-01-19 02:09:38 WARNING (MainThread) [homeassistant.setup] Setup of switch is taking over 10 seconds.
2018-01-19 02:09:38 WARNING (MainThread) [homeassistant.setup] Setup of remote is taking over 10 seconds.
2018-01-19 02:09:38 WARNING (MainThread) [homeassistant.setup] Setup of device_tracker is taking over 10 seconds.
2018-01-19 02:09:40 WARNING (MainThread) [homeassistant.setup] Setup of tts is taking over 10 seconds.
2018-01-19 02:09:56 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
2018-01-19 02:10:18 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting
2018-01-19 02:13:07 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/template.py", line 118, in async_render
    return self._compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.6/site-packages/jinja2/filters.py", line 668, in do_float
    return float(value)
jinja2.exceptions.UndefinedError: 'None' has no attribute 'state'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 343, in async_trigger
    yield from self._async_action(self.entity_id, variables)
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 433, in action
    yield from script_obj.async_run(variables)
  File "/usr/src/app/homeassistant/helpers/script.py", line 151, in async_run
    yield from self._async_call_service(action, variables)
  File "/usr/src/app/homeassistant/helpers/script.py", line 181, in _async_call_service
    self.hass, action, True, variables, validate_config=False)
  File "/usr/src/app/homeassistant/helpers/service.py", line 76, in async_call_from_config
    config[CONF_SERVICE_DATA_TEMPLATE]))
  File "/usr/src/app/homeassistant/helpers/service.py", line 72, in _data_template_creator
    for key, item in value.items()}
  File "/usr/src/app/homeassistant/helpers/service.py", line 72, in <dictcomp>
    for key, item in value.items()}
  File "/usr/src/app/homeassistant/helpers/service.py", line 74, in _data_template_creator
    return value.async_render(variables)
  File "/usr/src/app/homeassistant/helpers/template.py", line 120, in async_render
    raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'state'
2018-01-19 02:13:10 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/template.py", line 118, in async_render
    return self._compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.6/site-packages/jinja2/filters.py", line 668, in do_float
    return float(value)
jinja2.exceptions.UndefinedError: 'None' has no attribute 'state'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 343, in async_trigger
    yield from self._async_action(self.entity_id, variables)
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 433, in action
    yield from script_obj.async_run(variables)
  File "/usr/src/app/homeassistant/helpers/script.py", line 151, in async_run
    yield from self._async_call_service(action, variables)
  File "/usr/src/app/homeassistant/helpers/script.py", line 181, in _async_call_service
    self.hass, action, True, variables, validate_config=False)
  File "/usr/src/app/homeassistant/helpers/service.py", line 76, in async_call_from_config
    config[CONF_SERVICE_DATA_TEMPLATE]))
  File "/usr/src/app/homeassistant/helpers/service.py", line 72, in _data_template_creator
    for key, item in value.items()}
  File "/usr/src/app/homeassistant/helpers/service.py", line 72, in <dictcomp>
    for key, item in value.items()}
  File "/usr/src/app/homeassistant/helpers/service.py", line 74, in _data_template_creator
    return value.async_render(variables)
  File "/usr/src/app/homeassistant/helpers/template.py", line 120, in async_render
    raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'state'
2018-01-19 02:13:13 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/template.py", line 118, in async_render
    return self._compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.6/site-packages/jinja2/filters.py", line 668, in do_float
    return float(value)
jinja2.exceptions.UndefinedError: 'None' has no attribute 'state'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 343, in async_trigger
    yield from self._async_action(self.entity_id, variables)
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 433, in action
    yield from script_obj.async_run(variables)
  File "/usr/src/app/homeassistant/helpers/script.py", line 151, in async_run
    yield from self._async_call_service(action, variables)
  File "/usr/src/app/homeassistant/helpers/script.py", line 181, in _async_call_service
    self.hass, action, True, variables, validate_config=False)
  File "/usr/src/app/homeassistant/helpers/service.py", line 76, in async_call_from_config
    config[CONF_SERVICE_DATA_TEMPLATE]))
  File "/usr/src/app/homeassistant/helpers/service.py", line 72, in _data_template_creator
    for key, item in value.items()}
  File "/usr/src/app/homeassistant/helpers/service.py", line 72, in <dictcomp>
    for key, item in value.items()}
  File "/usr/src/app/homeassistant/helpers/service.py", line 74, in _data_template_creator
    return value.async_render(variables)
  File "/usr/src/app/homeassistant/helpers/template.py", line 120, in async_render
    raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'state'
2018-01-19 02:13:16 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/template.py", line 118, in async_render
    return self._compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.6/site-packages/jinja2/filters.py", line 668, in do_float
    return float(value)
jinja2.exceptions.UndefinedError: 'None' has no attribute 'state'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 343, in async_trigger
    yield from self._async_action(self.entity_id, variables)
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 433, in action
    yield from script_obj.async_run(variables)
  File "/usr/src/app/homeassistant/helpers/script.py", line 151, in async_run
    yield from self._async_call_service(action, variables)
  File "/usr/src/app/homeassistant/helpers/script.py", line 181, in _async_call_service
    self.hass, action, True, variables, validate_config=False)
  File "/usr/src/app/homeassistant/helpers/service.py", line 76, in async_call_from_config
    config[CONF_SERVICE_DATA_TEMPLATE]))
  File "/usr/src/app/homeassistant/helpers/service.py", line 72, in _data_template_creator
    for key, item in value.items()}
  File "/usr/src/app/homeassistant/helpers/service.py", line 72, in <dictcomp>
    for key, item in value.items()}
  File "/usr/src/app/homeassistant/helpers/service.py", line 74, in _data_template_creator
    return value.async_render(variables)
  File "/usr/src/app/homeassistant/helpers/template.py", line 120, in async_render
    raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'state'
2018-01-19 02:13:49 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/template.py", line 118, in async_render
    return self._compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.6/site-packages/jinja2/filters.py", line 668, in do_float
    return float(value)
jinja2.exceptions.UndefinedError: 'None' has no attribute 'state'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 343, in async_trigger
    yield from self._async_action(self.entity_id, variables)
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 433, in action
    yield from script_obj.async_run(variables)
  File "/usr/src/app/homeassistant/helpers/script.py", line 151, in async_run
    yield from self._async_call_service(action, variables)
  File "/usr/src/app/homeassistant/helpers/script.py", line 181, in _async_call_service
    self.hass, action, True, variables, validate_config=False)
  File "/usr/src/app/homeassistant/helpers/service.py", line 76, in async_call_from_config
    config[CONF_SERVICE_DATA_TEMPLATE]))
  File "/usr/src/app/homeassistant/helpers/service.py", line 72, in _data_template_creator
    for key, item in value.items()}
  File "/usr/src/app/homeassistant/helpers/service.py", line 72, in <dictcomp>
    for key, item in value.items()}
  File "/usr/src/app/homeassistant/helpers/service.py", line 74, in _data_template_creator
    return value.async_render(variables)
  File "/usr/src/app/homeassistant/helpers/template.py", line 120, in async_render
    raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'state'

Here is my automations.yaml edited with your value:

 - alias: google home - Adjust Volume
   trigger:
     - platform: state
       entity_id: input_number.slider1
   action:
     - service: media_player.volume_set
       data_template:
         entity_id: media_player.google_home
         volume_level: '{{ states.input_number.google_home.state | float / 80 }}'
         
 - alias: yamaha - Adjust Volume
   trigger:
     - platform: state
       entity_id: input_number.slider2
   action:
     - service: media_player.volume_set
       data_template:
         entity_id: media_player.home_cinema_main
         volume_level: '{{ states.input_number.home_cinema_main.state | float / 80 }}'

 - alias: google home - Volume
   trigger:
     - platform: state
       entity_id: media_player.google_home
   action:
     - service: input_number.set_value
       data_template:
         entity_id: input_number.slider1
         value: '{{ states.media_player.google_home.attributes.volume_level | float * 80 }}'
         
 - alias: yamaha - Volume
   trigger:
     - platform: state
       entity_id: media_player.home_cinema_main
   action:
     - service: input_number.set_value
       data_template:
         entity_id: input_number.slider2
         value: '{{ states.media_player.home_cinema_main.attributes.volume_level | float * 80 }}'

Are the devices on?

Yes they are

Those look like startup errors. I had to build in an if statement into the volume_level that would cause it to only populate when the media player is on. Here is an example, do not copy the code because it won’t work in your situation. You can use the general concept though.

  zone1_volume:
    value_template: >
      {% if is_state('media_player.yamaha_receiver', 'on')  %}
        {% set n = states.media_player.yamaha_receiver.attributes.volume_level | float %}
        {{ '%.1f'%( (-1.0+n)*100.0 | round(1) ) }}
      {% else %}
        "-80.0"
      {% endif %}
    unit_of_measurement: "DB"

And just to clarify, those errors only happen at startup even if the device is on. From what I remember, these none-type errors would always occur at startup because the device would be considered off momentarily (Even if the hardware was on).

This could be a different issue all together, hopefully this will help.

1 Like

Here’s how I did this with Sonos to sync the volumes. May be of some help…

Hello, here is my updated config files

Automations:

 - alias: 'Set Input Number From Volume'
   initial_state: on
   trigger:
     - platform: state
       entity_id: sensor.google_home_volume_changed
       to: 'true'
       for:
         seconds: 2
     - platform: state
       entity_id: sensor.yamaha_volume_changed
       to: 'true'
       for:
         seconds: 2
     - platform: homeassistant
       event: start
   action:
     - service: input_number.set_value
       data_template:
         entity_id: >-
           {% set room = trigger.entity_id.split(".")[1] | replace("_changed", "") %}
           {% set entity = ["input_number",room]|join(".") %}
           {{entity}}
         value: >-
           {% set room = trigger.entity_id.split(".")[1] | replace("_volume_changed", "") %}
           {% if room == "goole_home" %}
             {{states.sensor.google_home_volume.state }}
           {% elif room == "yamaha" %}
             {{states.sensor.yamaha_volume.state }}
           {% endif %}

 - alias: 'Set Volume From Input Number'
   initial_state: on
   trigger:
     - platform: state
       entity_id: input_number.slider1
     - platform: state
       entity_id: input_number.slider2
   condition:
     condition: and
     conditions:
       - condition: template
         value_template: >-
           {% set room = trigger.entity_id.split(".")[1] %}
           {% set input_num = ["states.input_number",room,"state"]|join(".") %}
           {% set vol = ["states.sensor",room,"state"]|join(".") %}
           {% if input_num != vol %}true
           {%else%}false
           {% endif %}
   action:
     - service: media_player.volume_set
       data_template:
         entity_id: >-
           {% set room = trigger.entity_id.split(".")[1]|replace("_volume","")%}
           {% set entity = ["media_player",room]|join(".")%}
           {{entity}}
         volume_level: >-
           {% set room = trigger.entity_id.split(".")[1]|replace("_volume","")%}
           {% if room == "google_home" %}
             {{states.input_number.slider1.state | int / 100 | float}}
           {% elif room == "yamaha" %}
             {{states.input_number.slider2.state | int / 100 | float}}
           {% endif %}

Configuration:

input_number:
  slider1:
    name: Google Home
    initial: 30
    min: 0
    max: 60
    step: 1
  slider2:
    name: Yamaha
    initial: 30
    min: 0
    max: 60
    step: 1

I included the sensors like this:

sensor:
  - platform: template
    sensors:  
      google_home_volume:
        value_template: >-
           {% set volume = states.media_player.google_home.attributes.volume_level %}
           {% set new_volume = volume * 100 %}
           {{ new_volume}}
      google_home_volume_changed:
        value_template: '{% if (states.input_number.slider1.state | int) != (states.sensor.google_home_volume.state | int ) %}true{%else%}false{% endif %}'
      yamaha_volume:
        value_template: >-
           {% set volume = states.media_player.home_cinema_main.attributes.volume_level %}
           {% set new_volume = volume * 100 %}
           {{ new_volume}}
      yamaha_volume_changed:
        value_template: '{% if (states.input_number.slider2.state | int) != (states.sensor.yamaha_volume.state | int ) %}true{%else%}false{% endif %}'

But unfortunatly it doesn’t work.
Now im’ getting this results in the log:

2018-01-19 13:36:15 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
2018-01-19 13:36:16 WARNING (MainThread) [homeassistant.setup] Setup of media_player is taking over 10 seconds.
2018-01-19 13:36:16 WARNING (MainThread) [homeassistant.setup] Setup of switch is taking over 10 seconds.
2018-01-19 13:36:16 WARNING (MainThread) [homeassistant.setup] Setup of device_tracker is taking over 10 seconds.
2018-01-19 13:36:16 WARNING (MainThread) [homeassistant.setup] Setup of remote is taking over 10 seconds.
2018-01-19 13:36:25 WARNING (MainThread) [homeassistant.setup] Setup of tts is taking over 10 seconds.
2018-01-19 13:36:32 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform yr is taking over 10 seconds.
2018-01-19 13:36:33 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
2018-01-19 13:36:42 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/template.py", line 118, in async_render
    return self._compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.6/site-packages/jinja2/sandbox.py", line 385, in getattr
    value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'entity_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 343, in async_trigger
    yield from self._async_action(self.entity_id, variables)
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 433, in action
    yield from script_obj.async_run(variables)
  File "/usr/src/app/homeassistant/helpers/script.py", line 151, in async_run
    yield from self._async_call_service(action, variables)
  File "/usr/src/app/homeassistant/helpers/script.py", line 181, in _async_call_service
    self.hass, action, True, variables, validate_config=False)
  File "/usr/src/app/homeassistant/helpers/service.py", line 76, in async_call_from_config
    config[CONF_SERVICE_DATA_TEMPLATE]))
  File "/usr/src/app/homeassistant/helpers/service.py", line 72, in _data_template_creator
    for key, item in value.items()}
  File "/usr/src/app/homeassistant/helpers/service.py", line 72, in <dictcomp>
    for key, item in value.items()}
  File "/usr/src/app/homeassistant/helpers/service.py", line 74, in _data_template_creator
    return value.async_render(variables)
  File "/usr/src/app/homeassistant/helpers/template.py", line 120, in async_render
    raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'dict object' has no attribute 'entity_id'

It’s so complicate

Thanks for your help

1 Like

I don’t think this startup process has ‘enitity_id’ in it’s trigger. So your code:

       {% set room = trigger.entity_id.split(".")[1] %}
       {% set input_num = ["states.input_number",room,"state"]|join(".") %}

Won’t work in that instance. You should remove that trigger or have an if statement in your template that looks for entity_id.

An example of this:

       {% if 'entity_id' in trigger.keys() %}
         {% if room == "goole_home" in trigger.entity_id %}
           {{states.sensor.google_home_volume.state }}
         {% elif room == "yamaha" in trigger.entity_id %}
           { {states.sensor.yamaha_volume.state }}
         {% else %}
           0
         {% endif %}
       {% else %}
         0
       {% endif %}

Hello Petro,
By removing the trigger you mean this one:

 - platform: homeassistant
   event: start

Thanks

Yes, but you can keep it if you search for entity_id in the event trigger keys by using

{% if "entity_id" in trigger.keys() %}

I keep it and have this code:

  - alias: 'Set Input Number From Volume'
    initial_state: on
    trigger:
      - platform: state
        entity_id: sensor.google_home_volume_changed
        to: 'true'
        for:
          seconds: 2
      - platform: state
        entity_id: sensor.yamaha_volume_changed
        to: 'true'
        for:
          seconds: 2
      - platform: homeassistant
        event: start
          {% if 'entity_id' in trigger.keys() %}
           {% if room == "goole_home" in trigger.entity_id %}
             {{states.sensor.google_home_volume.state }}
           {% elif room == "yamaha" in trigger.entity_id %}
             { {states.sensor.yamaha_volume.state }}
           {% else %}
             0
           {% endif %}
         {% else %}
           0
         {% endif %}          
    action:
      - service: input_number.set_value
        data_template:
          entity_id: >-
            {% set room = trigger.entity_id.split(".")[1] | replace("_changed", "") %}
            {% set entity = ["input_number",room]|join(".") %}
            {{entity}}
          value: >-
            {% set room = trigger.entity_id.split(".")[1] | replace("_volume_changed", "") %}
            {% if room == "goole_home" %}
              {{states.sensor.google_home_volume.state }}
            {% elif room == "yamaha" %}
              {{states.sensor.yamaha_volume.state }}
            {% endif %}

  - alias: 'Set Volume From Input Number'
    initial_state: on
    trigger:
      - platform: state
        entity_id: input_number.slider1
      - platform: state
        entity_id: input_number.slider2
    condition:
      condition: and
      conditions:
        - condition: template
          value_template: >-
            {% set room = trigger.entity_id.split(".")[1] %}
            {% set input_num = ["states.input_number",room,"state"]|join(".") %}
            {% set vol = ["states.sensor",room,"state"]|join(".") %}
            {% if input_num != vol %}true
            {%else%}false
            {% endif %}
    action:
      - service: media_player.volume_set
        data_template:
          entity_id: >-
            {% set room = trigger.entity_id.split(".")[1]|replace("_volume","")%}
            {% set entity = ["media_player",room]|join(".")%}
            {{entity}}
          volume_level: >-
            {% set room = trigger.entity_id.split(".")[1]|replace("_volume","")%}
            {% if room == "google_home" %}
              {{states.input_number.slider1.state | int / 100 | float}}
            {% elif room == "yamaha" %}
              {{states.input_number.slider2.state | int / 100 | float}}
            {% endif %}

Thanks for your help, i’m really confused. Should i try this code?

no, the jinja goes in the data_template inside your action:

action:
  - service: input_number.set_value
    data_template:
      entity_id: >-
        {% set room = trigger.entity_id.split(".")[1] | replace("_changed", "") %}
        {% set entity = ["input_number",room]|join(".") %}
        {{entity}}
      value: >-
        {% set room = trigger.entity_id.split(".")[1] | replace("_volume_changed", "") %}
        {% if room == "goole_home" %}
          {{states.sensor.google_home_volume.state }}
        {% elif room == "yamaha" %}
          {{states.sensor.yamaha_volume.state }}
        {% endif %}

Your trigger remains untouched from your original code.

Thanks for your help petro, i have now this error in the log:

2018-01-19 14:20:39 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: Entity ID {% set room = trigger.entity_id.split(".")[1] | replace("_changed" is an invalid entity id for dictionary value @ data['action'][0]['entity_id']. Got None
expected a dictionary for dictionary value @ data['action'][0]['data_template']. Got None
extra keys not allowed @ data['action'][0]['value']. Got None. (See /config/configuration.yaml, line 204). Please check the docs at https://home-assistant.io/components/automation/
2018-01-19 14:20:50 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
2018-01-19 14:20:50 WARNING (MainThread) [homeassistant.setup] Setup of media_player is taking over 10 seconds.
2018-01-19 14:20:51 WARNING (MainThread) [homeassistant.setup] Setup of remote is taking over 10 seconds.
2018-01-19 14:20:51 WARNING (MainThread) [homeassistant.setup] Setup of switch is taking over 10 seconds.
2018-01-19 14:20:51 WARNING (MainThread) [homeassistant.setup] Setup of device_tracker is taking over 10 seconds.
2018-01-19 14:21:04 WARNING (MainThread) [homeassistant.setup] Setup of tts is taking over 10 seconds.
2018-01-19 14:21:10 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.

Last automation:

 - alias: 'Set Input Number From Volume'
   initial_state: on
   trigger:
     - platform: state
       entity_id: sensor.google_home_volume_changed
       to: 'true'
       for:
         seconds: 2
     - platform: state
       entity_id: sensor.yamaha_volume_changed
       to: 'true'
       for:
         seconds: 2
     - platform: homeassistant
       event: start
   action:
     - service: input_number.set_value
       data_template:
       entity_id: >-
         {% set room = trigger.entity_id.split(".")[1] | replace("_changed", "") %}
         {% set entity = ["input_number",room]|join(".") %}
         {{entity}}
       value: >-
         {% set room = trigger.entity_id.split(".")[1] | replace("_volume_changed", "") %}
         {% if room == "goole_home" %}
           {{states.sensor.google_home_volume.state }}
         {% elif room == "yamaha" %}
           {{states.sensor.yamaha_volume.state }}
         {% endif %}

 - alias: 'Set Volume From Input Number'
   initial_state: on
   trigger:
     - platform: state
       entity_id: input_number.slider1
     - platform: state
       entity_id: input_number.slider2
   condition:
     condition: and
     conditions:
       - condition: template
         value_template: >-
           {% set room = trigger.entity_id.split(".")[1] %}
           {% set input_num = ["states.input_number",room,"state"]|join(".") %}
           {% set vol = ["states.sensor",room,"state"]|join(".") %}
           {% if input_num != vol %}true
           {%else%}false
           {% endif %}
   action:
     - service: media_player.volume_set
       data_template:
         entity_id: >-
           {% set room = trigger.entity_id.split(".")[1]|replace("_volume","")%}
           {% set entity = ["media_player",room]|join(".")%}
           {{entity}}
         volume_level: >-
           {% set room = trigger.entity_id.split(".")[1]|replace("_volume","")%}
           {% if room == "google_home" %}
             {{states.input_number.slider1.state | int / 100 | float}}
           {% elif room == "yamaha" %}
             {{states.input_number.slider2.state | int / 100 | float}}
           {% endif %}

I presume my problem is about entity_id:

Entity ID {% set room = trigger.entity_id.split(".")[1] | replace("_changed" is an invalid entity id for dictionary value @ data['action'][0]['entity_id']. Got Nonevalue @ data['action'][0]['entity_id']. Got None

But i don’t get it.

Thanks

@Romquenin

The problem is your input_number names don’t match. When I have some time later today I’ll write it out for you.

1 Like

Is the problem with input_number related to the “room” word. You are using it a lot in your automation. And it don’t use it in any of my config.

I don’t understand how it works in this case.

Thanks anyway Jer78

@Romquenin OK, here it is, try this out, but read my comments as you may need to make some modifications.

Sensors (the multiplications may be different for your setup. For Sonos it gives a float of e.g. 0.15 so I times it by 100 to get 15. So be careful when you use this to not max out your speakers. See what value in the media_player attributes.)

sensor:
  - platform: template
    sensors:  
      google_home_volume:
        value_template: >-
           {% set volume = states.media_player.google_home.attributes.volume_level %}
           {% set new_volume = volume * 100 %}
           {{ new_volume}}
      google_home_volume_changed:
        value_template: '{% if (states.input_number.google_home_volume.state | int) != (states.sensor.google_home_volume.state | int ) %}true{%else%}false{% endif %}'
      home_cinema_main_volume:
        value_template: >-
           {% set volume = states.media_player.home_cinema_main.attributes.volume_level %}
           {% set new_volume = volume * 100 %}
           {{ new_volume}}
      home_cinema_main_volume_changed:
        value_template: '{% if (states.input_number.home_cinema_main_volume.state | int) != (states.sensor.home_cinema_main_volume.state | int ) %}true{%else%}false{% endif %}'

Input Numbers (these have to be same names as your sensors for the automation to work)

input_number:
  google_home_volume:
    name: Google Home
    min: 0
    max: 60
    step: 1
  home_cinema_main_volume:
    name: Yamaha
    min: 0
    max: 60
    step: 1

Automations (again, the division is based off the values as mentioned above. Since it’s a different media_player you may want to test before setting volumes, I don’t want you to blow anything up!):

 - alias: 'Set Input Number From Volume'
   initial_state: on
   trigger:
     - platform: state
       entity_id: sensor.google_home_volume_changed
       to: 'true'
       for:
         seconds: 2
     - platform: state
       entity_id: sensor.home_cinema_main_volume_changed
       to: 'true'
       for:
         seconds: 2
     - platform: homeassistant
       event: start
   action:
     - service: input_number.set_value
       data_template:
       entity_id: >-
         {% set room = trigger.entity_id.split(".")[1] | replace("_changed", "") %}
         {% set entity = ["input_number",room]|join(".") %}
         {{entity}}
       value: >-
         {% set room = trigger.entity_id.split(".")[1] | replace("_volume_changed", "") %}
         {% if room == "google_home" %}
           {{states.sensor.google_home_volume.state }}
         {% elif room == "home_cinema_main" %}
           {{states.sensor.home_cinema_main_volume.state }}
         {% endif %}

 - alias: 'Set Volume From Input Number'
   initial_state: on
   trigger:
     - platform: state
       entity_id: input_number.google_home_volume
     - platform: state
       entity_id: input_number.home_cinema_main_volume
   condition:
     condition: and
     conditions:
       - condition: template
         value_template: >-
           {% set room = trigger.entity_id.split(".")[1] %}
           {% set input_num = ["states.input_number",room,"state"]|join(".") %}
           {% set vol = ["states.sensor",room,"state"]|join(".") %}
           {% if input_num != vol %}true
           {%else%}false
           {% endif %}
   action:
     - service: media_player.volume_set
       data_template:
         entity_id: >-
           {% set room = trigger.entity_id.split(".")[1]|replace("_volume","")%}
           {% set entity = ["media_player",room]|join(".")%}
           {{entity}}
         volume_level: >-
           {% set room = trigger.entity_id.split(".")[1]|replace("_volume","")%}
           {% if room == "google_home" %}
             {{states.input_number.google_home_volume.state | int / 100 | float}}
           {% elif room == "home_cinema_main" %}
             {{states.input_number.home_cinema_main_volume.state | int / 100 | float}}
           {% endif %}
1 Like

Well my friend thank you very much it works, for google home. The yamaha receiver don’t respond.

The google home respond perfectly, from mute to max and that’s pretty cool!

It will have been impossible without you and i want to thank you very much.

here is my log for the not solved yamaha error.

2018-01-19 18:07:50 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: Entity ID {% set room = trigger.entity_id.split(".")[1] | replace("_changed" is an invalid entity id for dictionary value @ data['action'][0]['entity_id']. Got None
expected a dictionary for dictionary value @ data['action'][0]['data_template']. Got None
extra keys not allowed @ data['action'][0]['value']. Got None. (See /config/configuration.yaml, line 241). Please check the docs at https://home-assistant.io/components/automation/
2018-01-19 18:07:57 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
2018-01-19 18:08:00 WARNING (MainThread) [homeassistant.setup] Setup of media_player is taking over 10 seconds.
2018-01-19 18:08:00 WARNING (MainThread) [homeassistant.setup] Setup of switch is taking over 10 seconds.
2018-01-19 18:08:00 WARNING (MainThread) [homeassistant.setup] Setup of remote is taking over 10 seconds.
2018-01-19 18:08:00 WARNING (MainThread) [homeassistant.setup] Setup of device_tracker is taking over 10 seconds.
2018-01-19 18:08:09 WARNING (MainThread) [homeassistant.setup] Setup of tts is taking over 10 seconds.
2018-01-19 18:08:19 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
2018-01-19 18:08:28 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
2018-01-19 18:48:07 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template yamaha_volume: UndefinedError: 'mappingproxy object' has no attribute 'volume_level'
2018-01-19 18:48:23 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

I keep reading the code and it’s exactly the same for both devices. Why is the receiver not receiving command?

Thanks again, you are amazing.

1 Like

@Romquenin
Sorry, I missed something important. Your media_player has the name home_cinema_main not Yamaha, so we need to make all the sensors and input_numbers the same name. Don’t worry, your friendly name as shown on the frontend can still be Yamaha. I updated the post above to reflect those changes so now it should work as intended. Also, I took out the initial values in the input_number’s because it’s going to get the initial value of the actual value on start or change so you don’t need those, they will just mess with things.

Go ahead and try it now. I think I got everything this time around! Crossing my fingers. :sweat_smile:

1 Like

Jer78 you are the king of the Yaml!!!

It works!!!:joy::joy::joy:

Like you said i will have to manage the max volume output but man you are awsome, you solved my problem.

I will dig into into it and try understand the full process, but you rock it.

Thank you so much for your time and generosity

1 Like

Now that i have my sliders working fine i still receive errors in the log, i have a card with a problem with automation on startup and my startup takes longer:

2018-01-19 19:45:44 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: Entity ID {% set room = trigger.entity_id.split(".")[1] | replace("_changed" is an invalid entity id for dictionary value @ data['action'][0]['entity_id']. Got None
expected a dictionary for dictionary value @ data['action'][0]['data_template']. Got None
extra keys not allowed @ data['action'][0]['value']. Got None. (See /config/configuration.yaml, line 241). Please check the docs at https://home-assistant.io/components/automation/
2018-01-19 19:45:53 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
2018-01-19 19:45:55 WARNING (MainThread) [homeassistant.setup] Setup of media_player is taking over 10 seconds.
2018-01-19 19:45:55 WARNING (MainThread) [homeassistant.setup] Setup of switch is taking over 10 seconds.
2018-01-19 19:45:55 WARNING (MainThread) [homeassistant.setup] Setup of device_tracker is taking over 10 seconds.
2018-01-19 19:45:55 WARNING (MainThread) [homeassistant.setup] Setup of remote is taking over 10 seconds.
2018-01-19 19:46:09 WARNING (MainThread) [homeassistant.setup] Setup of tts is taking over 10 seconds.
2018-01-19 19:46:13 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
2018-01-19 19:46:22 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>
    ^

Do you have any idea?

Thanks again.