I need a template to convert the incoming values (integer) into something meaningful for MQTT HVAC (string). It seems so simple yet I’m not succeeding.
The HVAC system’s operating mode is published as an integer value:
0=auto
1=heat
2=cool
4=off
FanMode is also published as an integer value:
0=auto
2=on
Both topics are published with retain=true so Home Assistant is assured of acquiring it upon startup. Nevertheless, it always reports the system is Off and the fan mode has no value. The only thing that displays and works correctly is the Target temperature.
Here’s what’s in configuration.yaml. The supplied list of modes (auto, heat, cool, off) do appear as selection options for Operation (a.k.a. “mode”). Using MQTTFX, I’ve confirmed the mode topic’s values is currently 1 (“Heat”) yet the UI always displays “Off”. Similarly, Fan Mode’s value is 0 so the UI should say Auto but it actually says nothing at all.
climate:
- platform: mqtt
name: "Thermostat"
optimistic: false
retain: false
qos: 0
payload_on: 1
payload_off: 0
modes:
- auto
- heat
- cool
- 'off'
mode_state_topic: "home/thermostat/temperaturemode"
mode_command_topic: "home/command/thermostat/temperaturemode"
mode_state_template: >-
{% if value == 0 %}
auto
{% elif value == 1 %}
heat
{% elif value == 2 %}
cool
{% elif value == 4 %}
'off'
{% endif %}
fan_modes:
- auto
- 'on'
fan_mode_state_topic: "home/thermostat/fancontrol"
fan_mode_command_topic: "home/command/thermostat/fancontrol"
fan_mode_state_template: >-
{% if value == 0 %}
auto
{% elif value == 2 %}
'on'
{% endif %}
current_temperature_topic: "home/thermostat/temperature"
min_temp: 17
max_temp: 28
temperature_state_topic: "home/thermostat/currentsetpoint"
temperature_command_topic: "home/command/thermostat/currentsetpoint"
hold_command_topic: "home/command/thermostat/mode"
hold_state_topic: "home/thermostat/mode"
hold_state_template: >-
{% if value == 2 %}
hold
{% else %}
'off'
{% endif %}
I looked through all of the config files in the Cookbook collection, searching for examples, but no one is using MQTT HVAC. The template tester indicates my templates are OK but apparently not.
Any clues to what I screwed up here?