I’m quite glad I came upon this thread! I have been trying (unsucessfully!) for more than a few hours to get this working with a template sensor. ih8gates - I had the same thing where the template sensor evaluated in the dev tool but when I put it in an automation/sensor it would not update automatically.
In the end it was omeasire’s idea that worked the trick. Check the template value every minute to see if it’s true or not! My code below for turning on my hot water heater the day before an airbnb booking begins (calendar is automatically generated/imported from airbnb so modifying that was out of the question):
- alias: Hot Water On day before
hide_entity: False
trigger:
platform: time
minutes: '/1'
seconds: 00
condition:
condition: and
conditions:
- condition: template
value_template: '{{ as_timestamp(now()) | int > (as_timestamp(states.calendar.airbnb.attributes.start_time)-79220) | int }}'
- condition: template
value_template: '{{ as_timestamp(now()) | int < (as_timestamp(states.calendar.airbnb.attributes.start_time)-79180) | int }}'
action:
service: notify.notify
data:
message: "Hot Water On day before"
So for this example it checks if the time is greater than 11:59:40 and less than 12:00:20, giving a buffer for the time trigger on the minute to make sure both are satisfied. For the sake of the example, the notification will turn into a MQTT trigger to trigger a relay.
I’m not sure how ‘computationally intensive’ checking every minute is, but the same idea could work with checking every 10 minutes.
Thanks for your help ih8gates and omeasire!