Template add mqtt sensor with dot

Hello,

I want to integrate a co2-meter in HA.
It communicates with MQTT and sends something like:

{"ClientID":"MS-CFCC","Date":"03-01-2023","Time":"11:01:02","CO2":610,"Temperature":17.45,"Humidity":64.10,"Pressure":1025.71,"IAQ":54.60,"GASres":366,"PM1.0":2.19,"PM2.5":2.31,"PM4.0":2.31,"PM10.0":2.31,"sps30status":"on"}

In forums I found that integration cn be done bij:


template:
  - trigger:
      - platform: mqtt
        topic: MSP-CFCC
    sensor:
      - name: CO2_meter_CO2
        unit_of_measurement: " ppm"
        state: "{{ (trigger.payload | from_json).CO2 }}"

That works for the most items, but that does not work for the “PM1.0”, “PM2.5” etc.

The best guess, based o other forum items, I can think of is:


    - name: CO2_meter_PM10
        unit_of_measurement: " μg/m3"
        state: "{{ (trigger.payload | from_json).['PM1.0'] }}"
     - name: CO2_meter_PM10
        unit_of_measurement: " μg/m3"
        state: "{{ (trigger.payload | from_json).['PM2.5'] }}"

etc.

But that does not work
It creates an entity, but does not read values. Info tab says: not available.

Does anyone know the trick to get this working?

Try this:

     - name: CO2_meter_PM10
        unit_of_measurement: " μg/m3"
        state: "{{ (trigger.payload | from_json)['PM1.0'] }}"
     - name: CO2_meter_PM10
        unit_of_measurement: " μg/m3"
        state: "{{ (trigger.payload | from_json)['PM2.5'] }}"

Great, that did it.

Thanks

Is there any reason you are using triggered template sensors rather than mqtt sensors?

Not specific, but this does what I want it to do: bring the values to the utilities I need.