I did exactly that. Tried your example, got this in log TypeError: unsupported operand type(s) for -: 'str' and 'int'
and unsupported operand type(s) for -: 'NoneType' and 'NoneType'
Here is the script
alias: Testing the timer
sequence:
- service: timer.start
data_template:
entity_id: timer.leave
duration:
minutes: "{{ (state_attr('input_datetime.leave_home', 'timestamp') -
state_attr('input_datetime.alarm_morning', 'timestamp')) / 60 }}"
And here is full issue from logs
2019-09-23 17:47:38 ERROR (MainThread) [homeassistant.components.script] Error executing script script.15217201925112. Unknown error for call_service at pos 1:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 209, in async_turn_on
await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 162, in async_run
await self._handle_action(action, variables, context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 246, in _handle_action
await self._actions[_determine_action(action)](action, variables, context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 329, in _async_call_service
context=context,
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 88, in async_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 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 72, in render_complex
return value.async_render(variables)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 215, in async_render
return compiled.render(kwargs).strip()
File "/usr/local/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'
2019-09-23 17:47:38 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall script.15217201925112 (c:16719b2a54894ab7ba1e5545a7b2ea14)>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/core.py", line 1242, in _safe_execute
await self._execute_service(handler, service_call)
File "/usr/src/homeassistant/homeassistant/core.py", line 1259, in _execute_service
await handler.func(service_call)
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 142, in service_handler
await script.async_turn_on(variables=service.data, context=service.context)
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 214, in async_turn_on
raise err
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 209, in async_turn_on
await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 162, in async_run
await self._handle_action(action, variables, context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 246, in _handle_action
await self._actions[_determine_action(action)](action, variables, context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 329, in _async_call_service
context=context,
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 88, in async_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 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 72, in render_complex
return value.async_render(variables)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 215, in async_render
return compiled.render(kwargs).strip()
File "/usr/local/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'