HA and turning lights on when a door is opened

I currently have my HA set up so that when our alarm is armed, the sun is below the horizon and the front door is opened, it’s supposed to turn on the Living room lights. I also have an automation that says if the alarm is armed, the sun is below the horizon and the basement door is open, it’s supposed to turn on the ‘Theater’ (basement) lights. But what really happens is if the alarm is armed, the sun is down and the front door is opened, the living room AND the basement lights come on. I thought I had just somehow managed to goof something up in the automation and hadn’t looked into it until now… but what I have in my automations file makes sense to me (lol), but apparently is somehow borked.

Here’s what I have:

#
#Turn Living Room Lights on when we come home
#
- alias: Turn Living Room Lights on when we come home
  trigger:
  - entity_id: binary_sensor.front_door
    platform: state
    from: closed
    to: open
  - entity_id: sensor.home_alarm_keypad
    platform: state
    from: Arm Away
    to: Entry Delay in Progress
  condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
    service: homeassistant.turn_on
    entity_id: light.leviton_dz6hd1bz_decora_600w_smart_dimmer_level_57_0
#
- alias: Turn Living Room Lights on when we come home FOB
  trigger:
  - entity_id: sensor.home_alarm_keypad
    platform: state
    from: Arm Away
    to: Disarmed
  condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
    service: light.turn_on
    entity_id: light.leviton_dz6hd1bz_decora_600w_smart_dimmer_level_57_0
#
#Turn Theater Lights on when enter through basement door
#
- alias: Turn Theater Lights on when enter through basement door
  trigger:
  - entity_id: binary_sensor.basement_door
    platform: state
    from: closed
    to: open
  - entity_id: sensor.home_alarm_keypad
    platform: state
    from: Arm Away
    to: Entry Delay in Progress
  condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
    service: homeassistant.turn_on
    entity_id: light.leviton_dz6hd1bz_decora_600w_smart_dimmer_level_36_0

What am I missing? With what’s there, shouldn’t it only turn on the Living room lights when the front door is open and the basement lights when the basement door is open?

You trigger both automations with your alarm code

  - entity_id: sensor.home_alarm_keypad
    platform: state
    from: Arm Away
    to: Entry Delay in Progress

There is no condition to check where you came in.
Also I think the automation in the middle does not trigger if the transition is from “arm away” to “entry delay…” in your component? One way to fix it would be to drop “from:…” and trigger when it goes to disarmed. But then this automation would run the action where ever you disarm the alarm.

I take it you want the light on when the door is open regardless of the alarm status? Just remove the alarm triggers.

Correct on the middle one - the ‘Turn Living Room Lights on when we come home FOB’ automation is for if the alarm is disarmed using a keyfob, in which case the alarm goes from ‘Arm Away’ to ‘Disarmed’ with no ‘Entry Delay in Progress’. I fiddled with it a bit and the way the data comes in from Invisalink, it goes from ‘Armed Away’ to ‘Entry Delay in Progress’ to ‘Disarmed’, so what I did for ‘simplicity’s sake’, to allow for it to work if a door was opened or a keyfob was used, I set up two separate automations. I suppose technically it could be just ‘to: disarmed’, but that’s a pretty significant delay - having it turn the light on when it transitions to ‘Entry Delay in Progress’ (when the door is opened) makes more sense overall, because that turns the lights on pretty much as soon as the door is opened, rather than after opening the door and tripping over a cat or two…

No, I really only want the light to come on if the sun is down and the alarm is armed. Technically, it could be set up to come on whenever the door is opened, but there isn’t really a reason on to do so… generally, the only reason to automate that is if we are away and come home at night.

Overall, it works as expected EXCEPT for turning the basement lights on too when entering through the front door.

Is there some way to check for where the entry was? I would have thought that having the ‘entity_id: binary_sensor.front_door’ and ‘entity_id: sensor.home_alarm_keypad’, that when the ‘binary_sensor.front_door’ goes from closed to open, and ‘sensor.home_alarm_keypad’ goes from ‘Arm Away’ to Entry Delay in Progress’, while sun.sun is ‘below_horizon’, it would trigger the action. But obviously, I’m ‘coding challenged’ lol.

Technically, it’s a minor thing that I could live with if needed - it accomplishes the main goal and if I need to go downstairs and turn the light off or pull HA up on my phone and turn it off, it’s not the end of the world (My wife is a different story lol), but it would be nice if it could be made to work the way I ‘envision’ it.

Well, move the alarm from trigger to condition? As said, having the alarm as trigger will trigger both of your automations as they are now. And you have the 3rd automation to turn on the light when alarm is actually disarmed.

Now your automation doesnt care if the alarm were on or off.

I think you may be getting your ‘or’ and ‘and’ confused.

triggers are all ‘or’. if you have two triggers, the automation will run as soon as either of the triggers happen. it doesn’t require both triggers to happen.

so in your first automation it will trigger when your alarm goes “to: Entry Delay in Progress” OR when the front door is opened (it doesn’t need both).

then in you last one it will trigger when your alarm goes “to: Entry Delay in Progress” OR when the basement door is opened (it doesn’t need both).

so in both situations you have the trigger as the alarm going to “entry delay…” so both automations will trigger.