Automation? to turn off a switch in 10 days

My google fu is failing me. I can not figure it out.
Can it be done?

Hi, I cannot not give you a working answer.
You will have to be aware that if you just use ‘on’ and a delay of 10 days, it will not work if HA is restarted in the meantime.
Somehow you will have to use the on date + 10 days as a trigger for switching off.

Maybe this might put you in the right direction to search for info/examples or someone else might jump in with a solution…

Create a calendar event and use that as a trigger.


Good pointer!
And I guess if needed regularly: in an automation which switches on, create the calendar event?

1 Like

Can’t you use a timer for this?
It should survive a reboot as far as I know.

Or something like this:

service: calendar.create_event
metadata: {}
  summary: Turn switch off (or description for event to have the switch on)
  start_date_time: "{{ now() }}"
  end_date_time: "{{now() + timedelta(days=10)}}"
  entity_id: calendar.test

create a datetime helper that gets set by an automation to 10 days from when the switch is turned on or when you want the switch to turn off.

then use the datetime helper as the trigger to turn the switch off.

1 Like

Thanks all. So far it looks like the datetime helper works.

1 Like

Yes, I think too that the datetime helper is the best solution.
Kudos to @finity

Just out of curiosity: can anyone enlighten me what the differences (pro/cons) are using a datetime helper or a timer?

1 Like

Timers are less robust and more failure prone.

it has gotten better since they now survive restarts but I still don’t trust them fully for long term timescales. anything longer than 5 minutes and somewhat critical I typically use a datetime instead of a timer or any type of wait/delay.

1 Like