I have been sitting with this template far to long now… what am I doing wrong? Its just using sun.sun and sensor.time… it cannot be that complicated : )
- platform: template
sensors:
timeofday:
friendly_name: "Time of day"
value_template: >
{% if (states.sun.sun.attributes.elevation | float > -2.0) and (states.sun.sun.attributes.elevation | float < 4) and (states.sensor.time.state < 12:00)%}sunrise
{% elif (states.sun.sun.attributes.elevation | float > 4.0) and (states.sensor.time.state < 09:00)%}morning
{% elif (states.sun.sun.attributes.elevation | float > 4.0) and (states.sensor.time.state > 09:00) and (state.sensor.time.state < 19:00)%}day
{% elif (states.sun.sun.attributes.elevation | float > 4.0) and (states.sensor.time.state > 19:00)%}evening
{% elif (states.sun.sun.attributes.elevation | float > -2.0) and (states.sun.sun.attributes.elevation | float < 4) and (states.sensor.time.state > 12:00)%}sunset
{% else %}night
{% endif %}
Copy and paste your template in Dev Tools/templates and you will see what you get.
The problem are the states.sensor.time.state > 09:00
-> TypeError: ‘>’ not supported between instances of ‘str’ and ‘int’
Use now().strftime('%H') | int > 9 instead.