Getting stuck on "Wait for device trigger"

Hi all.

I have stared at this automation for too long. I cannot figure out what I’m doing wrong. I’m fairly new to my HA automation journey, so please LMK if I’m doing something stupid.

I’m trying to automate lights based on the sun. When the sun is above the horizon, motion triggers it at 65% brightness, and below at 5% brightness. Then after 1 minute of no motion switch off the light.

This should be so simple but for some reason, my automating gets stuck at the last step and stays “Waiting for trigger” and never switches off the lights?

Any help will be greatly appreciated. :slight_smile:

Here is the yaml code:

id: '1644338994620'
alias: Light - Bathroom Downstairs v1 - sun.sun
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.motion_bathroom_downstairs_occupancy
    from: 'off'
    to: 'on'
condition:
  - condition: device
    type: is_off
    device_id: 6fdd28d5ed372036c37a2546af62c1c7
    entity_id: light.lights_overhead_bathroom_downstairs
    domain: light
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: sun.sun
            state: above_horizon
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.lights_overhead_bathroom_downstairs
            data:
              brightness_pct: 65
      - conditions:
          - condition: state
            entity_id: sun.sun
            state: below_horizon
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 5
            target:
              entity_id: light.lights_overhead_bathroom_downstairs
    default: []
  - wait_for_trigger:
      - type: no_motion
        platform: device
        device_id: e45615c69b8419deeb2ade195b21ae23
        entity_id: binary_sensor.motion_bathroom_downstairs
        domain: binary_sensor
        for:
          hours: 0
          minutes: 1
          seconds: 0
  - service: light.turn_off
    target:
      entity_id: light.lights_overhead_bathroom_downstairs
mode: single

Couple of things come to mind here:

1st. In your initial trigger you reference to;

binary_sensor.motion_bathroom_downstairs_occupancy

however in the wait trigger you reference to;

binary_sensor.motion_bathroom_downstairs

2nd. It’s generally advisable to use the state trigger not device trigger.

3rd. Unlikely but you have wait trigger for 1min, what’s the cool down period of your sensor, have you checked it’s state is changing to off on the time frame you expect?

Hi there -

Thank you for your response.

I’ll update #1 & 2 as outlined.

The cool-down period is 2 mins (Aqara Zigbee Motion). I set it to 1 minute, thinking it will add it once the 2-minutes cool-down period is complete? Should the “wait trigger” period be longer than the cool-down period?

Again, thank you for the help.

That depends on what the sensor is registering in home assistant during that period.

Go to developer tools and check the stats of the sensor after triggering motion and that will tell you what you need to know about it’s behaviour and can then add or subtract from that.

It seems that changing to a state trigger vs device trigger did the job.

Thank you for your help.

Your very welcome :+1:t2: