Problem to integrate MQTT data of climate sensor

Hello All!
A climate sensor provides CO2 data via MQTT. The basic data of the sensor added to configuration.yaml:

mqtt:
   sensor:
    - state_topic: "homeassitant/sensor/co2meter/c"
      name: "CO2 Meter"
      unit_of_measurement: "ppm"
      value_template: '{{ value_json.value | int }}'

I have no idea to access this entity within the MQTT integration. The payload can be observed by “MQTT config - listen to a topic”. Also with MQTT explorer. However, it is not recognized by MQTT as a new entity.
Any hint is welcome!
Cheers Uli

I think this is wrong

think the json value is missing some data

should look something like

"{{value_json['array_name'].its_data_point_you_reading }}"

need to see the json message

this mite help

Without that payload it’s a shot in the dark.

Hello,
thanks for the reply: attached a screencopy of “Home Assistant/MQTT/listen to topic”:


In MQTT Explorer it looks similar (the payloads are integers) and each sensor is a seperate topic.
The data of the sensor is available, however I found no way to get it as an entity of the MQTT integration.
Cheers Uli

It looks like I have the same problem regarding a single data value published to an MQTT broker by a Tasmota device. A rule running on the Tasmota device publishes the data as a single topic:value pair. Unlike other topic messages with many components that display within “{ }” in JSON format the “Listen to a topic” feature displays the data just like what K shows in the screencopy. It shows the topic followed by the data value on a single line with no “{ }” or any punctuation characters

The configuration.yaml uses a similar setup as K shows. HA shows an MQTT integration entity corresponding to the configuration.yaml entry, but the entity has an unavailable status.

Incidentally I find the MQTT integration configuration discovery fail to discover anything regardless of what the prefix setting is. I am using MQTT Explorer to view the traffic. MQTT shows the published data in the same way as “Listen to a topic” shows the data.

If there’s no json in the message, then just use value.

value_template: '{{ value | int }}'

Or just leave the option value_template out?
Not sure, try it.

Using just value worked. Thank you

Hello,
I first changed the value_template and in a second step I commented it out - however no change - still no change in the number of the entities of integration MQTT. How did you made use of the new measured value?
Cheers
Uli

Solved:
With this data inside configuration.yaml it finally works. The unique_id is essential to access and use it inside Home Assistant. An additional weakness of the sensor is, that it truncates the length of the state_topic string. It must include a individual name, the keyword “sensor” and the names of the measured values. I started with co2_meter instead of co2m - and this kicked off the individual names of the measured values. So trivial!

mqtt:
sensor:
- state_topic: “co2m/sensor/CO2c”
name: “CO2 Meter”
unit_of_measurement: “ppm”
unique_id: “kef20_co2meter_0x1”
- state_topic: “co2m/sensor/CO2t”
name: “CO2 Meter”
unit_of_measurement: “°C”
unique_id: “kef20_co2meter_0x2”

Cheers Uli