Best way to trigger automation based on time offset?

I have an automation that reminds me to turn off the guest mode at home every 24 hours until the it is actually turned off. Originally i was using a timer, but found that unreliable and got some help on this thread that helped me realize the error in my ways. I have updated my automation to use trigger based on time delta using this template:

{{ (as_timestamp(states('input_datetime.guest_visiting_timestamp')) | int) == (as_timestamp(now() - timedelta(hours=24))| int) }}

In doing some reading, I believe that since the template uses now() it gets evaluated every minute, is there a better way to do these sort of time offsets or is using now the preferred way?

If it’s not important that it checks exactly after 24 hours then you could just set up the automation based on time trigger.
So every day at noon as an example, and condition is the guest mode input boolean (I guess?)

1 Like

Your understanding is correct. It’s not a huge overhead though.

You can set another input datetime with the future datetime when your guest mode is turned on. You can then use a time platform trigger using the helper in the at: option. You will then notify and adjust the helper another 24 hours ahead when that triggers, under the condition that your guest mode is still on. I’m assuming your guest mode is an input boolean helper.

1 Like

Thank you both for the suggestions, i decided to take a piece out of each and just increment the input_datetime timer 24 hours when it is first set it:

"{{ state_attr('input_datetime.guest_visiting_timestamp', 'timestamp') + 86400 }}"

Then in the automation I check if the input_boolean is still set when that time comes around. Seems to be working and i believe it is more efficient, no empirical evidence, just touchy-feely.

1 Like