MQTT select - Sinope TH1300ZB Thermostat - Convert the json command payloads to friendly option names / subscribe not working

Trying to learn how to use MQTT select
https://www.home-assistant.io/integrations/select.mqtt/
here’s my first working draft (trying to add an unsupported zigbee2mqtt feature in HS for the Sinope TH1300ZB thermostat: “floor control mode”)

select:

  - name: "Test MQTT Select"
    state_topic: "zigbee2mqtt/THERMOSTAT1"
    value_template: "{{ value_json.floor_control_mode }}"
    command_topic: "zigbee2mqtt/THERMOSTAT1/set"
    options:
      - '{"floor_control_mode": "ambiant"}'
      - '{"floor_control_mode": "floor"}'

the select entity gets created and control/commands do work,

image

1 : How can I convert the json command payloads to friendly option names? IE: “ambiant” & “floor”
2 : The “state” remains “unknown”. Should it get updated based on my syntax above for state_topic & value_template ? or are my syntax/assumptions wrong?

here’s the payload received under state_topic: “zigbee2mqtt/THERMOSTAT1”

{
  "backlight_auto_dim": "sensing",
  "current": 0,
  "enable_outdoor_temperature": "ON",
  "energy": 192.18,
  "floor_control_mode": "floor",
  "floor_limit_status": "off",
  "gfci_status": "off",
  "keypad_lockout": "unlock",
  "linkquality": 102,
  "local_temperature": 20.6,
  "occupied_heating_setpoint": 20.5,
  "outdoor_temperature_timeout": null,
  "pi_heating_demand": 0,
  "power": 0,
  "power_apparent": 1104,
  "running_state": "idle",
  "second_display_mode": "setpoint",
  "system_mode": "heat",
  "temperature_display_mode": "celsius",
  "thermostat_occupancy": "occupied",
  "thermostat_outdoor_temperature": 1.5,
  "time_format": null,
  "voltage": 240
}

Thank you!

Anyone? been looking for examples all over the forums & Google but can’t find something to guide me in the right direction.
Thanks for your help.

  • HA newbie tying to learn :slightly_smiling_face:

I can obviously get the subscription component with MQTT Sensor in a separate entity but is it the correct approach? (vs getting state within the MQTT select entity)

sensor:

  - state_topic: 'zigbee2mqtt/THERMOSTAT1'
    name: 'THERMOSTAT1 Floor control mode'
    value_template: '{{ value_json.floor_control_mode }}'

If so, I’m just missing the “friendly name” part in my original post. thx

phew. finally figured it out, hope this helps other users as “mqtt select” examples are hard to find, especially when “command_template” is needed.

So instead of creating a bunch of input selects + sensors + automations
this acts as input_select + mqtt publish + mqtt subscribe, all in one.
Glad this works as it will save me dozens of unneeded entities & extra coding.

Cheers.

    - unique_id: thermostat1_floor_control_mode
      name: thermostat1 floor control mode
      retain: true
      command_topic: "zigbee2mqtt/THERMOSTAT1/set"
      command_template: >-
        {% set options = { 'ambiant':'{"floor_control_mode": "ambiant"}', 'floor':'{"floor_control_mode": "floor"}'} %}
        {{ options[value] if value in options.keys() else 'not set' }}
      state_topic: "zigbee2mqtt/THERMOSTAT1"
      value_template: "{{ value_json.floor_control_mode }}"
      options:
        - ambiant
        - floor

1 Like