I have a few problems I'm trying to solve.
First, not very common but does happen. For fans, lights, etc I have timers to auto shut them off. Think motion lights, bathroom fan, etc. Humidity is too high bathroom fan comes on for 10 minutes and then off. Sometimes if I'm testing something I will restart NR during these timers (happens with motion lights more often) and they will then be reset and won't trigger. It's not a huge issue but fans/lights have been left on for a while because of this.
Second, related to the first, the logic around what happens if the fan/light is manually shut off gets complicate because then the timer triggers later and might shut off prematurely. Light is triggered on because of motion, auto off in 5 minutes. I shut the light of manually in 4 minutes, then back on and a minute later the timer fires and auto shuts the light off. I have some logic in place to get around this but it's ugly.
Third, climate. I control my heatpumps via mqtt and I want to implement a hold for n hours. I could use a timer but again to my first point if I restart etc it might get reset and will never go off. It would also be nice to easily cancel this hold or change it, again, complicate NR logic to handle these case.
I've been searching for a solution but nothing has really popped up. In my ideal situation the timer (the date) would be stored and something would check every minute? if that date has passed simply trigger the event. This would easily allow me to remove, replace or catch missed events.
So, picture a state object like this
[
{ id: $unqiue_set_by_setter, trigger: $timestamp, topic: timer/fire/test },
{ id: living_climate_hold, trigger: $timestampe2, topic: climate/hold/off }
]
Every minute I loop over that list and check if it's past the timestamp. If it is I publish to the stored topic (with optional payload). Something else, probably another flow, would listen for that topic and handle the event (shut off the fan). If the light is shut off I simply remove the item from the list. If it's updated (hold changed for heatpump) I simply update the object in the list.
Thoughts? Am I overly complicating this?