Unwanted / Not comprehensible conversion when using Energy Datatype

Hi All,

I’m measuring energy and my sensor reports Wh. Because I’m interested in kWh I’m converting the Wh to kWh using a simple Javascript transform.

My Problem now is, that it leads to different results when using Energy datatype or not:

Number:Energy  Energy_Consumption_PoolHeatPump       "Poolwärmepumpe [%.2f kWh]"       (gPool,gCounters)  { channel="knx:device:bridge:bm_switch_actuator_1:energy_consumption_pool_heat_pump" [profile="transform:JS", function="divideBy1000.js"]}
Number         Energy_Consumption_PoolHeatPump_Test  "Poolwärmepumpe Test [%.2f kWh]"  (gPool,gCounters)  { channel="knx:device:bridge:bm_switch_actuator_1:energy_consumption_pool_heat_pump" [profile="transform:JS", function="divideBy1000.js"]}

As you can see in the attached Image, using Energy-Type seems to “undo” my conversion.

What’s happening here?

Best Regards

The output of that is a secret, but very relevant here.

I will take a guess that the transform returns a numeric only, without units.
It doesn’t matter what you think the units are, if you don’t specify them to openHAB.
You don’t need to convert anything in your transformation, just append the correct unit to the incoming value, "1234.0 Wh", and let the framework sort it out.

That does rely on the binding passing quantity states through the number type channel. Some do, some don’t.

What’s supposed to happen.
The Number:Energy type item has a different default display format that adds the kWh unit.
Note that’s independent of the [%.2f…] you specified. Those strings are ignored in the OH3 UI that you use.

Thanks for your answers.

So first here’s the script. As you suggested it only returns numeric values:

(function(inputData) {
    var DIVIDE_BY = 1000;
    return parseFloat(inputData) / DIVIDE_BY;

The underlying thing is a knx thing with DPT13.010 which should return Wh. So as I understand you right, I don’t have to convert the value. Instead I only need to work with the UoM and OpenHab will do the rest.

But how can I avoid to see Wh? For example I’ve created a Chart which shows me the daily consumption. It displays Wh but I wan’t to see kWh. Also when creating Pages I can’t see an option to define the UoM.

Thank you very much

You can define the display format (thus override the default) in the item’s metadata - state description - pattern. Use the format string you used e.g. %.2f