Automating - turning on the lights when arriving home but also turning off the light when bedroom occupency is on

So I have a couple of automations that are conflicting and not working together. I live alone so I don’t have to worry about SO.

I’m trying to do:

A) When home, after sunset turn on all_lights group.
B) When arriving home, after sunset, unlock the front door, turn on all_lights group.
C) After sunset, If bedroom sensor is occupied after 5 minutes turn off all_lights group.

arriveHome:

alias: arriveHome
description: Arrive Home
trigger:
  - platform: zone
    entity_id: person.me
    zone: zone.home
    event: enter
condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
action:
  - service: lock.unlock
    data: {}
    target:
      entity_id: lock.front_door
  - service: switch.turn_on
     data: {}
        target:
        entity_id: switch.alllights
 mode: single

lightcontrol:

alias: lights-control
description: Lights Control
trigger:
  - platform: time_pattern
    minutes: /5
condition: []
action:
  - choose:
      - conditions:
          - condition: sun
            after: sunrise
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id: switch.alllights
      - conditions:
          - condition: state
            entity_id: binary_sensor.sleepnumber_master_bedroom_aram_is_in_bed
            state: "off"
          - condition: sun
            after: sunset
            after_offset: "-00:30:00"
            before: sunset
            before_offset: "00:15:00"
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.alllights
    default: []
mode: single

turn off lights:

alias: Turn off lights when in Bed
description: ""
trigger: []
condition:
  - condition: state
    entity_id: binary_sensor.sleepnumber_master_bedroom_aram_is_in_bed
    state: "on"
    for:
      hours: 0
      minutes: 5
      seconds: 0
    attribute: device_class
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.alllights
mode: single

Any help in the conflict between A&C or general improvements would be appreciated.

Unless I’m missing something I don’t see a conflict between a and C.

I doubt you can both enter a zone and go to bed at the same time. Well, unless of course the zone is your bedroom. :wink:

Maybe you can explain the conflict better.

What I’m running into is that after sunrise when the bedroom sensor is not closed, the lights turn off after about 5 minutes no matter what.

I use timer helper for this kind of automation when I want ie. to turn off light after
some period of inactivity.
This works every time without an issue. I used before automations like you posted here but for me this didn’t work always as expected.

I just noticed that I misread the automation for c.

there is no trigger. Only a condition. I misread the condition as being the trigger.

so the automation should never start and the actions will never run. that automation is moot and superfluous.

it’s automation b that is triggering the lights to turn off at about 5 minutes after sunrise. That’s the one that needs reworked.

typically you shouldn’t use time pattern triggers but a regular trigger instead and then use choose/conditions to perform the desired actions.

I’m not sure what you are trying to accomplish with the sunrise section of automation b since you never listed sunrise in your list of requirements.

Yup, you’re right – I had removed the trigger to stop it from running and forgot that when I posted it.

The issue that I was running into is that sometimes I go to bed very early – before sunset and I’d like to either prevent the lights from coming on at sunset or to turn them off after a couple of minutes. I couldn’t figure out a trigger.

I have re-worked and broken up the larger automation into two smaller ones and will report back if that worked. Thank you.