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, use 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 rather than conventional time because as the seasons change, the timing in which the automation runs will be 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 better automate their home.

Check out my other posts on Home Automation and other Smart Home technologies here!

If you're interested in solar energy, check out this blog with 7 neat facts I bet you didn't know about solar!