I wonder if you can solve this one as your solution does not work for my entity.
I have a binary_sensor.curtain_not_needed which is a trend sensor on sensor.bedroom_window_temp.
It is one of several triggers in an automation and I want to know which entity_id triggered.
I have these facts: (I am using persistent_notification message to retrieve)
trigger.entity_id: binary_sensor.curtain_not_needed
trigger.to_state: <state binary_sensor.curtain_not_needed=on; entity_id=sensor.bedroom_window_temp, friendly_name=curtain_not_needed, gradient=-0.003124310251228358, invert=False, min_gradient=-0.0033, sample_count=1, sample_duration=120, device_class=cold @ 2020-05-11T18:31:08.223690+10:00>
trigger.to_state.state: on ;
However adding {{ state_attr(trigger.event.data.entity_id, ‘friendly_name’) }}
results in a log entry of:
Developer Tools
test curtain: Error executing script. Unexpected error for call_service at pos 1: Error rendering data template: UndefinedError: 'dict object' has no attribute 'state'
6:27:28 PM – Automation (ERROR) - message first occurred at 6:07:35 PM and shows up 6 times
Updating rest sensor took longer than the scheduled update interval 0:00:01
6:27:06 PM – Sensor (WARNING) - message first occurred at 6:04:05 PM and shows up 6 times
Updating device list from legacy took longer than the scheduled scan interval 0:00:12
6:27:06 PM – Device tracker (WARNING) - message first occurred at 6:03:36 PM and shows up 24 times
Config entry for upnp not ready yet. Retrying in 80 seconds.
6:26:24 PM – config_entries.py (WARNING) - message first occurred at 6:03:39 PM and shows up 16 times
Wanted UPnP/IGD device with UDN "uuid:0065b8f9-9ecd-4c26-8008-94a1115c0e20" not found, aborting
6:26:24 PM – UPnP (WARNING) - message first occurred at 6:03:39 PM and shows up 16 times
Error during template condition: UndefinedError: 'binary_sensor' is undefined
6:21:39 PM – helpers/condition.py (ERROR) - message first occurred at 6:06:39 PM and shows up 4 times
Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for willyweather doing I/O at custom_components/willyweather/weather.py, line 209: result = requests.get(self._build_url(), timeout=10).json()
6:09:08 PM – util/async_.py (WARNING)
Error doing job: Exception in callback async_track_state_change.<locals>.state_change_listener(<Event state_...124731+10:00>>) at /usr/src/homeassistant/homeassistant/helpers/event.py:81
6:08:29 PM – helpers/template.py (ERROR)
Log Details (ERROR)
Logger: homeassistant.components.automation
Source: helpers/service.py:135
Integration: Automation (documentation, issues)
First occurred: 6:07:35 PM (6 occurrences)
Last logged: 6:27:28 PM
test curtain: Error executing script. Unexpected error for call_service at pos 1: Error rendering data template: UndefinedError: 'dict object' has no attribute 'state'
test curtain: Error executing script. Unexpected error for call_service at pos 1: Error rendering data template: UndefinedError: 'dict object' has no attribute 'event'
test curtain: Error executing script. Unexpected error for call_service at pos 1: Error rendering data template: UndefinedError: 'homeassistant.core.State object' has no attribute 'event'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 222, in async_render
return compiled.render(kwargs).strip()
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
File "/usr/local/lib/python3.7/site-packages/jinja2/sandbox.py", line 407, in getattr
value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'state'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 132, in async_prepare_call_from_config
template.render_complex(config[CONF_SERVICE_DATA_TEMPLATE], variables)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 71, in render_complex
return {key: render_complex(item, variables) for key, item in value.items()}
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 71, in <dictcomp>
return {key: render_complex(item, variables) for key, item in value.items()}
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 73, in render_complex
return value.async_render(variables)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 224, in async_render
raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'dict object' has no attribute 'state'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 153, in _async_step
self, f"_async_{cv.determine_script_action(self._action)}_step"
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 623, in _async_call_service_step
*self._prep_call_service_step(), blocking=True, context=self._context
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 252, in _prep_call_service_step
return async_prepare_call_from_config(self._hass, self._action, self._variables)
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 135, in async_prepare_call_from_config
raise HomeAssistantError(f"Error rendering data template: {ex}") from ex
homeassistant.exceptions.HomeAssistantError: Error rendering data template: UndefinedError: 'dict object' has no attribute 'state'