Working with UoM in MainUI and MQTT

Hello all,

I had some issues with my item/thing/channel configuration after upgrading to v3.4.0. I came from managing my configuration in files a while ago and converted everything into UI based configuration.

I write this post to help other. Any feedback on my method is welcome as well.

Below I use an example of a dedicated dsmr reader dsmrreader/dsmr-reader: DSMR-telegram reader & data visualizer for hobbyists. Free for non-commercial use. ( that is running on a raspberry pi completely independent of openhab. It sends it’s data over MQTT and I use those messages to do the fancy stuff in Openhab.

I’m not going into any details on setting up this server or the communicate with MQTT. I’m focusing on the Units of Measure part as that was the part I had to struggle with.

The thing definition of the MQTT message looks like this:

Here is an example of a MQTT message send by the server:

{"id": 69138993, "timestamp": "2022-12-26T10:48:19Z", "electricity_delivered_1": "4723.374", "electricity_returned_1": "11485.934", "electricity_delivered_2": "7918.930", "electricity_returned_2": "4291.034", "electricity_currently_delivered": "1.740", "electricity_currently_returned": "0.000", "phase_currently_delivered_l1": "0.000", "phase_currently_delivered_l2": "0.000", "phase_currently_delivered_l3": "1.981", "extra_device_timestamp": "2022-12-26T10:45:49Z", "extra_device_delivered": "1974.931", "phase_currently_returned_l1": "0.240", "phase_currently_returned_l2": "0.000", "phase_currently_returned_l3": "0.000", "dsmr/reading/phase_voltage_l1": "229.4", "dsmr/reading/phase_voltage_l2": "0.0", "dsmr/reading/phase_voltage_l3": "227.8"}

The electricity_delivered_1 parameter is the total energy delivered during the night since the start of measurement. It’s given by the dsmr reader as a kWh value. I would like to make sure that Openhab reads it as such and that it displays the value in MWh with three decimal values.

For that I define the channel so that Openhab knows that the value that it will receive on this channel is kWh:

and offcourse the json path transformation:

Next you add an item to the channel with the type Number:Energy:

And, after saving and going back to the item, you add metadata to it of the type “State description”:

(in the example above, I already had a state description defined, that’s why the white text is visible above the “add metadata” link).

Finally, in the state description, you set the format so that the item is always displayed in MWh and with 3 decimal numbers:

For ease of copy pasting: %.3f MWh

I hope I’ve helped someone with this.