Input Number/Volume Slider for Yamaha Receiver & Google home

Hello everyone,

First i want to thanks the community for this amazing platform!

I would love to be able to use a volume slider for my receiver and my smart speaker.
I’m sorry to post a topic for this, because the question have been already asked a lot. But unfortunately it doesn’t work.

Here is my config automation.yaml:

 - 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.select_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.select_value
       data_template:
         entity_id: input_number.slider2
         value: '{{ states.media_player.home_cinema_main.attributes.volume_level | float * 80 }}'

And there is my input_number:

input_number:
  slider1:
    name: Google Home
    initial: 40
    min: 0
    max: 100
    step: 10
  slider2:
    name: Yamaha
    initial: 40
    min: 0
    max: 100
    step: 10

I don’t get it because i duplicated the config from users automations.yaml and for them it works.
Any help will be awsome.

Thanks

I think you have to use conditions on automation:
https://home-assistant.io/docs/scripts/conditions/

Just example:
condition:
condition: or
conditions:

  • condition: and
    conditions:
  • condition: state
    entity_id: input_number.slider1
    state: ‘on’

Shouldn’t it be set_value not select_value?

Input numbers are never on, and you don’t need to have conditions unless you want the automation to only trigger under certain circumstances.

Thank you for your replies.

I don’t use the select_value, where do you see it?

Well i don’t understand your advice,

In the action for the third and fourth automation you are calling service input_number.select_value

It should be input_number.set_value

My bad, excuse me i feel dumb.

I chnaged the value and still nothing. It’s frustating.

Thnaks

Is any of it working?

Do you get any errors in the logs when you drag the slider?

Does the automation show as triggered in the logbook when you drag the slider?

I do have my sliders on the UI. They are both displaying the different volume value i set in the input_number:

input_number:
  slider1:
    name: Google Home
    initial: 40
    min: 0
    max: 100
    step: 10
  slider2:
    name: Yamaha
    initial: 40
    min: 0
    max: 100
    step: 10

For the rest once both sliders muted the devices and once it put volume max.

I don’t get to find those values again.

It’s paynfull

thanks

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?