Help needed for retrieving mqtt value

Hi,

I’m trying to understand how to retrieve a value published by a device in zigbee2mqtt and make it a sensor.
This is what I see in mqtt explorer:

and the simple code I’m trying for this:

mqtt:
  sensor:
    - name: "Salon system mode"
      state_topic: "zigbee2mqtt/Thermostat Salon/set"
      value_template: "{{ (value_json.system_mode) }}"

Unfortunately, the sensor always shows ‘unknown’.

Can someone give me a hint on how to get this working?
Many thanks

  • In Zigbee2MQTT, select Setting → Home Assistant integration → Enabled.

  • Restart Zigbee2MQTT.

  • Zigbee2MQTT should now automatically create entities in Home Assistant for all devices it manages.


NOTE

Zigbee2MQTT topics that end with the word set are normally used for setting a device’s value (not for reading the device’s value).

Thanks. But this setting was already enabled.

Concerning your ‘note’, I see another place where this info could be available. This is under


And the config is what shows under Zigbee2MQTT → Expose:

UnderZigbee2MQTT → State, the following data is available:

{
    "away_preset_temperature": "5.0",
    "battery": 100,
    "calibrated": true,
    "child_lock": false,
    "device_temperature": 24,
    "internal_heating_setpoint": 22,
    "last_seen": "2025-05-25T11:27:11.578Z",
    "linkquality": 255,
    "local_temperature": 22.4,
    "occupied_heating_setpoint": 22,
    "power_outage_count": 0,
    "preset": "manual",
    "schedule": false,
    "schedule_settings": "mon,sun|0:00,21.0|12:00,17.0|18:00,21.0|23:59,21.0",
    "sensor": "internal",
    "setup": false,
    "system_mode": "heat",
    "update": {
        "installed_version": 2590,
        "latest_version": 2590,
        "state": "idle"
    },
    "update_available": false,
    "valve_alarm": false,
    "valve_detection": true,
    "voltage": 2900,
    "window_detection": true,
    "window_open": false,
    "calibrate": null,
    "external_temperature_input": null
}

Is there a way to read the system_mode state?

Then there should be no need for you to configure an MQTT Sensor in YAML. Zigbee2MQTT has already created climate entities containing the information you want.

There’s no need to read that value directly from an MQTT topic because Zigbee2MQTT has already created a climate entity containing it. A climate entity’s state value is the operating mode (heat, cool, auto, etc) so it has what you want.

Go to Developer tools → States and find your climate entities in the displayed list. Let’s say one of them is climate.thermostat_salon. Find it in the list and click it. All of it’s available properties will be displayed at the top of the list.

You can read an entity’s state value with a template. For example, copy-paste the following template into the Template Editor (Developer tools → Template):

{{ states('climate.thermostat_salon') }}

Damn! That simple! All I needed
Many thanks for your time.

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag.

It will automatically place a check-mark next to the topic’s title which indicates to others that the topic has been solved. This helps other users find answers to similar questions.