thus firing the sunrise script. How can I make sure that the sunrise script is not executed when my alarm sensor is unavailable? Any help is appriciated.
It may be more efficient to use a template trigger rather than triggering every minute. You would simply have to use as_local(states.sensor.time.last_updated).timestamp() rather than now().timestamp() in the trigger template.
- id: wake_up_light
alias: Wake_up Light
description: ''
trigger:
- platform: template
value_template: >
{% set t = (state_attr('sensor.samsung_galaxy_s10_next_alarm', 'Time in Milliseconds')|int) / 1000 %}
{{ 0 < t < as_local(states.sensor.time.last_updated).timestamp() + 1800 }}
action:
- service: script.sunrise
mode: single
Actually with recent changes to how now() is handled in templates you may even still be able to use that. Not sure if that update has been merged/released yet though.
Technically true but both perform work every minute. The first one evaluates the condition’s template, the second one evaluates the trigger’s template.
Even the first one won’t update its last_triggered time every minute because that only occurs if the action is executed.
I am running Beta 5.2 because I boot from SSD on RPi4.
The solution of @123 works, I suppose. Yesterday I forgot to reload my automations so it was pretty dark this morning. Will test again tonight.
If I understand correctly, the method of both tom_l and 123 both work, and one is not per sé better than the other? @tom_l, Can you please explain the logic behind your script? Is as_local(states.sensor.time.last_updated).timestamp() the current time (eg 13:34) when I set alarm (eg at 07:00)?