So, I am trying to automate a light to get progressively angrier at me the longer my standing desk is in the down position. To trim down the requirements slightly, I essentially want to have a wall light change scene after 2 hours of the sensor being in the closed position (desk in sitting mode). Once that 2 hour mark is hit, every 5 minutes, I would like the light to change to a scene for 1 minute, and then change back again. If it gets to 3 hours, I want to change to another scene until the desk is in the up position.
if at any point the sensor goes to the open position, then the light scene should go back to normal, so no 5 minute change, no 3 hour final scene, and if its before the 2 hours, then essentially it should no longer matter.
To add some additional complexity, I would like the 2h timer to start from when I walk into the room (not at a fixed time), and, I don't want it to get angry at me outside of 8am and 5pm. So for example, if the timer starts at 3:30.. next "angry" would be 5:30.. which shouldn't fire because its outside of the 8-5 window.
What I have tried?
So, my first attempt at this was to create an helper timer. I then setup an automation to start the timer when a motion sensor gets triggered.
Next, I setup another automation to cancel the timer when the desk is in the open/standing position.
Third, I setup another automation that triggers when the timer ends (ie, reaches 2 hours). This then runs a script that loops until the desk sensor is in the open position. The loop essentially set the angry scene, wait 1 minute, sets the normal scene, waits 4 minutes and keeps looping with a repeat index off 11 (which should mean it does it up to an hour).
The problem with this approach was that the desk script seems to continue running as the until doesn't seem to be checked very often. So you would end up with thing happening while the script continued to run.