Automation movement and lifx - sensor acting like toggle

Hi All,
Bit unsure of what is causing this and it seems to only be prevelant in my automation with lifx bulbs.

pretty simple… movement seen --> turn on lights --> wait 6 minutes --> turn light off.

However after movement executes the automation if you move infront of the movement sensor it toggles off the lights.

I have changed to a totaly different type of movement sensor so Im pretty sure its something in my layout.

thankyou

  alias: Guest Bathroom Lighting
  trigger:
  - entity_id: binary_sensor.guest_toilet_movement
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - after: '17:30:00'
    before: '23:59:59'
    condition: time
  action:
  - data:
      brightness_pct: '100'
      color_name: white
      entity_id:
      - light.lifx_d0_73_d5_38_1a_e2
      - light.lifx_d0_73_d5_38_25_6e
      - light.lifx_d0_73_d5_51_c5_63
    service: light.turn_on
  - delay: 
      minutes: 5
  - data:
      entity_id:
      - light.lifx_d0_73_d5_38_1a_e2
      - light.lifx_d0_73_d5_38_25_6e
      - light.lifx_d0_73_d5_51_c5_63
    service: light.turn_off

when an automation with a delay is triggered again during the delay it will skip all conditions and all delays/wait templates and just execute the actions. To overcome this you can create a timer and turn the lights off when the timer finishes. This way you timer will also be reset on a new motion detection. Search the forum or let me know in case you need some help.

Or just use two automations like this cookbook example:

1 Like

@Burningstone ok need some help…

I have managed to get this working but I did it with
a. configuration.yaml holding the timer (im sure that is right)
b. an automation starting lights on with movement picked up by sensor
c. a second automation killing the lights after timer expires. (if I walk into the movment zone the counter starts again).

So function wise this is working fine.

Question. Is the 2 automations how this is done or am I missing something.

It’s easier to just use @tom_l suggestion.

Here the code for the same with a timer

The timer, goes into configuration.yaml

timer:
  guest_bath_light_timer:
    duration: '00:06:00'

The first automation:
Motion detected -> turn on light and start timer
When an already running timer is started it will just start again from the beginning.

- alias: "Turn on guest bathroom light on motion"
  trigger:
    platform: state
    entity_id: binary_sensor.guest_toilet_movement
    to: 'on'
  action:
    - service: timer.start
      entity_id: timer.guest_bath_light_timer
    - service: light.turn_on
      data:
        brightness_pct: '100'
        color_name: white
        entity_id:
          - light.lifx_d0_73_d5_38_1a_e2
          - light.lifx_d0_73_d5_38_25_6e
          - light.lifx_d0_73_d5_51_c5_63

The second automation turns off the light when the timer finishes.

- alias: "Turn off lights after 6 minutes of no motion"
  trigger:
    platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.guest_bath_light_timer
  action:
    service: light.turn_off
    entity_id:
      - light.lifx_d0_73_d5_38_1a_e2
      - light.lifx_d0_73_d5_38_25_6e
      - light.lifx_d0_73_d5_51_c5_63

Yep thats what I ended up with… thanks guys.