Wait for trigger keeps waiting indefinitely

I have a script which gets called from an automation. The script turns on two lights and then waits for a trigger before turning on more lights. The trigger is light level from a Hue sensor. The script waits for light level to fall below 14000 for 5 minutes. For some reason, the script keeps waiting indefinitely for this trigger even when light level has fallen below 14000 and remained there for hours.

When script is called, switch.under_cabinet_lights is turned on, then a 5 seconds wait, then light.family_room_table_lamp is turned on. But after that, script keeps waiting for light level to go below 14000. The switch.staircase_top_lights is never turned on.

Under Trace Timeline, it keeps showing Wait for 1 trigger and Still running even after two hours.

How do I fix this?

sequence:
  - continue_on_error: true
    service: switch.turn_on
    data: {}
    target:
      entity_id:
        - switch.under_cabinet_lights
  - delay: "00:00:05"
  - service: light.turn_on
    target:
      entity_id: light.family_room_table_lamp
    data:
      brightness_pct: 100
  - wait_for_trigger:
      - platform: numeric_state
        entity_id:
          - sensor.hue_motion_sensor_1_illuminance
        for:
          hours: 0
          minutes: 5
          seconds: 0
        attribute: light_level
        below: 14000
  - continue_on_error: true
    service: switch.turn_on
    target:
      entity_id: switch.staircase_top_lights
    data: {}

I don’t think you need the attribute line. This works on my Hue motion sensors:

trigger:
  - platform: numeric_state
    entity_id:
      - sensor.bedroom_motion_sensor_illuminance
    for:
      hours: 0
      minutes: 10
      seconds: 0
    below: 1000

I did try without the attribute line, but same behavior.

If I use the trigger in automation with or without attribute, it works fine. It does not work in wait for trigger in the script.

I’m not a Hue user so I’ll defer to others about the state v. attribute issue until you provide more info.

What does the trace show?

Is the light level already below the threshold at the moment the wait for trigger starts?

Keep in mind that for all triggers (which includes wait_for_trigger) the trigger must transition from ‘not met’ to ‘met’ in order for the trigger to be fired. If you enter that wait_for_trigger block and the light level is already below 14000 then you must wait for the level to rise above 14000 and then fall back below 14000 and stay there for 5 minutes.

1 Like

Under Trace Timeline, it keeps showing Wait for 1 trigger and Still running even after two hours.

This is a strong possibility that I did not check for. It is very much possible that by the time script is called by the automation, the light level has already fallen below 14000. I will try to eliminate this possibility and update this post. The trigger transition did not cross my mind. Thanks for pointing it out.

If you switch to a wait template you are not held to the same rule as with a wait for trigger.

The only way that can be true is if the sensor has the illuminance value both as its state and as a light_level attribute. Please share a screenshot from Developer Tools / States showing the state and attributes, like this:

If you are guessing things like this, it’ll take you much longer to get to a working solution. Use the States view above to work out if you should be referencing the state (so no attribute: line) or an attribute of the sensor.