Automation - Wait for Trigger. Am I Doing This Wrong?

It’s checking my wink motion sensor state.
If it’s on and it’s between Sunset and sunrise, the light_on command is executed and a 90 second timer is started.

After 90 seconds of no motion, the light is turned off.

I also have it set to restart timer (trigger element) if motion is detected within the 90 seconds.

Here’s an alternative way, using a single automation. I’ve tested it (using my own entities) and it works as per your requirements.

- id: 'abc123xyz456'
  alias: Kitchen - Lighting w Motion
  description: Turns on Kitchen Pots for 5 mins when motion detected after sunset
  trigger:
  - platform: state
    entity_id: binary_sensor.presence_8
    to: 'on'
  - platform: state
    entity_id: binary_sensor.presence_8
    to: 'off'
    for: '00:05:00'
  condition:
  - condition: sun
    after: sunset
    after_offset: -00:30:00
  action:
  - choose:
    - conditions:
        condition: template
        value_template: "{{ trigger.to_state.state == 'on' and is_state('light.light_kitchen_pots_level', 'off') }}"
      sequence:
        service: light.turn_on
        data:
          entity_id: light.light_kitchen_pots_level
          brightness_pct: 85
    - conditions:
        condition: template
        value_template: "{{ trigger.for is defined }}"
      sequence:
        service: light.turn_off
        entity_id: light.light_kitchen_pots_level

It uses choose to determine which one of the two triggers triggered the automation.

  • If it was the first trigger (motion sensor turns on) and the light is currently off, the action is turn on the light.
  • if it was the second trigger (motion sensor is off for 5 minutes), the action is turn off the light.
1 Like

Wow! Nice. Thank you. I’ll give this a shot tonight.

If you’re eager to test it, change the sunset condition to sunrise (or exclude the entire condition) and it’ll work immediately (that’s how I tested it and set for to just 00:01:00).

Any progress to report?

Hi! Yes. It is working quite well. There is the occasional time where the light may go out (due to 5 mins of non-motion), but then takes a while to come back on with motion for some reason. As in, if the light goes out right now, motion does not immediately make it come back on. Almost like the trigger of to: off for: 5 mins was picked up, but when it went to action the turn off light the motion sensor maybe flips back to on quicker than the automation can pick it up, therefore causing the light to remain off until such time as the motion sensor reverts back to off, then to on.