Lights On When Arriving Home

I’ve recently moved to a new home and taken the opportunity to start from scratch and, hopefully, not repeat some of my former mistakes.

I’m stuck at what I believe should be a simple automation. I’d like my front porch light to come on as I approach my home if the sun is down.

I’ve created two zones, “Home” and “Home Wide”.

“Home” is basically just my street and “Home Wide” is the whole of my small town.

My reasoning is that if I’m only going a few blocks, walking the dog for example, then I want to look for a state change in my trackers (Android phone and Tile) from “Home Wide” to “Home”.

If I’ve been further away, then I want to look for a change from “Away” to" Home Wide".

The light never comes on.

My trackers are working properly, they indicate the transition from “Home” to “Home Wide” to “Home” as I walk the dog, but the automation never triggers.

Here’s my yaml:

alias: Lights On Arrive Home
description: ""
triggers:
  - trigger: state
    entity_id:
      - person.pitcritter
    to:
      - Home Wide
    from:
      - not_home
  - trigger: state
    entity_id:
      - person.pitcritter
    from:
      - Home Wide
    to:
      - home
conditions:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
    enabled: true
actions:
  - action: light.turn_on
    metadata: {}
    target:
      entity_id: light.front_stairs
    data: {}
mode: single

What am I missing?

Please edit your post and format your pasted config correctly for the forum. Use the </> button. Or do this: https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

Thank you. That’s far more readable.

I have to speculate a little bit. :innocent:

The triggers look ok and the automation itself should trigger. Have you verified the traces? If the automation has really never run, I suggest that you delete it and start from scratch.

The entity “sun.sun” may not be a good one. It doesn’t display for me in my sun entities and can only be addressed in YAML. Things might be easier, if you set up the automation through the UI and use “after sunset” instead.

Thank you.

I’ll try that.

Conditions might be an issue, traces are the best way.

One thing I discovered is that elevation was more valuable than the calculated above/below horizon. I had to play around with the value but I found I wanted the lights to come on when the sun was slightly below the horizon and off when it was slightly above. Also numbers feel better to me when building an automation.