if motion turn on/off switch 10 times space over the course of the next hour. Say, on for 2 minutes, off for 8. Something like that. The actual intervals can be configurable.
If I were using time.sleep() this would be simple, but I’m not quite sure how to do it using appdaemon run_in scheduling. Any ideas?
You could store the state changes with timestamps in a sensor entity (as an attribute dict) and check that data during each callback and do something if the criteria you’re looking for matches.
Ah ok, yeah if you’re looking to run every hour that is fine. I thought maybe you wanted to check when the event happened if $x amount has happened within the last hour. As long as this works for you.
I suppose this isn’t actually my whole solution. I’m using another virtual switch that gets turned on with motion in the room. This code only runs when that other virtual switch is on. It turns the device on for 2 minutes, then off for 8 minutes, as long as that other switch is on, aka the room is occupied. the 10 * 60 is straight from the docs. I don’t know why it’s put that way in the docs and not just 600 seconds.
I also still need to parameterize that interval and the now+interval.