Hi, Im trying to follow your code, cos I would like to do the same, but I’m experiencing no result at all, probably cos there are errors in the log…let me share if you don’t mind, this is the code for the simple automation:
- id: '1594636020436'
alias: Cambio Horas depuración
description: ''
trigger:
- entity_id: input_datetime.tiempo_depuracion
platform: state
condition: []
action:
entity_id: timer.swiming_pool
service: timer.start
data_template:
duration: "{{states(input_datetime.tiempo_depuracion)}}"
When I execute it or change the hours in the UI the automation is executed, but nothing happens (the timer does not change). And I saw this error in the logs:
jinja2.exceptions.UndefinedError: 'input_datetime' is undefined
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 72, in render_complex
return {key: render_complex(item, variables) for key, item in value.items()}
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 72, in <dictcomp>
return {key: render_complex(item, variables) for key, item in value.items()}
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 74, in render_complex
return value.async_render(variables)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 230, in async_render
raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'input_datetime' is undefined
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 656, 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: 'input_datetime' is undefined
Any idea how to resolve it?