Brent Saltzman


Interested in all things technology with a passion for analog, design, audio, and anything that sparks creativity and imagination.


Home Assistant Automations based on Solar Elevation Angle

I use Home Assistant for all of my home automation and control needs. If you haven't heard of Home Assistant, it's pretty awesome and it supports a ton of stuff.

One of the neat things you can do on the automation side is control components based on the Sun. The example you will find from the Home Assistant documentation uses events sunrise and sunset with the option to give an offset as a trigger for an automation. This sounds perfect for dusk to dawn exterior lighting, right?

Well in the summer where we have longer days and the sun drops below the horizon and is officially set, it's still not quite dark enough outside and it's a waste of energy to turn on your exterior lighting.


HomeAssistant Sun Sensor Card

Home Assistant's Sun component does provide the solar elevation angle in degrees in the sensor card, would it be great to use this as our automation trigger? We can using a value_template!
Here's how I turn on my exterior lighting around my house when it truly gets dark outside:

automation:  
  alias: "Exterior Lighting on when it's dark outside"
  trigger:
    platform: numeric_state
    entity_id: sun.sun
    value_template: "{{ state.attributes.elevation }}"
    below: -4.0
  action:
    service: switch.turn_on
    entity_id: switch.exterior_lighting

This way our lights won't turn on earlier while there's still plenty of light out after sunset.

I love using solar position to automate lighting as opposed to using conventional time because as the seasons change, the timing in which the automation runs will happen around the same brightness outside no matter what time of year it is.

As Home Assistant is a community driven project, I submitted a pull request with this example to the official documentation. Hopefully this helps others help better automate their home.

Previous Post | Next Post