Life360 Tracker Automation

I have an automation that uses life360 and when anyone in the family gets home after dark it is supposed to turn on the Driveway Light and Porch Light, Delay 10 minutes, and then turn the lights off. It works perfectly when only one person gets home. If multiple people get home at the same time it get’s a little screwed up.

For example, my wife and I got home at the same time last night. HA reports my wife getting home at 8:21, the automation runs and the lights come on. Then it reports me getting home at 8:23, the automation runs and the lights go off. I’m pretty sure the problem is the automation being called for each person getting home. I’m just not sure how to fix it. I’m still new to this. Here’s my yaml.

- alias: Turn on Outside Lights when arriving home after dark
  description: ''
  trigger:
   - entity_id: device_tracker.life360_emory, device_tracker.life360_jaci, device_tracker.life360_sierra, device_tracker.life360_fiona
     platform: state
     from: 'not_home'
     to: 'home'
     
  condition:
    condition: state
    entity_id: sun.sun
    state: 'below_horizon'
      
  action:
   - service: switch.turn_on
     data:
       entity_id:
         - switch.shelly_shsw_25_ba70a4_1
         - switch.shelly_shsw_25_ba70a4_2
   - delay: 
       seconds: 600
   - service: switch.turn_off
     data:
       entity_id:
         - switch.shelly_shsw_25_ba70a4_1
         - switch.shelly_shsw_25_ba70a4_2

Thanks for any help. :grinning:

This is a classic problem that has been discussed very often on the forum. The issue is how automations work. If the automation actions contain a delay or wait_template, and is sitting in one when a trigger fires, rather than starting the automation over, instead it simply aborts the delay/wait_template and continues with the next step.

Move the actions into a script. Then in the automation, turn off the script (in case it’s still running from a previous trigger), then start it.

Automation:

- alias: Turn on Outside Lights when arriving home after dark
  description: ''
  trigger:
  - entity_id: device_tracker.life360_emory, device_tracker.life360_jaci, device_tracker.life360_sierra, device_tracker.life360_fiona
    platform: state
    to: 'home'
     
  condition:
    condition: state
    entity_id: sun.sun
    state: 'below_horizon'
      
  action:
  - service: script.turn_off
    entity_id: script.lights_on_and_off
  - service: script.lights_on_and_off

Then in scripts.yaml:

lights_on_and_off:
  sequence:
  - service: switch.turn_on
    entity_id:
    - switch.shelly_shsw_25_ba70a4_1
    - switch.shelly_shsw_25_ba70a4_2
  - delay: 
      minutes: 10
  - service: switch.turn_off
    entity_id:
    - switch.shelly_shsw_25_ba70a4_1
    - switch.shelly_shsw_25_ba70a4_2

Works perfect. Thanks.