MQTT HVAC on a MC6 thermostat

Premise: I’m new to MQTT integration with HA, I’ve read many questions on the community that have helped me so far but atm I’m stuck…

I have some MC6 HVAC thermostat that I’d like to integrate in HA via MQTT.
The problem is that this device sends values and receive command using a single MQTT topic where it publishes and subscribes to.
The topic is updData/MACADDRESS

The MQTT paload is a json:

{"msgid":18,
"mac":"MACADDRESS",
"version":4,
"temp":265,                       <---multiplied by 10
"humi":500,                      <---multiplied by 10
"settemp":250,                    <---multiplied by 10
"mode":2,
"onoff":1,
"frost":70,"
....
"standby":2,
"fan":2,"
timezone":13,
"prog":0,
"temp_prog":{}
}

I have a MQTT climate platform configured and it works readings both the current temp and the desired temp, but I’m not able to send temp variation to the device.

- climate:
      name: MC6 HVAC
      object_id: mc6_hvac
      modes:
        - "cool"
        - "heat"
        - "fan_only"
        - "drying"
        - "off"
      mode_state_topic: "updData/MACADDRESS"
      mode_state_template: "{{ value_json.node }}"
      fan_modes:
        - "Auto"
        - "High"
        - "Medium"
        - "Low"
      fan_mode_state_topic: "updData/MACADDRESS"
      fan_mode_state_template: "{{ value_json.fan }}"
      min_temp: 16
      max_temp: 30
      temp_step: 0.1
      current_temperature_topic: "updData/MACADDRESS"
      current_temperature_template: "{{ value_json.temp|float / 10  }}"
      temperature_state_topic: "updData/MACADDRESS"
      temperature_state_template: "{{ value_json.settemp|float / 10  }}"
      current_humidity_topic: "updData/MACADDRESS"
      current_humidity_template: "{{ value_json.humi|float / 10  }}"
      precision: 0.1
      retain: false
      qos: 0

How can I set the returning json to be publised as the thermostat wants it.

Another problem are the operating mode transcoding: the device sends numbers (1 cool, 2 heat, 3 vent, 4 auto) but HA tries to send “cool” or “heat”…

TY in advance

Solved.

mqtt:
  - climate:
      name: MC6 Climate
      object_id: mc6_1
      unique_id: mc6_1
      # MC6 gets updates immediately but sends status messages only after some minutes, so it's better to update the UI optimistically
      optimistic: true
      # MC6 in MQTT config supports only 4 modes, cooling,heating,fan only and dehumidifying
      # MC6 discard the dry mode when sent by mqtt, it may report it's status if the dehumid settings is enabled on the thermostat (not tested)
      modes:
        - "cool"
        - "heat"
        - "fan_only"
        - "dry"
      mode_state_topic: "updData/MACADDRESS-lowercase"
      # from MC6 manual: mode(1 cool, 2 heat, 3 vent, 4 auto), but in my thermostat the Auto fnction is replaced by Dehumid
      mode_state_template: >-
        {% if value_json.mode == 1 %}
          cool
        {% elif value_json.mode == 2 %}
          heat
        {% elif value_json.mode == 3 %}
          fan_only
        {% elif value_json.mode == 4 %}
          dry
        {% endif %}
      mode_command_topic: "MACADDRESS-lowercase"
      mode_command_template: >-
        {% if (value | string) == "cool" %}
          { "mode": 1 }
        {% elif (value | string) == "heat" %}
          { "mode": 2 }
        {% elif (value | string) == "fan_only" %}
          { "mode": 3 }
        {% elif (value | string) == "dry" %}
          { "mode": 4 }
        {% endif %}
      # from MC6 manual: fan speed(1 high, 2 medium, 3 low, 4 auto)
      fan_modes:
        - "High"
        - "Medium"
        - "Low"
        - "Auto"
      fan_mode_state_topic: "updData/MACADDRESS-lowercase"
      fan_mode_state_template: >-
       {% if value_json.fan == 1 %}
          High
        {% elif value_json.fan == 2 %}
          Medium
        {% elif value_json.fan == 3 %}
          Low
        {% elif value_json.fan == 4 %}
          Auto
        {% endif %}
      fan_mode_command_topic: "MACADDRESS-lowercase"
      fan_mode_command_template: >-
       {% if value == "High" %}
         { "fan":3  }
        {% elif value == "Medium" %}
         { "fan":2  }
        {% elif value == "Low" %}
         { "fan":1  }
        {% elif value == "Auto" %}
         { "fan":4  }
        {% endif %}
      min_temp: 5
      max_temp: 30
      temp_step: 0.5
      current_temperature_topic: "updData/MACADDRESS-lowercase"
      # dividing by 10 when reading the settings
      current_temperature_template: "{{ value_json.temp | float / 10  }}"
      temperature_state_topic: "updData/MACADDRESS-lowercase"
      # dividing by 10 when reading the settings
      temperature_state_template: "{{ value_json.settemp | float / 10  }}"
      temperature_command_topic: "MACADDRESS-lowercase"
      # multiplying by 10 when writing the settings
      temperature_command_template: "{ \"settemp\":{{ (value * 10) | int }} }"
      current_humidity_topic: "updData/MACADDRESS-lowercase"
      # dividing by 10 when reading the settings
      current_humidity_template: "{{ value_json.humi | int  / 10  }}"
      precision: 0.1
      retain: false
      qos: 1

  - switch:
      unique_id: mc6_1_switch_onoff
      object_id: mc6_1_switch_onoff
      name: "MC6-1 Switch-onoff"
      state_topic: "updData/MACADDRESS-lowercase"
      optimistic: false
      state_on: "ON"
      state_off: "OFF"
      value_template: >-
       {% if value_json.onoff == 1 %}
          "ON"
        {% elif value_json.onoff == 2 %}
          "OFF"
        {% endif %}
      command_topic: "MACADDRESS-lowercase"
      payload_on: '{"onoff":1 }'
      payload_off: '{"onoff":2 }'


template:
  - sensor:
    - name: "MC6-1-Humi"
      device_class: humidity
      unit_of_measurement: '%'
      state: "{{ state_attr('climate.mc6_hvac', 'current_humidity') | float }}"