[mqtt hvac]command payload template

I found a way around to have multiple thermostats with a single set of automatons (not one set per thermostat).

configuration.yaml

climate:
  - platform: mqtt
    name: Bedroom heating
    device:
      identifiers: '00:1A:22:0C:XX:XX'
    modes:
      - "off"
      - "auto"
      - "heat"
    precision: 0.5
    min_temp: 4.5
    max_temp: 29.5
    temp_step: 0.5
    mode_command_topic: "/eq3mqtt/00:1A:22:0C:XX:XX/trv_mode"
    temperature_command_topic: "/eq3mqtt/00:1A:22:0C:XX:XX/trv_temp"
    mode_state_topic: "/eq3mqtt/00:1A:22:0C:XX:XX/status"
    mode_state_template: >-
      {% if value_json.mode == "manual" %}
        {% if value_json.temp == "4.5" %}
          off
        {% else %}
          heat
        {% endif %}
      {% elif value_json.mode == "auto" %}
        auto
      {% endif %}
    temperature_state_topic: "/eq3mqtt/00:1A:22:0C:XX:XX/status"
    temperature_state_template: "{{value_json.temp}}"
    current_temperature_topic: "/eq3mqtt/00:1A:22:0C:XX:XX/status"
    current_temperature_template: "{{value_json.temp}}"
    json_attributes_topic: "/eq3mqtt/00:1A:22:0C:XX:XX/status"
    json_attributes_template: "{{ {'mac':value_json.trv, 'valve':value_json.valve, 'boost':value_json.boost,   'window':value_json.window, 'battery':value_json.battery} | tojson}}"
    away_mode_state_topic: "/eq3mqtt/00:1A:22:0C:XX:XX/status"
    away_mode_state_template: >-
      {% if value_json.mode == "holiday" %}
        on
      {% else %}
        off
      {% endif %}

as you see I post and listen everything related to a given thermostat in its own topics /eq3mqtt/<mac address>/...

Then the automatisation for temperature becomes:

- alias: eq3mqtt_Temperature_Helper
  description: ''
  trigger:
  - platform: mqtt
    topic: /eq3mqtt/+/trv_temp
  condition: []
  action:
    service: mqtt.publish
    data_template:
      payload: >
        {% if trigger.payload == 4.5 %} {{trigger.topic.split('/')[2]}} off 
        {% else %}  {{trigger.topic.split('/')[2]}} settemp {{trigger.payload}}
        {% endif %}
      topic: /eq3mqtt/radin/trv

Notice the wildcard to listen to all topics of all sensors, later I extract the MAC address from the topic that actually triggered the automation.

And the automation for modes (same trick as the temp automation):

- alias: eq3mqtt_Mode_Helper
  description: ''
  trigger:
  - platform: mqtt
    topic: /eq3mqtt/+/trv_mode
  condition: []
  action:
    service: mqtt.publish
    data_template:
      payload: >
        {% if trigger.payload == "heat" %} {{trigger.topic.split('/')[2]}} manual
        {% else %} {{trigger.topic.split('/')[2]}} {{trigger.payload}}
        {% endif %}
      topic: /eq3mqtt/radin/trv

But now it is needed a kind of “forwarder” between the generic topic of the esp32_mqtt_eq3 and the individual topics of each thermostat:

- alias: eq3mqtt_status_proxy
  trigger:
  - platform: mqtt
    topic: "/eq3mqtt/radout/status"
  action:
    service: mqtt.publish
    data_template:
      topic: "/eq3mqtt/{{ trigger.payload_json.trv }}/status"
      payload: "{{ trigger.payload_json | tojson }}"

Here I extract the mac address from the json response.

For pulling the status of the thermostats, in case they are changed manually, I found that it is better to do it separately otherwise the ESP32 misses some messages and the thermostats are not updated.
I pull my different thermostats at different second every 2 minutes. (Not sure if it is too much and will affect the battery or not, I will see)

- alias: Pulling_Thermostat_Bedroom
  description: ''
  trigger:
  - platform: homeassistant
    event: start
  - platform: time_pattern
    minutes: /2
    seconds: 15
  condition: []
  action:
  - service: mqtt.publish
    data_template:
      payload: "00:1A:22:0C:XX:XX unlock"
      topic: /eq3mqtt/radin/trv

I hope this helps others to add multiple thermostats :slight_smile: