Lights on bu sun angle - nice story

Last week we were watching TV and my girl friend got up from the coach and wanted to switch on the lights. And exactly at that moment Home Assistant switched on the lights in the room… we both started laughing.

In case you are wondering the lights turn on when the sun gets below 3.5 degrees. Maybe I should factor in the amount of clouds and switch on earlier depending on how cloudy it is.

I copied this from somewhere on the forum

binary_sensor:  
  - platform: template
    sensors:
      virtual_dark:
        friendly_name: "Virtually Dark"
        delay_on:
          seconds: 60
        delay_off:
          seconds: 60
        value_template: >
          {% if ( (states.sun.sun.attributes.elevation | int < 10) and (states.sensor.dark_sky_cloud_coverage.state | int > 30)) %}true
          {% elif ( (states.sun.sun.attributes.elevation | int < 15) and (states.sensor.dark_sky_cloud_coverage.state | int > 45)) %}true
          {% elif ( (states.sun.sun.attributes.elevation | int < 20) and (states.sensor.dark_sky_cloud_coverage.state | int > 70)) %}true
          {% elif (states.sensor.dark_sky_cloud_coverage.state | int > 90) %}true
          {% else %}false
          {% endif %}

which works most of the time.