Using sun elevation AND cloudiness to trigger interior and exterior lights

The {{ state_attr('sun.sun', 'elevation') }} is doing the job, but on cloudy days this value needs adjustments. {{ states.sensor.yr_cloudiness.state }} (now it’s 80,6% cloudiness).

I can use a sensor to measure the light, but I’d rather put cloudiness into account in this matter, and that is way more fun :smiley:.

How can I tweak the above: '-4.0' value via a formula/template?

This is what I want:
IF cloudy
THEN change the value of elevation to fire the trigger earlier
…since it’s darker when it’s cloudy

- platform: numeric_state
  entity_id: sun.sun
  value_template: '{{ state.attributes.elevation }}'
  above: '-4.0'

And way less accurate.

Clouds can reflect light, not just block it.

But if that is what you want, what is your cloud sensor entity_id?

Sure, but not when the sun elevation is close to the horizon. My experience, living at 60 degrees North, is that it´s darker when the sun sets and it’s cloudy, than if there are no clouds.


Cloudiness entity_id: sensor.yr_cloudiness, which now returns 96.1. It was more clouds earlier with value 82.6.

You will probably have to tweak the values but this should give you the general idea:

- platform: template
      {% if states('sensor.yr_cloudiness')|float < 82.6 %} 
        {{ state_attr('sun.sun', 'elevation')|float > -8 }}
      {% else %}
        {{ state_attr('sun.sun', 'elevation')|float > -4 }}
      {% endif %}
1 Like

Thank you, @tom_l.

So if I get this right:
IF cloudiness is less than 82.6 AND sun elevation is more than -8 THEN true
IF sun elevation is more than -4 THEN return true


Close enough.