Home arrival light automation behaviors

Hi all. I have an automation that I am using that is exhibiting some strange behavior, but only when both parties enter/leave the residence at the same time.

I WANT it to function like this:

If person “x” is away and comes home when the sun is down, the light is turned on and then turned off after the predetermined time. This works perfectly when one person in the automation comes home, however when both return home the light turns on briefly then immediately turns off. What am I missing here? See code below.

Edit, I don’t think I did the code block formatting correctly sorry for that.*

`# FLOOD LIGHTS ARRIVAL #

  • alias: Porch Light Arrival
    trigger:
    • platform: state
      entity_id: binary_sensor.matt_home
      from: ‘off’
      to: ‘on’
    • platform: state
      entity_id: binary_sensor.brittany_home
      from: ‘off’
      to: ‘on’
      condition:
      condition: state
      entity_id: sun.sun
      state: ‘below_horizon’
      action:
    • service: switch.turn_on
      entity_id: switch.front_porch_light
    • delay: ‘00:02:30’
    • service: switch.turn_off
      entity_id: switch.front_porch_light`

Try to use OR conditon. See reference for syntax.

Use a timer instead and just set it reset it when someone gets home.

I’ve found that running an automation more than once in parallel, causes issues. Check your home assistant log, you will see an exception.

Try it like this instead:

trigger:
  platform: state
  entity_id: 
    - binary_sensor.matt_home
    - binary_sensor.brittany_home
  from: ‘off’
  to: ‘on’

etc...

Also in future please select your code and press the </> button in the message toolbar or follow the instructions in the blue banner at the top of the page to format your code correctly. Indentation is important in YAML.

1 Like

Thanks, I’ll give that a shot and see what it does. Help me understand the functional difference between how I had it, and how you have it here?

Well, I tried that format. It does not trigger at all.

Please post your properly formatted automation code.

You could try separating the actions into a script and starting that script from the automation, but only if it’s not currently running.

automation:
- alias: Porch Light Arrival
  trigger:
    platform: state
    entity_id:
    - binary_sensor.matt_home
    - binary_sensor.brittany_home
    to: 'on'
  condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  - condition: state
    entity_id: script.front_porch_light
    state: 'off'
  action:
    service: script.front_porch_light

script:
  front_porch_light:
    sequence:
    - service: switch.turn_on
      entity_id: switch.front_porch_light
    - delay: '00:02:30'
    - service: switch.turn_off
      entity_id: switch.front_porch_light
1 Like

Thanks, I’m going to give it a shot. I guess I never thought that this wouldn’t be able to be completed with a simple automation. Frustrating!

Well, I didn’t say it couldn’t. I suggested this based on what others have said. I have many automations with multiple triggers and I’m not aware of any having issues like this. But that could just be because I haven’t noticed (yet.) It could also be that I tend to put long action sequences, especially ones with delays or waits, into scripts rather than putting the actions directly into the automations anyway.

The script and automation combo works great. Thanks!

1 Like