Mode_state_template for mqtt json not working

Hi,

I’m trying to get a “climate” card working with mqtt, but I’m failing with the templates for the state and command modes.

This is what I have so far

  climate:
    name: "climate test"
    max_temp: 25
    min_temp: 15
    precision: 0.1
    temp_step: 0.5
    modes:
     - auto
     - heat
     - cool
     - 'off'
    mode_state_template: >-
      {% set values = { 'auto':'auto', 'day':'heat',  'night':'cool', 'off':'off'} %}
      {{ values[value] if value in values.keys() else 'off' }}
    mode_state_topic:  "ebusd/700/z1OPMode"
    value_template: "{{ value_json.opmode.value }}"
    mode_command_template: >-
      {% set values = { 'auto':'auto', 'day':'heat',  'night':'cool', 'off':'off'} %}
      {{ values[value] if value in values.keys() else 'auto' }}
    mode_command_topic: "ebusd/700/z1OpMode/set"
    temperature_state_topic: "ebusd/700/z1ActualRoomTempDesired"
    value_template: "{{ value_json.tempv.value }}"
    temperature_low_state_topic: "ebusd/700/z1NightTemp"
    value_template: "{{ value_json.tempv.value }}"
    temperature_high_state_topic: "ebusd/700/z1DayTemp"
    value_template: "{{ value_json.tempv.value }}"
    temperature_low_command_topic: "ebusd/700/z1NightTemp/set"
    temperature_high_command_topic: "ebusd/700/z1DayTemp/set"
    current_temperature_topic: "ebusd/700/z1ActualRoomTempDesired"
    value_template: "{{ value_json.tempv.value }}"

and the json looks like this

{
  "opmode": {
    "value": "day"
  }

the modes are : auto, day, night and off

Its correctly showing the temperature, so the template with " value_json.tempv.value" is apparently correct for the json of the temperature topic which looks like this

{
  "tempv": {
    "value": 20.5
  }
}

Its also sending the command correctly, but its just always sending “auto” because of the if statement, but it doesn’t default to “off” with the state template - which i find weird.

I tried to debug this in the Template simulator in the editor tools, but I seem to fail to grasp how this works, since I cannot copy/paste my yaml files there.

If been googling, searching and trying for hours…

Any help or guidance would be appreciated.

System Info:
Docker Home Assistant 2023.3.1 Frontend 20230302.0 - latest
Mosquitto
Ebusd

1 Like

Similar issues debugging thermostat templates…

now it’s partial working:


object_id: Vaillant01
name: Vaillant
max_temp: 28
min_temp: 15
precision: 0.1
temp_step: 0.5
action_topic: "ebusd/ctlv2/OpMode"
action_template: "{{ value_json.opmode.value }}"
modes:
  - auto
  - heat
  - cool
  - "off"
mode_state_template: >-
  {% set mode_values = { 'auto':'auto', 'day':'heat', 'night':'cool', 'aus':'off'} %}
  {{ mode_values[value_json.opmode.value] | default('off') }}
mode_state_topic: "ebusd/ctlv2/HwcOpMode"
mode_command_template: >-
  {% set values = { 'auto':'auto', 'heat':'day', 'cool':'night', 'off':'aus'} %}
  {{ values[value] | default('auto') }}
mode_command_topic: "ebusd/ctlv2/OpMode/set"
value_template: "{{ value_json.tempv.value }}"
temperature_state_topic: "ebusd/ctlv2/z1ActualRoomTempDesired"
temperature_low_state_topic: "ebusd/ctlv2/z1NightTemp"
temperature_high_state_topic: "ebusd/ctlv2/z1DayTemp"
temperature_low_command_topic: "ebusd/ctlv2/z1NightTemp/set"
temperature_high_command_topic: "ebusd/ctlv2/z1DayTemp/set"
current_temperature_topic: "ebusd/ctlv2/z1ActualRoomTempDesired"
current_temperature_template: "{{ value_json.tempv.value }}"

Option 2, adapted from: Ebus integration? - #93 by brozikcz

object_id: Vaillant01
name: Vaillant
max_temp: 28
min_temp: 15
temp_step: 0.5
modes:
 - auto
 - heat
 - cool
 - 'off'
mode_state_template: >-
  {% set values = { 'auto':'auto', 'day':'heat',  'night':'cool', 'off':'off'} %}
  {% set state = value_json["opmode"].value %}
  {{ values[state] if state in values.keys() else 'off' }}
mode_state_topic:  "ebusd/ctlv2/z1OpMode"
mode_command_template: >-
  {% set values = { 'auto':'auto', 'heat':'day',  'cool':'night', 'off':'off'} %}
  {{ values[value] if value in values.keys() else 'auto' }}
mode_command_topic: "ebusd/ctlv2/z1OpMode/set"
current_temperature_topic: "ebusd/ctlv2/z1ActualRoomTempDesired"
current_temperature_template: '{{value_json["tempv"].value}}'
temperature_state_topic: "ebusd/ctlv2/z1ActualRoomTempDesired"
temperature_state_template: '{{value_json["tempv"].value}}'
temperature_low_state_topic: "ebusd/ctlv2/z1NightTemp"
temperature_low_state_template: '{{value_json["tempv"].value}}'
temperature_high_state_topic: "ebusd/ctlv2/z1DayTemp"
temperature_high_state_template: '{{value_json["tempv"].value}}'
temperature_low_command_topic: "ebusd/ctlv2/z1NightTemp/set"

I try set HA sensor value integration (with filter-direction = r|u|^w on mqtt-hassio.cfg)

“ebusd/ctlv2/z1ActualRoomTempDesired” or “ebusd/hmu/Status01”

{
“0”: {“name”: “temp1”, “value”: 23.5},
“1”: {“name”: “temp1”, “value”: 23.5},
“2”: {“name”: “temp2”, “value”: null},
“3”: {“name”: “temp1”, “value”: null},
“4”: {“name”: “temp1”, “value”: null},
“5”: {“name”: “pumpstate”, “value”: “off”}
}

Did you get this working? i also use the ctlv2