Enhanced version of MQTT HVAC (Climate platform) with proper History Chart

@flyboy
Replying to your post here because this thread is specifically about enhancing MQTT HVAC.

Thanks for making the enhancements!

My “update” is based on the discussion I started here:

In a nutshell, I want the thermostat’s history chart to show when the furnace is actively heating (or A/C is cooling) and not simply when it is in “heat mode” (which is what almost all of Home Assistant climate platforms currently do). To achieve this, the climate platform has to acquire the operating state which means, for MQTT HVAC, yet another MQTT topic (and template) dedicated to this purpose.

In this post I mentioned that I discovered someone is already working on a PR to add an “activity topic”. It wasn’t precisely what I had in mind but, after contacting the author, convinced him/her to employ a template to allow for greater flexibility (and also address a potential charting error if in auto mode).

The PR is still in the pipe but I just helped myself to the code and incorporated it into my custom_components/climate/mqtt_climate.py.

The only modification I made was to the name of the new topic. The PR’s version uses:

  • state_topic
  • state_template

IMHO, that’s inconsistent with how all other topic/templates are named. All others are in the form:

  • something_state_topic
  • something_state_template

The PR’s version lacks the something part. My version uses:

  • status_state_topic
  • status_state_template

Ideally it should be state instead of status but state_state_topic is damned confusing!

So my version contains the enhancement in the aforementioned PR by @definitio plus the following two lines (near line 46):

CONF_STATE_TOPIC = 'status_state_topic'
CONF_STATE_TEMPLATE = 'status_state_template'

It all ends up looking like this in configuration.yaml:

climate:
  - platform: mqtt_climate
    name: "Thermostat"
    optimistic: false
    retain: false
    qos: 0
    payload_on: 1
    payload_off: 0
    # Acquire HVAC operating status
    status_state_topic: "premise/home/thermostat/heatingstatus"
    status_state_template: >-
      {% set values = { '1':'heat', '2':'cool', '4':'idle'} %}
      {{ values[value] if value in values.keys() else 'idle' }}
    modes:
      - auto
      - heat
      - cool
      - 'off'
    # Acquire HVAC operating mode
    mode_state_topic: "premise/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: "premise/command/home/thermostat/temperaturemode"
    mode_command_template: >-
      {% set values = { 'auto':'0', 'heat':'1',  'cool':'2', 'off':'4'} %}
      {{ values[value] if value in values.keys() else '4' }}
    --- etc ---

Finally, here’s my version which is running well and producing no errors (in the log): mqtt_climate.py

I’m new to HA development, so I don’t know the best way to get these incorporated into a released version.

I’m a novice as well so I may be omitting a few steps but the general idea is you get a GitHub account, install git on your PC, use it to fork the MQTT HVAC platform to your repository, make all desired enhancements to this local copy (modifications are tracked by git), then submit a pull request to have your version incorporated into Home Assistant’s repo. There’s a vetting process to get your changes into the main repo and this podcast episode does a good job of explaining it.