Binary sensor with sun elevation not updating

I am trying to make a simple binary sensor that indicates if the sun is low according to my preferences.

  - platform: template
        friendly_name: "Sun is low"
        entity_id: sensor.sun_is_low
        icon_template: "mdi:weather-sunny"
        value_template: '{{ state_attr("sun.sun", "elevation") | float < 6 }}'

When starting or restarting Home-Assistant, the binary-sensor holds the correct value.
However, when the sun elevation is changed so that the binary_sensor should toggle, nothing happens.

I literally sat in front of the dashboard waiting for the sun elevation to update and the binary sensor is not updating.

As it is suggested in this thread, I also tested with this code:

value_template: {{ states.sun.sun.attributes.elevation | float < 6 }}

What am I missing ?

The entity_id your sensor is relying on to tell it when to update is, ummm, itself :man_shrugging:

Try sun.sun instead.


What Marc said, or even leave out the entity id as the system should be able to work this out from the template alone.

Thanks for the swift analysis.
It works fine now.
That also explains why none of my other sensors were working !

1 Like