Sync value from one device to another - Trigger is undefined

What I am currently trying to achieve is to synchronize two device values. The triggering seems to already work, but the problem is that the action cannot get the value from the other device. My automation looks like the following:

automation 3:
  alias: 'Anzeige mit Radiator synchronisieren'
    platform: numeric_state
    entity_id: climate.neq1334623
    value_template: '{{ state.attributes.temperature }}'
    below: 50
    service: climate.set_temperature
      entity_id: climate.neq0611872
      operation_mode: manual
      temperature: '{{ trigger.to_state.attributes.temperature | float }}'

I already tried a lot of different options for “{{ trigger.to_state.attributes.temperature | float }}” but none seemed to really work. In this case I get the following error when trying to trigger the action:

17-03-20 07:07:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: name=Anzeige mit Radiator synchronisieren, message=has been triggered, domain=automation, entity_id=automation.anzeige_mit_radiator_synchronisieren>
17-03-20 07:07:53 INFO (MainThread) [homeassistant.helpers.script] Script Anzeige mit Radiator synchronisieren: Running script
17-03-20 07:07:53 INFO (MainThread) [homeassistant.helpers.script] Script Anzeige mit Radiator synchronisieren: Executing step call service
17-03-20 07:07:53 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/", line 99, in async_render
    return self._compiled.render(kwargs).strip()
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/", line 385, in getattr
    value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'trigger' is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/", line 237, in _step
    result = next(coro)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/automation/", line 305, in async_trigger
    yield from self._async_action(self.entity_id, variables)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/automation/", line 386, in action
    yield from script_obj.async_run(variables)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/", line 151, in async_run
    yield from self._async_call_service(action, variables)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/", line 181, in _async_call_service
    self.hass, action, True, variables, validate_config=False)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/", line 88, in async_call_from_config
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/", line 84, in _data_template_creator
    for key, item in value.items()}
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/", line 84, in <dictcomp>
    for key, item in value.items()}
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/", line 86, in _data_template_creator
    return value.async_render(variables)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/", line 101, in async_render
    raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'trigger' is undefined
17-03-20 07:07:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=140111392429448-77>

So question is: What is the correct way to get the temperature attribute from my “climate.neq0611872” inside an action.

Seems to be working if I use the following action block:

    service: climate.set_temperature
      temperature: '{{ states.climate.neq1334623.attributes.temperature | float }}'
      entity_id: climate.neq0611872
      operation_mode: manual

Still not so sure why I cannot use “trigger” in the data_template.

1 Like

Thanks for your post, it has just given me the solution to another problem :slight_smile: