MQTT sensors (from domoticz)

My domoticz setup is publishing several sensor data with MQTT. If I don’t create a separate floor and room in domoticz for every sensor all data is in one topic (domoticz/out). Every domoticz payload has a unique id (idx) and I managed to create a value_template based on this id:

  - platform: mqtt
    name: "Woonkamer Temp"
    state_topic: "domoticz/out"
    unit_of_measurement: '°C'
    force_update: false
    value_template: "{% if value_json.idx == 6252 %} {{ value_json.svalue1 }} {% endif %}"

Payload:

{ "Battery" : 100, "RSSI" : 7, "description" : "", "dtype" : "Temp + Humidity", "id" : "11022", "idx" : 6252, "name" : "Woonkamer", "nvalue" : 0, "stype" : "Cresta, TFA TS34C", "svalue1" : "24.4", "svalue2" : "53", "svalue3" : "1", "unit" : 1 }

10 other Cresta devices are sending data.

The effect is I don’t get continuous readings. The badges only show the data for a second or so.Tried force_update true and false. Tried expire_after: 30. all without effect.

Solved thanks to:

That’s because the value_template has no ‘else’ in it. It returns a value if idx==6252 but, if it’s not, then it returns … nothing. So sensor.woonkamer_temp contains a value only for the brief time idx is 6252 and no value when it isn’t.

The suggested solution is a good one. It demultiplexes the received payload into separate, unique topics. FWIW, it’s the same approach (see Strategy 2) I suggested for users of the Sonoff RF Bridge (and any other device that uses a single MQTT topic to carry information for multiple sensors and switches).

Thanks for your solutions. Good to read I implemented the most effective.