MQTT + Lovelace climate card formatting for pool heater

I’m working on setting up the Lovelace climate card for controlling my pool heater using the MQTT HVAC integration, and it’s mostly working great. The current temperature and temperature setpoint show up fine, however the status (heat/off) is not showing up or updating when I turn the heat on and off.

I think (but still very new–so could definitely be wrong!) this might be because of the way my pool controller formats its MQTT messages, which look like this:

{
  "heatMode": {
    "val": 0,
    "name": "off",
    "desc": "Off"
  }
}

when the heat is off, or:

{
  "heatMode": {
    "val": 1,
    "name": "heater",
    "desc": "Heater"
  }
}

when the heat is on (this comes from the topic easytouch2-8/state/temps/bodies/1/pool/heatMode). I think if the system was just reporting “1” or “0” or “heat” or “off”, this might be easy? but since I’m getting three values, maybe I need to parse them up?

My thinking was I could just set up my configuration.yaml file to read the pool heater state directly:

    mode_state_topic: easytouch2-8/state/temps/bodies/1/pool/heatMode
    mode_state_template: >-
      {% if value_json['heatMode']['val'] == "0" %}
        off
      {% if value_json['heatMode']['val'] == "1" %}
        heat
      {% endif %}

but that doesn’t seem to do what I’d like. Am I missing something in how to format this, or is there another way to get at the heater status in Home Assistant?

Thank you.

    mode_state_template: >-
      {% if value_json['heatMode']['val'] == 0 %}
        off
      {% if value_json['heatMode']['val'] == 1 %}
        heat
      {% endif %}

Thank you Tom! I can confirm your simple solution worked perfectly for my problem, and my Lovelace thermostat heat icon now lights up when I turn on the pool heater.

edit for anyone with a similar problem that stumbles on this: I changed my 2nd if to an elif, which makes sense since I’m looping/terminating with an endif. Here’s what my code looks like:

mode_state_template: >-
  {% if value_json['heatMode']['val'] == 0 %}
    off
  {% elif value_json['heatMode']['val'] == 1 %}
    heat
  {% endif %}
1 Like