Automate a Light Based on Sunset and Cloudiness

I already have an automation that turns on a light a set time before sunset. It seems to work but I’d like to modify it to compensate for cloudy evenings. On cloudy days, I wanted the light to come on sooner but I couldn’t figure out how to do it efficiently so I just compensated by adjusting the time to trigger the light sooner. Obviously, Home Assistant has the Sun integration but I’ve also installed the OpenWeatherMap integration. So, I have a couple I can work with. Below is the current working automation. Feel free to suggest improvements for it as well as helping to solve the aforementioned issue.

  alias: Turn on Sink Light - Before Sunset
  description: Turns on the light over the sink prior to sunset.
  trigger:
  - platform: sun
    event: sunset
    offset: -00:60:00
  condition:
  - condition: state
    entity_id: light.kitchen_sink_light
    state: 'off'
  action:
  - service: light.turn_on
    data:
      brightness_pct: 10
      entity_id: light.kitchen_sink_light
    entity_id: light.kitchen_sink_light
  mode: single

I’m, assuming I would have to add another trigger to read data from something like: sensor.openweathermap_cloud_coverage

1 Like

If you search the forum you will see this has been tried before and it is a poor idea.

Sun at a low angle reflecting off the clouds can be very bright.

Do yourself a favour and buy a cheap Lux meter. If you are into DIY a BH1750 and an ESP8266 running ESPHome can cost less than $15, is extremely reliable and integrates perfectly with Home Assistant.

Here are a couple of suggestions:

The first just calculates if it’s subjectively “dark” by measuring the suns angle and cloud cover:

sensor:
  - platform: template
    sensors:
      dark_outside:
        friendly_name: It Is Dark Outside
        value_template: >
          {% if (state_attr('sun.sun', 'elevation') | int < -2) %}
            true
          {% elif (state_attr('sun.sun', 'elevation') | int < 1) and (states('sensor.dark_sky_cloud_coverage') | int > 80) %}
            true
          {% elif (state_attr('sun.sun', 'elevation') | int < 2) and (states('sensor.dark_sky_cloud_coverage') | int > 85) %}
            true
          {% elif (state_attr('sun.sun', 'elevation') | int < 3) and (states('sensor.dark_sky_cloud_coverage') | int > 95) %}
            true
          {% else %}
            false
          {% endif %}

the next is a custom integration:

3 Likes

I use this board to do the same. It comes with a built in LDR and runs ESPHome easily. Perfect for what you are hoping to achieve.

EPS8266 Witty Development Board