It does but it’s kind of broken right now when you want to convert from one unit to a different one. The problem is no matter what you put into the Channel, the State Description will override it so instead of converting the 1000 Wh to 1 kWh you’ll end up with 1000 kWh.
Because of this bug the only way to actually change the units of the value coming from MQTT is through a JS Transformation.
Is your Item of Number type? Then you must pass it a number from MQTT, divided by 1000. You can add text “kWh” in your Item pattern metadata for display.
Is your Item of Number:Energy type? Then you must pass it a value with units. You can give Item a default unit text “kWh” in your Item pattern metadata. You can transform the number coming from MQTT by appending the text " Wh" to it. No need to divide, if you use the proper units then openHAB takes care of conversions.
I didn’t either. That’s cool! I should follow my own advice and reread the docs periodically. NOTE: that’s a new feature in OH 3.2 and not available in OH 3.1. And I don’t know when that feature was added during OH 3.2 development. So @Daniel_Hermann1, which version of OH are you running?
It must be a recent enough 3.2 if it’s not exploding on the expression and it appears to be doing the math at least and removing the decimal places. And I’m guessing you have the syntax right there as well.
So what is the type of the Item now and what is the State Description on that Item? Do you want to just show that Item as kWh but let it remain stored as Wh? Do you want it stored as kWh too? This has implications to things like charting and the like.
Of course if you want to handle UNDEFs etc, it might get more tricky…
Thanks for the correction regarding the whitespace, will correct the above post for posterity.
So i Tried (isNaN(input)) ? input : input/1000 + " kWh" as Transformation, leaving the field “Unit of Measurement” as kWh. Unfortunately I get 645.898 kWh as an answer (or just 645.898 if i leave the Unit of Measurement, even thogh I have the + "kWh " in the JS command).
The right answer would be 0.65… kWh.
In the Log I get the message
2021-12-17 09:02:49.545 [WARN ] [t.generic.ChannelStateTransformation] - Transformation service (ISNAN(INPUT)) ? INPUT for pattern input/1000 + " kWh" not found!