Paste this in the template tool and lets see what you have:
{{ as_timestamp(states('input_datetime.run_timed_test')) }}
{{ as_timestamp(states('input_datetime.run_timed_test')) > now().timestamp() }}
Paste this in the template tool and lets see what you have:
{{ as_timestamp(states('input_datetime.run_timed_test')) }}
{{ as_timestamp(states('input_datetime.run_timed_test')) > now().timestamp() }}
Thanks here is the error:
TypeError: '>' not supported between instances of 'NoneType' and 'float'
Does input_datetime.automation.run_timed_test
contain the date and time or just the time?
I believe it only contains the time because this will return none
if there’s no date.
as_timestamp(states('input_datetime.run_timed_test'))
So if you compare none
to a float
it will produce the error message you received:
TypeError: ‘>’ not supported between instances of ‘NoneType’ and ‘float’
Try this:
trigger:
- platform: template
value_template: "{{ now() >= today_at(states('input_datetime.run_timed_test')) }}"
Sorry the scheduled task does not run. I am posting again both configurations.
Scheduler:
alias: schedule_timed_test
description: ''
trigger: []
condition: []
action:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.run_timed_test
data:
timestamp: '{{ now().timestamp() + 60 }}'
mode: single
Activity to be scheduled and ran 60 seconds after scheduler:
alias: run_timed_test
description: ''
trigger:
- platform: template
value_template: '{{ now() >= today_at(states(''input_datetime.run_timed_test'')) }}'
condition: []
action:
- service: mqtt.publish
data:
topic: shell
payload: timer-test
mode: single
It works for me.
This is my test automation:
alias: run_timed_test
description: ''
trigger:
- platform: template
value_template: '{{ now() >= today_at(states(''input_datetime.alarm_time'')) }}'
condition: []
action:
- service: notify.persistent_notification
data:
title: '{{ now(). timestamp () | timestamp_local }}'
message: Hello world!
mode: single
At 15:27 I executed this service call via Developer Tools > Services:
At 15:28, the automation triggered and generated the persistent notification:
I used your example character by character and it does not run for me, so I think I ended here. Anyway, a questions please-
today_at
statement? Does it mean that automation does not run if it is scheduled three hours later and it is the next day, after midnight?That’s a bad sign.
Until you fix the cause of its failure to work, there’s not much point for anyone to continue because your system isn’t behaving normally.
I suggest you check Logs for any errors because something is clearly wrong.
2021-11-23 15:33:00 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'today_at' is undefined when rendering '{{ now() >= today_at(states('input_datetime.alarm_time')) }}'
seems like today_at
is your own custom defined object.
can today_at
be avoided? I am afraid tha it will make problem if scheduled automation is next day.
Yes, you are free to design the template any way you want.
I have upgraded to latest version of HA, but when I enable the automation with script that should be scheduled that you recommended there is error:
2021-11-24 21:30:22 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{{ now() >= today_at(states('input_datetime.alarm_time')) }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 398, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1698, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/local/lib/python3.9/site-packages/jinja2/sandbox.py", line 393, in call
return __context.call(__obj, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1653, in today_at
raise ValueError(
ValueError: could not convert str to datetime: 'unknown'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 514, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 400, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: could not convert str to datetime: 'unknown'