"Dark Out" kind of rule or event?

Hi all- I have mostly been doing basic stuff, have a few z-wave switches among other things.

I have automations that turn on some inside lights at sunset (under cabinet, foyer…).

What I would really like to do is have it turn them on earlier if the expected light level outside is low. Think about an overcast day, where not much ambient light is coming into the house.

How would I get started with something like this?

Thanks,
-jamie

you got to find the right sensor or combo of sensors

Use the dark sky cloud cover…

- platform: template
  sensors:
    indoor_lights_auto_on:
      friendly_name: 'Indoor Lights Auto On'
      value_template: >-
          {%- if is_state("input_boolean.bedtime","off") and is_state("group.household","home") -%}
            {%- if (states.sun.sun.attributes.elevation | int < 10 ) -%}
              True
            {%- elif ( (states.sun.sun.attributes.elevation | int < 25) and (states.sensor.dark_sky_cloud_coverage.state | int > 70)) -%}
              True
            {%- elif (states.sensor.dark_sky_cloud_coverage.state | int > 95) -%}
              True
            {%- else -%}
              False
            {%- endif -%}
          {%- else -%}
            False
          {%- endif -%}

Thanks! I will give that a shot- sounds perfect. Also a nice example on the value_template which I haven’t tried yet

This is mine…

sensor:
  - platform: template
      sensors:
        dark_outside:
          value_template: >
          {% if (states.input_boolean.sunset_offset.state == 'on') %}true
          {% elif (states.sun.sun.attributes.elevation | int < 3) %}true
          {% elif ( (states.sun.sun.attributes.elevation | int < 4.5) and (states.sensor.dark_sky_cloud_coverage.state | int > 80)) %}true
          {% elif ( (states.sun.sun.attributes.elevation | int < 6.5) and (states.sensor.dark_sky_cloud_coverage.state | int > 85)) %}true
          {% elif (states.sensor.dark_sky_cloud_coverage.state | int > 90) %}true
          {% else %} false {% endif %}

Has been really reliable :+1:

The input boolean goes on 35 minutes before sundown and goes off 35 minutes after sunrise.

3 Likes

What’s the reason for the boolean and using elevation under 3 degrees? They seem redundant.

The boolean means that it’s always classed as dark when it’s between dusk and dawn regardless of the other reasons, the others are basically for if it gets dark during the between dawn and dusk.

I don’t know why other people’s numbers are in the 20s, if it’s in the 20s here it’s proper daytime. Maybe different places in the world? No idea, but it works well here with those.

I got those values from setting a notification for every time we switched the lights on, that contained the value of those sensors. Kept a record for a fortnight or so, and then chucked them in to a template. Haven’t needed to manually switch the lights on since :+1:

3 Likes

Thank you for your template! Since Dark Sky is going away, I refactored this for my purposes utilizing the Weatherbit.io cloud coverage sensor.

binary_sensor template

platform: template
sensors:
  dark_outside:
    value_template: >
      {{ state_attr("sun.sun","elevation")|float < 3
      or (state_attr("sun.sun","elevation")|float < 4.5 and states("sensor.weatherbit_cloud_coverage")|float > 80)
      or (state_attr("sun.sun","elevation")|float < 6.5 and states("sensor.weatherbit_cloud_coverage")|float > 85)
      or (states("sensor.weatherbit_cloud_coverage")|float > 90) }}
2 Likes

I’ve created a sensor based on elevation and cloud coverage, which gives me a number which is used to check against the elevation of the sun to either turn on the lights (in the evening, below) or turn off in the morning (above), using a numerical input (between 0 and 6, steps 0.1, currently at 1.5, which seems to be the sweet spot for me)

    - name: darkness
        state: >
          {{ states('input_number.golden_hour') | float + 1.5 * 
              (states('sensor.openweathermap_cloud_coverage') | float / 100)}}