Problem with template

Have set up the following sensor. Now it is 0:14 and i still see Day as the sensor state. Where could i have gone wrong?

  - platform: template
    sensors:
       day_night:
         friendly_name: 'День и ночь'
         value_template: >-
             {%- if now().hour > 20 and now().hour < 24 %}
                 Evening
             {%  elif now().hour > 0 and now().hour < 7 %}
                 Night
             {% else %}
                 Day
             {%- endif %}

Try this:

{% elif now().hour >= 0 and now().hour < 7 %}

You might want to do the same for the evening condition:

{%- if now().hour >= 20 and now().hour < 24 %}

Yes thank you! That has done the trick!

1 Like