Jinja2 Templating Issue

Hello, I’ve been trying to integrate checking if the time is over 8pm into my template sensor but I can’t seem to crack it. This is my example:

        {% if state_attr('sensor.io_bearded_dragon_raw_night', 'max_value')|float < 40 %}
          {% if state_attr('sensor.time', 'time')|float <= 20:00  %}
          Temperature | Fault
          {% else %}
          Night Protection | OK
          {% endif %}
        {% else %}
          Healthy | OK
        {% endif %}

If the time is after 8pm & the temperature is low display “Night Protection | OK”
If the time isn’t after 8pm & the temperature is low display “Temperature | Fault”
If neither of these arguments are true than display “Healthy | OK”

I’ve looked it up & have seen that its possible if I integrate a “for” in there but I’m not sure how I would go about doing that as I don’t need to count anything.

I hope that made enough sense, Any help would be great! :slight_smile:

{% if state_attr('sensor.io_bearded_dragon_raw_night', 'max_value')|float < 40 %}
  {% if states('sensor.time').split(':')[0] | int < 20  %}
    Temperature | Fault
  {% else %}
    Night Protection | OK
  {% endif %}
{% else %}
  Healthy | OK
{% endif %}

or

{% if state_attr('sensor.io_bearded_dragon_raw_night', 'max_value')|float < 40 %}
  {% if now().hour < 20  %}
    Temperature | Fault
  {% else %}
    Night Protection | OK
  {% endif %}
{% else %}
  Healthy | OK
{% endif %}
2 Likes