Please Help with What Should Be A Simple Automation But Cannot Figure It Out

All, hoping for some help here as getting up to speed with HA and this one is proving difficult.

Trying to build an HA automation to do the following:

Scenario #1

  1. If time is between 10pm and 7am
  2. Motion is detected in the room (from motion sensor already in HA) for 4 seconds.
  3. Turn on Light in room (already in HA) for 5 seconds.
  4. If door in room is closed (previously would be open) then keep light on until door is opened (from the now closed state)
  5. If door in room (step 4) is never closed during 10 seconds (after step 2 & 3 have turned light on) then turn light off.

I’ve tried with Building Blocks and I keep getting stuck in trying to get this to work. Similarly I can only find the Entity moves From and To in the When section of the automation so we can’t nest those in AND IF or THEN DO ?

Thanks for any help you can offer as this one I feel should be simple but cannot get it to work as desired.

Conditions (the “And If” section) are a check of the current instant, they do not look at the past or wait for something to happen.

If you need to listen for another event you can use a Wait for Trigger action.


Your “When”/Trigger should be the motion detection.

Then the “And If”/Condition will be your time frame.

Your “Then Do”/Action sequence should be

  1. Turn on the light
  2. Wait for Trigger action with a 10 second time out.
  3. Condition to check if the Wait timed out
  4. Turn light off

Thanks so much for the quick reply. It looks like I was close as I do have 1, 2, 4 in place but not sure how to do 3 (condition to check if wait timed out). Can you provide additional guidance there ? Also would I need the Continue on Timeout to be ON or OFF ?

Also if I want to add a step 6 - if door is open (after being closed) turn light off at 10 seconds, is that also possible in the same automation ?

Thanks again

There are examples in the docs in the Wait Variable section. For yours you will need to use a Template condition like:

- alias:  Wait for trigger was did not fire before timing out.
  condition: template
  value_template: "{{ wait.trigger is none  }}"

If you want to add that o the same automation you would need to switch 3 to an If/Then action. Use another Wait for trigger in one of the branches.

Thanks again for your help. I will give these a try and report back, appreciate it !

One thing was about the Continue on Timeout toggle, should that be on or off for this ? Thank

continue_on_timeout needs to be true, which is the default value.

Thanks so much. I did get it working albeit it looks a little different than what you show here. What maddening is I am now trying the reverse for a day scene and that should be simpler but I’ve yet to get that one working.

Scenario #2

  1. If time is between 7:01am and 9:59pm
  2. Motion is detected in the room (from motion sensor already in HA) for 4 seconds.
  3. Don’t turn the light on UNLESS the door is then closed.
  4. If door in room is opened (after previously closed above in step 3) then turn light off.

I clearly have a lot to learn with HA but I’m determined to get there.