Simple if template to test A/C current temperature

Good Morning,

I was wondering if someone can help me with this if template. I am getting inconsistent results when I use developer tools.

This trigger defines the A/C conditions before arrival

sensor:

  - name: "Cool When The Livingroom is Over 75 degrees"

    state: >
          {% if states('states.climate.living_room.attributes.current_temperature')| float >= 75 %}

          cool

          {% else %}

          off

          {% endif %}

      - name: "Heat When The Livingroom is under 60 degrees"

        state: >

          {% if states('states.climate.living_room.attributes.current_temperature')| float <=60 %}

          heat

          {% else %}

          off

          {% endif %}

This is my first if template and I also new to templates as you can tell.

Thanks,

Welcome to the wild world of templates! :slight_smile:

You kind of combined two different methods of retrieving attribute data… so let’s just stick with the best one for this use:

sensor:
  - name: "Cool When The Livingroom is Over 75 degrees"
    state: >
      {% if state_attr('climate.living_room', 'current_temperature')| float(0) >= 75 %}
      cool
      {% else %}
      off
      {% endif %}
  - name: "Heat When The Livingroom is under 60 degrees"
    state: >
      {% if state_attr('climate.living_room', 'current_temperature')| float(0) <=60 %}
      heat
      {% else %}
      off
      {% endif %}

Also, note that the float filter needs a default value in case your climate entities’ are unavailable or unknown.

1 Like

Thank you!

I will give it a try as soon as I get home.

Have a great day.

Hello,

I just tested it and it working as expected.

Thank you!

1 Like