NOTE
Update: 2019-10-27
This custom component is no longer maintained.
In Home Assistant version 0.96, the climate component’s architecture was modified (known as “Climate 1.0”) and this custom component has not been updated to work with it.
As of version 0.99, graphing was corrected for MQTT HVAC so I have decided to discontinue maintenance of this custom component.
To be clear, the revised MQTT HVAC component now renders the graph correctly but lacks the command_templates included in my custom component. If you require this functionality, I describe a simple workaround in this post.
Updated: 2019-06-18
The latest version of my enhanced MQTT HVAC component has been revised for use with Home Assistant 0.93+
I’ve created a version of MQTT HVAC (MQTT climate platform) with the following enhancements:
-
Supports monitoring the HVAC system’s current operating state ( activity_state_topic
status_state_topic). This permits the thermostat to report the current state of the HVAC system (its activity: heating/cooling/idle) as opposed to its operating mode (heat/cool/auto/off). This also lets the History Chart correctly show when the HVAC system is actively heating/cooling (green-shaded area in chart). -
Automatically sets the temperature step-size based on the unit system (metric = 0.5, imperial = 1.0). You can override this behavior by setting a desired step-size using the temp_step parameter. In the current release version (0.81) MQTT HVAC supports temp_step (but does not auto-configure itself based on the unit system). -
Convert mode with a template for publishing to MQTT (mode_command_template).
-
Convert fan_mode with a template for publishing to MQTT (fan_mode_command_template).
-
Convert hold with a template for publishing to MQTT (hold_command_template).
Here’s an example of how I have it configured for my thermostat.
climate:
- platform: my_mqtt
name: "Thermostat"
qos: 0
payload_on: 1
payload_off: 0
# ENHANCEMENT: Get actual HVAC status. Must map to 'heat'and 'cool'.
activity_state_topic: "home/thermostat/heatingstatus"
activity_state_template: >-
{% set values = { '1':'heat', '2':'cool', '4':'idle'} %}
{{ values[value] if value in values.keys() else 'idle'}}
modes:
- auto
- heat
- cool
- 'off'
mode_state_topic: "home/thermostat/temperaturemode"
mode_state_template: >-
{% set values = { '0':'auto', '1':'heat', '2':'cool', '4':'off'} %}
{{ values[value] if value in values.keys() else 'off' }}
mode_command_topic: "home/thermostat/temperaturemode/command"
# ENHANCEMENT: Convert mode for publishing to MQTT
mode_command_template: >-
{% set values = { 'auto':'0', 'heat':'1', 'cool':'2', 'off':'4'} %}
{{ values[value] if value in values.keys() else '4' }}
fan_modes:
- auto
- 'on'
fan_mode_state_topic: "home/thermostat/fancontrol"
fan_mode_state_template: >-
{% set values = { '0':'auto', '1':'on'} %}
{{ values[value] if value in values.keys() else 'auto' }}
fan_mode_command_topic: "home/thermostat/fancontrol/command"
# ENHANCEMENT: Convert fan_mode for publishing to MQTT.
fan_mode_command_template: >-
{% set values = { 'auto':'0', 'on':'1'} %}
{{ values[value] if value in values.keys() else '0' }}
current_temperature_topic: "home/thermostat/temperature"
min_temp: 17
max_temp: 28
temp_step: 0.5
temperature_state_topic: "home/thermostat/currentsetpoint"
temperature_command_topic: "home/thermostat/currentsetpoint/command"
hold_state_topic: "home/thermostat/mode"
hold_state_template: "{{ 'hold' if value == '2' else 'auto' }}"
hold_command_topic: "home/thermostat/mode/command"
# ENHANCEMENT: Convert hold for publishing to MQTT.
hold_command_template: "{{ '2' if value == 'hold' else '0' }}"
To have History Chart work correctly, you must convert activity_state_topic
's payloads into the key-words heat and cool (see activity_state_template in the example above). They are the only two key-words the chart knows how to represent with a shaded area (the key-words are hard-coded in the Lovelace UI). When the HVAC state is neither heating or cooling, I prefer to represent that state as ‘idle’ but it can also be ‘off’.
Here’s an example of the History Chart showing when my furnace was heating (the green-shaded areas). It just finished a heating cycle, raising the temperature from 21 to 21.5 and is now idle.
Installation Instructions
Create a new directory under custom_components called my_mqtt
(or choose something else other than mqtt
).
config/custom_components/my_mqtt
Copy the contents of this pastebin link into a new file called climate.py
.
config/custom_components/my_mqtt/climate.py
Create a new file in the same directory named manifest.json
. Paste the following text into the file and save it.
{
"domain": "my_mqtt",
"name": "My MQTT",
"documentation": "https://www.home-assistant.io/components/climate.mqtt/",
"dependencies": ["mqtt"],
"codeowners": [],
"requirements": []
}
In configuration.yaml
, find your existing MQTT climate entity and replace:
platform: mqtt
with:
platform: my_mqtt
The next step is needed ONLY if your climate entity uses the unique_id
option. If it doesn’t then simply run Config Check and restart Home Assistant. If it does then perform the following additional steps:
- Stop Home Assistant.
- Save a copy of
config/.storage/core.entity_registry
to serve as a backup. - Use a text editor to modify the following file:
config/.storage/core.entity_registry
- Find your climate entity and replace: “platform”: “mqtt” with “platform”: “my_mqtt”
- Save the file and restart Home Assistant.