Best way to do action, then wait, then do another action?

I’m fairly new with HA - just getting into the cool stuff. I’m trying to figure out the best way to accomplish the following:

  1. Motion sensor senses motion
  2. A light is turned on and set to red (this was easy, I have it configured already)
  3. Motion sensor stops sensing motion
  4. The light changes to yellow (got this too)
  5. After 2 minutes, the light turns green
  6. After 10 minutes, the light turns off
  7. At any point after step 3, if the sensor triggers again, it should abandon the wait/timer actions and just turn red and start over.

Do I use scripts? I saw info about single and parallel - how do I get it to interrupt and override the pending actions? Any help is much appreciated.

You’re going to need some helpers. You’ll need one or more timer helpers and probably an input_select helper to keep track of where you are in the process. A timer can be cancelled or (re)started. You can trigger an automation on timer.finished. You can add the timers and input_select to your dashboard and watch the process.

I assume you’ve already created some automations to get where you are. See how far you can get with these hints. Sometimes it’s good to struggle a bit in order to gain understanding. :slight_smile: Scripts are just automations without a trigger. They are useful when you need to reuse the same logic/actions from multiple automations or maybe even multiple places in the same automation.

One final hint. As long as your motion sensor is reliable, I like to cancel the timer(s) when motion is first detected and then restart the timer when the motion is clear. Otherwise, constant motion could allow your timer to expire. It’s OK to cancel a timer that is already idle. It has no effect.

Or you could just use the colour attribute of the light to track the progress.

Yes, that could work. Didn’t occur to me because I’ve yet to use multicolor lights with HA. However, in general, there might be more states than colors. Maybe he’ll want to add flashing next?

The red light does really not make any sense.
The sensor will not transmit motion all the time, when there is motion, but with intervals, so the red light will just be the “cool down” of the sensor or it’s transmitting interval.

The easiest way would just be to make anautomation that have mode set to restart and then all the events will just be timed with delays.

1 Like

:laughing:

Nice. These are all great starts for me to get to reading the documentation. Thank you!

Success! I now have 2 color-coded bathroom occupancy indicators (1 for each bathroom in an office). Red when occupied, yellow for 3 minutes (let the smells dissipate =), then green for 10 minutes. I used the Linptech ES1ZZ(TY) zigbee occupancy sensor reviewed on https://www.youtube.com/watch?v=Kt1FpRM8R18

For reference, here’s what I ended up doing. There’s an automation that triggers off the mmwave occupancy sensor, it sets a RGB light to red and clears the 3 minute and 10 minute timers:

When the sensor reports unoccupied, it sets the light to yellow and starts the 3 minute timer

When the 3 minute timer finishes it sets the light to green and starts the 10 minute timer

Finally, the 10 minute timer ends and turns off the light entirely

All this required 4 timers set up in the “Helpers” section