Presence detection, sunset lights

this is what I have.

hide_entity: true  
trigger:
  platform: state
  entity_id: device_tracker.moes_cell, device_tracker.donnas_s7
  from: 'home'
condition:
  condition: sun
  after: sunset
action:
  service: light.turn_on
  entity_id: light.outside_lights

I’m trying to get my outside lights to turn on if one or more devices are not home after sunset. Would someone please point me in the right direction?

Try this:

trigger:
  platform: sun
  event: sunset
condition: and
  conditions:
    - condition: state
      entity_id: 'device_tracker.moes_cell'
      state: 'not home'
    - condition: state
      entity_id: 'device_tracker.donnas_s7'
      state: 'not home'
action:
  service: light.turn_on
  entity_id: light.outside_lights

Sun sunset is the trigger. The “and” condition will keep it the lights on until both devices are home.

I have not tested this as I do not have a light outside.

Thank you MediaCowboy, so the “and” instead of “or”?

I read your automation as it will trigger at sunset. The the condition will be met only if both device trackers are not home. I think Or would work better for the OPs request. Or would return true if on or both are not home.

Conditions won’t keep anything on. Conditions are only checked once when the trigger is met. In this case, sunset is a singular event so the trigger only happens once and if both devices left after sunset the light wouldn’t turn on.

@Moe247365 if you want to have a light on anytime someone comes home after sunset I would create three triggers. One for sunset so the light always triggers at sunset. Then one for each of the devices leaving home so it will turn on the light when either person leaves home.

I think there’s a mistake in the condition block:

condition: and
  conditions:
    - condition: state
      entity_id: 'device_tracker.moes_cell'
      state: 'not home'
    - condition: state
      entity_id: 'device_tracker.donnas_s7'
      state: 'not home'

should be

condition: 
  condition: and
  conditions:
    - condition: state
      entity_id: 'device_tracker.moes_cell'
      state: 'not home'
    - condition: state
      entity_id: 'device_tracker.donnas_s7'
      state: 'not home'

or even simpler (as conditions to my understanding must all pass)

condition:
  - condition: state
    entity_id: 'device_tracker.moes_cell'
    state: 'not home'
  - condition: state
    entity_id: 'device_tracker.donnas_s7'
    state: 'not home'

Hth

Yes “or” is better and sorry I meant it will turn on the light if neither device is home. Sorry one should not post and drink.

This is what I ended doing. I might use the “add condition” to only turn the lights on if someone is not home, but for now this works.

trigger:
- platform: state
entity_id: device_tracker.moes_cell
from: ‘home’
to: ‘not_home’
- platform: state
entity_id: device_tracker.donnas_s7
from: ‘home’
to: ‘not_home’
- platform: sun
event: sunset
condition:
condition: sun
after: sunset
action:
- service: light.turn_on
entity_id: light.outside_lights

Everyone thank you! this is what I ultimately ended up doing.

  • alias: Turn On Outside Lights On When Moe Is Not Home
    hide_entity: true
    trigger:
    - platform: state
    entity_id: device_tracker.moes_cell
    from: ‘home’
    to: ‘not_home’
    - platform: sun
    event: sunset
    condition:
    condition: and
    conditions:
    - condition: sun
    after: sunset
    - condition: state
    entity_id: ‘device_tracker.moes_cell’
    state: ‘not_home’
    action:
    - service: light.turn_on
    entity_id: light.outside_lights
  • alias: Turn On Outside Lights On When Donna Is Not Home
    hide_entity: true
    trigger:
    - platform: state
    entity_id: device_tracker.donnas_s7
    from: ‘home’
    to: ‘not_home’
    - platform: sun
    event: sunset
    condition:
    condition: and
    conditions:
    - condition: sun
    after: sunset
    - condition: state
    entity_id: ‘device_tracker.donnas_s7’
    state: ‘not_home’
    action:
    - service: light.turn_on
    entity_id: light.outside_lights