ESP32 and MIFlora over MQTT

  • Platform information:
    • Hardware: Raspberry Pi3+
    • OS: openhabian latest stable

Hello everybody,

I have an ESP32 that collects the data from my plant sensors and sends it to my broker via MQTT.

The problem, I get the following error message in the log.

2019-04-14 11:32:49.569 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.moi' in '{"tem":"19.9"}'

2019-04-14 11:32:49.577 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.fer' in '{"tem":"19.9"}'

2019-04-14 11:32:49.588 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.lux' in '{"tem":"19.9"}'

2019-04-14 11:32:51.017 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.tem' in '{"moi":"49"}'

2019-04-14 11:32:51.023 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.fer' in '{"moi":"49"}'

2019-04-14 11:32:51.027 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.lux' in '{"moi":"49"}'

What im doing wrong?

Things:

......
		Thing topic mirflora1 "Blume 1" @ "BT-GERÄTE" {
    Channels:
        Type string : moi   	"Bodenfeuchte"          [ stateTopic="home/BLEGateway/BTtoMQTT/C47C8D6A3826", transformationPattern="JSONPATH:$.moi"]
		Type string : tem    	"Temperatur"   			[ stateTopic="home/BLEGateway/BTtoMQTT/C47C8D6A3826", transformationPattern="JSONPATH:$.tem"]
		Type string : fer  		"Fruchtbarkeit"			[ stateTopic="home/BLEGateway/BTtoMQTT/C47C8D6A3826", transformationPattern="JSONPATH:$.fer"]
		Type string : lux   	"Helligkeit"			[ stateTopic="home/BLEGateway/BTtoMQTT/C47C8D6A3826", transformationPattern="JSONPATH:$.lux"]
    }
		Thing topic mirflora2 "Blume 2" @ "BT-GERÄTE" {
    Channels:
        Type string : moi   	"Bodenfeuchte"          [ stateTopic="home/BLEGateway/BTtoMQTT/C47C8D6A36A8", transformationPattern="JSONPATH:$.moi"]
		Type string : tem    	"Temperatur"   			[ stateTopic="home/BLEGateway/BTtoMQTT/C47C8D6A36A8", transformationPattern="JSONPATH:$.tem"]
		Type string : fer  		"Fruchtbarkeit"			[ stateTopic="home/BLEGateway/BTtoMQTT/C47C8D6A36A8", transformationPattern="JSONPATH:$.fer"]
		Type string : lux    	"Helligkeit"			[ stateTopic="home/BLEGateway/BTtoMQTT/C47C8D6A36A8", transformationPattern="JSONPATH:$.lux"]
    }
		Thing topic mirflora3 "Blume 3" @ "BT-GERÄTE" {
    Channels:
        Type string : moi   	"Bodenfeuchte"          [ stateTopic="home/BLEGateway/BTtoMQTT/C47C8D6A3BAC", transformationPattern="JSONPATH:$.moi"]
		Type string : tem    	"Temperatur"   			[ stateTopic="home/BLEGateway/BTtoMQTT/C47C8D6A3BAC", transformationPattern="JSONPATH:$.tem"]
		Type string : fer  		"Fruchtbarkeit"			[ stateTopic="home/BLEGateway/BTtoMQTT/C47C8D6A3BAC", transformationPattern="JSONPATH:$.fer"]
		Type string : lux    	"Helligkeit"			[ stateTopic="home/BLEGateway/BTtoMQTT/C47C8D6A3BAC", transformationPattern="JSONPATH:$.lux"]
    }
......

Items:

Group   gBlume

Number  whz_blume1_tem      "Temperatur"        <flower>        (gBlume)            {channel="mqtt:topic:broker:mirflora1:tem"}
Number  whz_blume1_fer      "Fruchtbarkeit"     <flower>        (gBlume)            {channel="mqtt:topic:broker:mirflora1:fer"}
Number  whz_blume1_lux      "Sonnenlicht"       <flower>        (gBlume)            {channel="mqtt:topic:broker:mirflora1:lux"}
Number  whz_blume1_moi      "Feuchtigkeit"      <flower>        (gBlume)            {channel="mqtt:topic:broker:mirflora1:moi"}

