Hello does anyone know how to check if an event on local calendar will happen in the next x
hours in an automation or node red (I am complete beginner of node red).
Thanks.
Can you put node-red in your tags? Because this is not related to automation and templates.
Yes it is as i would prefer to use an automation with a template and node red is a last result but i will add node red
Edit: node-red tag doesn’t exist at least i cant find it
Edit 2: just found it
In automation, you can use a template condition.
{{ state_attr('calendar.your_calendar', 'start_time') }}
Is giving you the start_time of the next event.
you can then compare this to now()
- condition: template
value_template: '{{ ( state_attr('calendar.your_calendar', 'start_time')|default(0,true)|as_timestamp()|default(0,true) - now()|as_timestamp()) <= (5 * 60 * 60) }}'
That will trigger as soon as the event is in less than 5 hours (5 * 60 minutes * 60 seconds)
P.S.: Not tested, you’ll have to play arround.
1 Like
Thank you so much this works perfectly in my automation
1 Like