Newb here... I can't see what I've done wrong

I’ve successfully set up most of my automations with a little help from googling, but I just can’t see where I’ve gone wrong with this one.

It never triggers even if all three of us are at home.
When I test the or condition for the the phones it says “Condition did not pass”?

alias: Livingroom light on at sunset
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: 0
condition:
  - condition: or
    conditions:
      - condition: device
        device_id: 0edb41ad04cb7cd41b93483771b101cc
        domain: device_tracker
        entity_id: device_tracker.mark_s_phone
        type: is_home
      - condition: device
        device_id: e161a47fd92765c634ac3e3bf1634aee
        domain: device_tracker
        entity_id: device_tracker.sophie_s_phone
        type: is_home
      - condition: device
        device_id: ac978308336385a8099fb45987b170a2
        domain: device_tracker
        entity_id: device_tracker.summer_s_phone
        type: is_home
action:
  - type: turn_on
    device_id: 9331ec1e4a6fda4d3d87fa418fb4880d
    entity_id: light.livingroom_light
    domain: light
mode: single

Check in Developer Tools → State and see if those entities show home.

Your condition could be a numeric condition that zone.home is above 0.

1 Like

Yes, it shows we are all at home.

I think this should be right?

alias: Livingroom light on at sunset
description: ""
trigger:
  - platform: numeric_state
    entity_id: zone.home
    attribute: persons
    above: 0
action:
  - type: turn_on
    device_id: 9331ec1e4a6fda4d3d87fa418fb4880d
    entity_id: light.livingroom_light
    domain: light
mode: single
condition:
  - condition: sun
    after: sunset
  - condition: device
    type: is_off
    device_id: 9331ec1e4a6fda4d3d87fa418fb4880d
    entity_id: light.livingroom_light
    domain: light

Because you trigger on zone count then you might get home lets say at noon, and then the lights wont turn on when it’s dark.

Just replace the condition you had in the previous post with numeric on zone above 0.

Please tell me this is better?

alias: Livingroom light on at sunset
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: 0
condition:
  - condition: numeric_state
    entity_id: zone.home
    attribute: persons
    above: 0
action:
  - type: turn_on
    device_id: 9331ec1e4a6fda4d3d87fa418fb4880d
    entity_id: light.livingroom_light
    domain: light
mode: single
1 Like

Remove this line

The rest looks fine

2 Likes

Thank you for this!

You probably want to trigger off both sunset and people coming home — then check both in the conditions section.

At the moment, if you go out and return home after sunset, the light won’t come on — your trigger only fires once, at sunset. How I’d write it (with category prefix in the alias for easier organisation, random unique ID, slightly more reliable sunset detection, and service call rather than the messy device notation):

alias: Lights - living room light on at sunset
id: 843cda44-87a3-40c5-a257-4bc6aaef54de
trigger:
  - platform: state
    entity_id: sun.sun
    from: 'above_horizon'
    to: 'below_horizon'
  - platform: numeric_state
    entity_id: zone.home
    above: 0
condition:
  - condition: numeric_state
    entity_id: zone.home
    above: 0
  - condition: state
    entity_id: sun.sun
    state: 'below_horizon'
action:
  - service: light.turn_on
    entity_id: light.livingroom_light

(sorry @Tinkerer — I wrote the initial response on a phone and padded it out in this edit on the laptop at the same time as you!)

3 Likes

Something like:

alias: Livingroom light on at sunset
description: ""
trigger:
  - platform: state
    entity_id: sun.sun
    to: 'below_horizon'
  - platform: numeric_state
    entity_id: zone.home
    above: 0
condition:
  - condition: state
    entity_id: sun.sun
    state: 'below_horizon'
  - condition: numeric_state
    entity_id: zone.home
    above: 0
action:
  - type: turn_on
    device_id: 9331ec1e4a6fda4d3d87fa418fb4880d
    entity_id: light.livingroom_light
    domain: light
mode: single
2 Likes

Thanks for catching that.

Keep in mind this will always turn on the light when you get home after sunset.
There might be times when you don’t want this, you know straight to beds days.
Perhaps another condition should be added before midnight or something?

1 Like