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:
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:$..energy
The channel configuration dialog allows me to specify a JSONPATH transformation
JSONPATH:$..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?