Issue with template sensor and sun.sun

Hi all,

I’ve made a template for sunstates. It was working since a few days/week before, but it doesn’t work anymore.
it seems that when sun set, all is ok, but when sun rise I have an unknown value in history, and the value in template stay the same than when the sun set.
(before I was using the above_horizon states, now I’ve try with the elevation, but there is no change)

here is my code:

>   tmpl_sunstate:
>     entity_id: template.tmpl_sunstate
>     friendly_name_template: >
>       {% if state_attr('sun.sun','elevation') | float > 0.1 %}
>         Le soleil se couchera à
>       {% else %}
>         Le soleil se lèvera à
>       {% endif %}
>     value_template: >
>       {% if state_attr('sun.sun','elevation') | float > 0.1 %}
>         {{as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom('%H:%M', true)}}
>       {% else %}
>         {{as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom('%H:%M', true)}}
>       {% endif %}
>     icon_template: >
>       {% if state_attr('sun.sun','elevation') | float > 0.1 %}
>         mdi:weather-sunset-down
>       {% else %}
>         mdi:weather-sunset-up
>       {% endif %}

have you any idea on what’s wrong ?

that’s probably because since 0.81 there is a breaking change in refreshing entities in templates

Template sensors will no longer auto update if we can’t find relevant entities in the template. You’ll want to review your template sensors and consider adding relevant entity_id entries or use the new homeassistant.update_entity service.

Try to change:

   tmpl_sunstate:
     entity_id: template.tmpl_sunstate

to:

   tmpl_sunstate:
     entity_id: sun.sun