I have tried this in my configuration and I can’t get my light to switch from on to off and the other way around.
I do not have the homeassistant start in this code but I have implemented that. So the light goes on when I do restart. But the trigger for the elevation does not work. Any ideas?
I think my elevation is around 40. My house so to speak.
automation:
alias: “Exterior Lighting on when dark outside”
trigger:
platform: numeric_state
entity_id: sun.sun
value_template: “{{ state.attributes.elevation }}”
# Can be a positive or negative number
below: -4.0
action:
service: switch.turn_on
entity_id: switch.exterior_lighting
Not sure (please use </> or [code] tags to format your code so we can check indenting) but looking at it from another angle (pun!), the sun moves at 15° an hour so -4° is 16 minutes after sunset. Maybe try an automation based on sunset time and time offset? https://home-assistant.io/cookbook/automation_sun/
there is an example on that linked page that matches your approach:
- alias: 'Turn a few lights on when the sun gets dim'
trigger:
platform: numeric_state
entity_id: sun.sun
value_template: '{{ state.attributes.elevation }}'
below: 3.5
action:
service: scene.turn_on
entity_id: scene.background_lights
So at least it should work your way. Did you check, that configuration is properly loaded and the automation is available and enabled?
The last thing i would want to have is a check on restart if the light should be on or off. I dont think these automations will check that.
So they will probably leave the switch as it is.