I have set up a time only input.datetime helper with the time I wish my wake up alarm to be. I have also set up a input_number which ranges between 0 and 30 minutes. This is the time before the input.datetime that the automation should be triggered to start fading in my lights up to the wake up time. How would I go about using a template to trigger the automation the amount of time in the input_number before the input.datetime. Date is irellevant as it should run every day.
In other words I wish to trigger an automation a variable amount of time before a specific time both of which can be set in the frontend.
Create a Template Sensor that computes the wake up time (subtracts input_number’s value from the input_datetime’s value). Set its device_class to timestamp.
In your automation, use a Time Trigger that monitors the Template Sensor you created.
Simple as that; let me know if you need help creating the Template Sensor.
Thanks for your reply. I would prefer to use a template trigger to save any uneccesary entities I’m just not sure how to template it. I’m not familiar with templating timestamps.
This does appear to be supported (it is working) however the transistion is in seconds and my value is in minutes so i changed it to the following for the reference of anyone viewing this thread in future.
Since I was looking for similar automation could you pls help with mine? I have a time sensor that dynamically changes let’s say sensor.sunset_time. I want to set an automation that will notify me 10 minutes before the sunset. How can I achieve that?
A Time Trigger supports an input_datetime that includes time-only, date-only, or time and date. If it’s not working for your time-only input_datetime then the question is: are you using a very old version of Home Assistant?
If you are using a recent version, then check the automation’s trace to see if it has in fact triggered but encountered some other problem.
Thank you very much for responding! I am running version 2022.7.7. I checked the trace for the automation but since it doesn’t trigger I don’t get anything.
I believe the reason why your automation isn’t triggering is because its two Time Triggers refer to input_datetime entities that don’t exist.
When you define an input_datetime, the name option represents its friendly name not its entity_id. The Time Trigger requires the input_datetime’s entity_id.
Here’s how to correctly reference the two input_datetime entities that you defined:
trigger:
- platform: time
at: 'input_datetime.alert_reminder_1'
- platform: time
at: 'input_datetime.alert_reminder_2'
You can also do this:
trigger:
- platform: time
at:
- input_datetime.alert_reminder_1
- input_datetime.alert_reminder_2