Goodnight routine

I’ve set up a script and automation to run through Alexa. The script turns on the landing lights for 10 minutes when we go to bed. Then the automation kicks in for motion detection which runs until sunrise. The lights on the landing are huge lights. The routine runs but no matter what I try to change to keep the lights on longer than 20 seconds when no motion is detected seems impossible. Here is the code. Hopefully, someone can see what I am missing.

alias: Landing Motion Control (HA)
triggers:
  - entity_id: binary_sensor.hue_motion_sensor_1_motion
    to: "on"
    trigger: state
conditions:
  - condition: state
    entity_id: input_boolean.alexa_goodnight_v3
    state: "on"
  - condition: state
    entity_id: light.landing
    state: "off"
actions:
  - entity_id: light.landing
    data:
      brightness_pct: 25
    action: light.turn_on
  - wait_for_trigger:
      - entity_id: binary_sensor.hue_motion_sensor_1_motion
        to: "off"
        trigger: state
    timeout: "00:02:00"
  - entity_id: light.landing
    action: light.turn_off
mode: restart

Hi, please start by reading point 11 (format it properly) from the How to help us help you - or How to ask a good question

Thanks for the response. I couldn’t find the formatting button as the prompt suggested when I published the post, my apologies

:wink: No problem, you can still edit your post now that you know how to format the code.

Hi,

Instead of timeout, try delay.

  - delay:
      minutes: 10

Replaced the timeout line with delay and got the following message. New to yaml so not entirely sure what it means

Message malformed: required key not provided @ data[‘actions’][1][‘wait_for_trigger’][1][‘trigger’]

The suggestion was to replace the entire wait_for_trigger with delay.

In other words, your automation will no longer wait for the motion detector to report off but will simply wait for a hard-coded period of time to pass.


FWIW, you may have misunderstood the purpose of the timeout option. The wait_for_trigger will wait for the motion detector to report off up to a maximum about of time specified by timeout. In other words, the wait_for_trigger finished when either the detector reports off or the timeout expires, whichever occurs first.

Not really, I use a combination.
After the Motion-Sensor goes from on → off , wait this delay, and then action.

  - alias: Wait until there is no motion from device
    wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
    continue_on_timeout: false
  - alias: Countdown or it restarts upon motion_sensor signal
    delay:
      hours: 0
      minutes: 0
      seconds: 10

I hope this is understandable.

If that was your intended suggestion, then I can understand why the OP didn’t understand what you meant when you wrote:

1 Like

Thanks, but a little beyond me. From my original code where would this new code go. Only been using this for three weeks or so

If you edit your automation in visual editor:

Countdown is in building-block IIRC.


Thanks for this. I’ll spend a little more time trying to understand this and make changes to my existing code. Thanks again

Put this code in place and seems to do the trick. Thanks for all your help

alias: Landing Motion Control (HA)
triggers:
  - entity_id: binary_sensor.hue_motion_sensor_1_motion
    to: "on"
    trigger: state
conditions:
  - condition: state
    entity_id: input_boolean.alexa_goodnight_v3
    state: "on"
  - condition: state
    entity_id: light.landing
    state: "off"
actions:
  - entity_id: light.landing
    data:
      brightness_pct: 25
    action: light.turn_on
  - wait_for_trigger:
      - entity_id: binary_sensor.hue_motion_sensor_1_motion
        from: "on"
        to: "off"
        trigger: state
    continue_on_timeout: false
  - delay: "00:00:30"
  - entity_id: light.landing
    action: light.turn_off
mode: restart
1 Like