Hi everyone,
I’m creating a template sensor that compares the actual time with 4 input_datetime helpers and changes accordingly.
When I make it simple with just the first condition it works. When I add all the conditions I need the output is always “Pasto 4”, meaning that it always skip to the final {% else %}.
I guess there’s some typo but I can’t find it.
Here’s the new template sensor:
- name: prossimo_orario_cibo_gatti_new
state: >
{% if now().timestamp() < (state_attr('input_datetime.pasto_gatti_1', 'timestamp')) %}
Pasto 1
{% elif now().timestamp() > (state_attr('input_datetime.pasto_gatti_1', 'timestamp'))
and now().timestamp() < (state_attr('input_datetime.pasto_gatti_2', 'timestamp')) %}
Pasto 2
{% elif now().timestamp() > (state_attr('input_datetime.pasto_gatti_2', 'timestamp'))
and now().timestamp() < (state_attr('input_datetime.pasto_gatti_3', 'timestamp')) %}
Pasto 3
{% else %}
Pasto 4
{% endif %}
Can someone help me?
Thank you!