Hi,
I am having trouble formatting a number extracted within the general MQTT thing from a JSON string using a JSONPATH transformation.
For example, my electricity meter outputs the following string to a Mosqitto MQTT broker:
[{"lifetime":61245767,"energy":7589.13868887,"power":351.46,"power_l1":95.32,"power_l2":132.36,"power_l3":123.78,"voltage_l1":234.6,"voltage_l2":233.3,"voltage_l3":234.2,"status":"001C0104","rate":14.66,"price":0.2426,"time":1640512178355},{"serial":"EBZ5DD3BZ06ETA_107","custom_id":"1EBZ0100507409","device_id":"1EBZ0100507409"}]
I created an “Electricity Meter” thing with an “Energy” channel :
UID: mqtt:topic:29be605c8c:2e5f28b0fe
label: Electricity Meter
thingTypeUID: mqtt:topic
configuration:
payloadNotAvailable: offline
availabilityTopic: smartmeter/status
payloadAvailable: online
bridgeUID: mqtt:broker:29be605c8c
channels:
- id: Energy
channelTypeUID: mqtt:number
label: Energy
description: ""
configuration:
stateTopic: smartmeter/state
transformationPattern: JSONPATH:$.[0].energy
The channel configuration dialog allows me to specify a JSONPATH transformation JSONPATH:$.[0].energy
to extract the energy value from the JSON string. This is all very good. However, I am missing a field “Incoming Value Format” in the configuration dialog, similar to the “Outgoing Value Format” field:
Currently I am getting the follwing output, which has a ridiculously number of decimal places:
I principle, the JSONPATH transformation could be applied later when linking the channel to an item. The JSONPATH option is the profile dialog has a “State Formatter” field, which I was looking for earlier in the MQTT thing dialog. However, when given the transformation here, it is not applied and I get “NONE” as output.
The only way this works is when I do the JSONPATH transformation in the MQTT channel dialog as show above, and add a “State Description” to the energy “Item” with a “Pattern”. However, the pattern overrides the “unit of measurement” given in the MQTT channel dialog, but finally formats the number as I want:
Overall the option to enter a number format is not very consistent. I feel there should be a possibility to format the number right in the general MQTT thing dialog before it is passed on to the main.ui. I am using openHAB 3.2.0 Release Build in the official docker container under aarch64 (Odroid C2).
Any idea how this could be handled differently? I am missing something here?