I’ve set up an input_datetime to trigger my alarm clock. I’d like to have an offset of 2 minutes before the alarm clock rings to turn slowliy fade up the light. How can I implement the offset? So far I’m using this to trigger the alarm:
The first part gets the time two minutes from now. Then it’s comparing it to the input_datetime. When they equal each other it’s two minutes before your alarm time.
Where do I have to place the offset part in my given example with sensor.time and the comparison to states.input_datetime.alarm_clock.attributes.timestamp? Can’t get it to work.
You can just replace your value_template in your trigger with the one I provided. It should work as is.
Your template won’t work for this because you need to convert the current time to seconds before adding 120 to it. Sensor.time is a string so it can’t be converted to seconds. Now() gets you the current time as a datetime object so you can convert it to seconds using strftime.
For shits and giggles, copy that code into a sensor template and watch whether the template turns true or false. I’m wondering if templates are broken in triggers or if now() is broken everywhere. Also, have you looked at the release notes and checked to see if there are any breaking changes?
The other option is to toss that into the template editor and verify that it works as expected as well.
I haven’t tried it in an automation. The only way these would trigger in an automation is based off sensors updating. using now() will not cause triggers to occur when now() changes, but using sensor.time should. I would expect the last variation you posted to trigger the most.
Trying to run an automation based on template trigger @petro posted above. It doesn’t trigger. Actually its a test for an alarm clock automation that is more complex but I try it to run it simple first. I’ve made an input_boolean and an input_datetime with ui card.
The only thing I wanted was an offset for my alarm clock to fade up the light before the media service starts. After research was template the only way to realize an automation. If there is a more elegant way I would be thankful for a way to go.