Number  whz_blume1_tem2     "Temperatur"        <flower>        (gBlume)            {channel="mqtt:topic:broker:mirflora2:tem"}
Number  whz_blume1_fer2     "Fruchtbarkeit"     <flower>        (gBlume)            {channel="mqtt:topic:broker:mirflora2:fer"}
Number  whz_blume1_lux2     "Sonnenlicht"       <flower>        (gBlume)            {channel="mqtt:topic:broker:mirflora2:lux"}
Number  whz_blume1_moi2     "Feuchtigkeit"      <flower>        (gBlume)            {channel="mqtt:topic:broker:mirflora2:moi"}

Number  whz_blume1_tem3     "Temperatur"        <flower>        (gBlume)            {channel="mqtt:topic:broker:mirflora3:tem"}
Number  whz_blume1_fer3     "Fruchtbarkeit"     <flower>        (gBlume)            {channel="mqtt:topic:broker:mirflora3:fer"}
Number  whz_blume1_lux3     "Sonnenlicht"       <flower>        (gBlume)            {channel="mqtt:topic:broker:mirflora3:lux"}
Number  whz_blume1_moi3     "Feuchtigkeit"      <flower>        (gBlume)            {channel="mqtt:topic:broker:mirflora3:moi"}

MQTT-Message that the broker received

Client mosqsub/27667-openhabno received PUBLISH (d0, q0, r0, m0, ‘home/BLEGateway/BTtoMQTT/C47C8D6A3826’, … (14 bytes))
home/BLEGateway/BTtoMQTT/C47C8D6A3826 {“tem”:“20.2”}
Client mosqsub/27667-openhabno received PUBLISH (d0, q0, r0, m0, ‘home/BLEGateway/BTtoMQTT/C47C8D6A3BAC’, … (14 bytes))
home/BLEGateway/BTtoMQTT/C47C8D6A3BAC {“lux”:“6642”}
Client mosqsub/27667-openhabno received PUBLISH (d0, q0, r0, m0, ‘home/BLEGateway/BTtoMQTT/C47C8D6A3BAC’, … (13 bytes))
home/BLEGateway/BTtoMQTT/C47C8D6A3BAC {“fer”:“425”}
Client mosqsub/27667-openhabno received PUBLISH (d0, q0, r0, m0, ‘home/BLEGateway/BTtoMQTT/C47C8D6A36A8’, … (12 bytes))
home/BLEGateway/BTtoMQTT/C47C8D6A36A8 {“moi”:“36”}
Client mosqsub/27667-openhabno received PUBLISH (d0, q0, r0, m0, ‘home/BLEGateway/BTtoMQTT/C47C8D6A3826’, … (12 bytes))
home/BLEGateway/BTtoMQTT/C47C8D6A3826 {“moi”:“41”}
Client mosqsub/27667-openhabno received PUBLISH (d0, q0, r0, m0, ‘home/BLEGateway/BTtoMQTT/C47C8D6A3BAC’, … (12 bytes))
home/BLEGateway/BTtoMQTT/C47C8D6A3BAC {“moi”:“49”}
Client mosqsub/27667-openhabno received PUBLISH (d0, q0, r0, m0, ‘home/BLEGateway/BTtoMQTT/C47C8D6A3826’, … (13 bytes))
home/BLEGateway/BTtoMQTT/C47C8D6A3826 {“lux”:“492”}

The JSONPATH tranformation you are trying to apply is not a valid path for whatever message is being published to the topic.

What you need to realize here is that because your device is publishing different JSON messages to the same topic for each device, two of the three Items will generate an error for each message. For example, if {“temp”:“20.1”} is published to home/BLEGateway/BTtoMQTT/C47C8D6A3826, whz_blume1_fer, whz_blume1_lux, and whz_blume1_moi will generate errors because the message doesn’t match the JSONPATH for those Items.

If you are using the 2.5 M1 version of the binding, you can chain transformations and put a REGEX transformation first to match only those messages that you care about. See MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters for details.

If you have control over how the device publishes it’s readings, it would be even better and more appropriate to have it publish the sensor readings to separate topics in the first place.

That would be the way forward and actually how MQTT was designed for.