When I sleep, turn off AC in 90 minutes.
Then start again after about 2 hours for 60 minutes.
Sounds simple, but have 2 problems:
Sleep at different times so just timed automation won’t work.
Now the thing is the place where I am there are a lot of power cuts and it’s possible that HA can get restarted multiple times during night, so need a solution where timer persists on restart.
Depending on your platform, I’m on ubuntu and has been testing alternate timer automation using crontab with HA api.
The basic idea is when a switch is turn off with automation, a job to turn it back on is added to the crontab with appropriate time to execute so doesn’t matter HA restart or system reboot, the job will run when it’s time.
Something to consider.
Not sure what you’re using, or plan to use, for HA to know when you’ve gone to sleep, but when that happens, you can grab the current timestamp into an input_text. Then you can trigger the next event (e.g., turning the AC off 90 minutes later) by comparing sensor.date__time (converted to a timestamp) to the grabbed timestamp. This will work, as long as HA has a chance to gracefully shutdown when you have a power outage, because input_text entities are saved & restored at shutdown and startup. (If HA doesn’t have a chance to gracefully shutdown, I’m not sure what would work.) E.g.: