Sorry to bring that old discussion up again, but I am facing a problem here (most probably it is my lack of knowledge).
(Running OH 3.3.0 as a VM with Openhabian / Debian on Proxmox)
I am using a MQTT Smartmeter Device that reads the power consumption from the grid. Unfortunately, the meter does provide only a single value per packet, still they are all using the same format:
{"Time":"2022-08-29T18:44:01","Z1":{"76_7_0":-4.04}}
The value after Z1 changes, so 76_7_0 could be 1_8_1 or 2_8_0 f.e., hence I needed to implement the REGEX function.
Now, when defining the MQTT Thing in a text file, the expression looks like that:
Thing topic Zaehler @ "MQTT" {
Channels:
Type number : z1Zaehlerstand "Zählerstand" [stateTopic="tele/Zaehler/SENSOR", transformationPattern="REGEX:(.*1_8_0.*)∩JSONPATH:$.Z1.1_8_0"]
Type number : z1BezugTarif1 "Bezug Tarif 1" [stateTopic="tele/Zaehler/SENSOR", transformationPattern="REGEX:(.*1_8_1.*)∩JSONPATH:$.Z1.1_8_1"]
Type number : z1BezugTarif2 "Bezug Tarif 2" [stateTopic="tele/Zaehler/SENSOR", transformationPattern="REGEX:(.*1_8_2.*)∩JSONPATH:$.Z1.1_8_2"]
Type number : z1Einspeisung "Einspeisung" [stateTopic="tele/Zaehler/SENSOR", transformationPattern="REGEX:(.*2_8_0.*)∩JSONPATH:$.Z1.2_8_0"]
Type number : z1Leistung "Aktuelle Gesamtleistung" [stateTopic="tele/Zaehler/SENSOR", transformationPattern="REGEX:(.*16_7_0.*)∩JSONPATH:$.Z1.16_7_0"]
Type number : z1LeistungL1 "Aktuelle Leistung L1" [stateTopic="tele/Zaehler/SENSOR", transformationPattern="REGEX:(.*36_7_0.*)∩JSONPATH:$.Z1.36_7_0"]
Type number : z1LeistungL2 "Aktuelle Leistung L2" [stateTopic="tele/Zaehler/SENSOR", transformationPattern="REGEX:(.*56_7_0.*)∩JSONPATH:$.Z1.56_7_0"]
Type number : z1LeistungL3 "Aktuelle Leistung L3" [stateTopic="tele/Zaehler/SENSOR", transformationPattern="REGEX:(.*76_7_0.*)∩JSONPATH:$.Z1.76_7_0"]
}
Without the REGEX, the well know error is to be seen in the logs. With the REGEX, ALL outcome is filtered and no packed is passed through at all.
So I defined the things in the UI, using the same parameters:
UID: mqtt:topic:6296256670:Zaehler
label: Generic MQTT Thing
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:jarvis
channels:
- id: z1Leistung
channelTypeUID: mqtt:number
label: Einspeisung / Bezug (Zähler)
description: ""
configuration:
stateTopic: tele/Zaehler/SENSOR
transformationPattern: REGEX:(.*16_7_0.*)∩JSONPATH:$.Z1.16_7_0
unit: W
- id: z1Zaehlerstand
channelTypeUID: mqtt:number
label: Zählerstand
description: ""
configuration:
stateTopic: tele/Zaehler/SENSOR
transformationPattern: REGEX:(.*1_8_0.*)∩JSONPATH:$.Z1.1_8_0
unit: Wh
- id: z1Einspeisung
channelTypeUID: mqtt:number
label: Einspeisung
description: ""
configuration:
stateTopic: tele/Zaehler/SENSOR
transformationPattern: REGEX:(.*2_8_0.*)∩JSONPATH:$.Z1.2_8_0
unit: Wh
Which works like a charm. Now, call me old fashioned, but I would like to stay with the text files. Any idea why it does work only with the UI version ?
Looking at the docs for the binding, the REGEX should work just fine (unless I made a mistake with the syntax, that is…)