OH4: unit - Wmin not accepted

Shelly sends via MQTT the Energy values only in Wmin (Watt per minute) for whatever reason… As the main Energy unit is kWh I tried to convert without using a JavaScript. With the unit concept I tried to enter Wmin in the metadata-unit of the item, but I got an error (…could not be parsed to a known unit).
But both W and min are supported (Units Of Measurement | openHAB) - so what am I doing wrong?
Conversion via a script works fine by the way - but without script would be more elegant…

You probably need to convert it to Wh as unit symbol you try to use is not recognized.
There are combined units which are added by openHAB itself, however underlying library might not catch all possible combinations see:

Watt Second (Ws) and Watt Hour (Wh) are supported so I’d call that a regression that Wmin doesn’t work. It’s worth filing an issue I think.

Wmin was never supported, only Ws and Wh.

Using * for multiplying (or / for dividing) units should always work: W*min.

Wmin seems to be a very uncommon unit and I believe there is no need to add a special label in core like Ws and Wh.

1 Like

Would code like val energy = 50|W * 10|min work then in rules DSL (or the equivalent in ECMA JS) ? Or would it need to be val energy = 50|W * 60 * 10|s ?

The tip with the multiplication worked great, so W*min in the unit did the trick and I don’t need any DSL-rule any more. For the 4 plugs I had the (subjective) impression that this reduced the CPU usage (but not the memory).
And I also wonder why Shelly decided to use Wmin…
The DSL rule was quite tricky (for me…), as it arrives as String but I needed an Integer.

var Number returnValue
var int IntImport = Integer.parseInt(input)  
returnValue = IntImport * 0.000017

My guess is it would work based on what I’ve seen in other threads. For example val watts = 120|V * 5|A generated 600 W as the result of the calculation, which was a pleasant surprise. I would expect either of your examples to work.

I think what @J-N-K is saying is that because Ws and Wh are commonly used, a shorthand label was created for them. Wmin can still be represented, just without the shorthand label. For example, their equivalent using the * are W*s and W*h which is the standard way to show the units have been multiplied. If there isn’t already a label, you can always multiply the units using the * in the units. So 50|W * 10|min should work. You don’t need to only use s or h.

For Rules DSL I don’t know if it can handle the * or / in the units with the short hand representation (e.g. 50|W * min). It might work if it’s escaped (e.g. 50|W \* min). Creating a QuantityType should work though. (e.g. QuantityType.valueOf('50 W*min')).

For JS Scripting see JavaScript Scripting - Automation | openHAB which has some discussion on this point and shows the JS equivalents.

The result of the last line of code executed is what gets returned so you could just use

Integer.parseInt(input) * 0.000017

somewhat OT, but reading that example section

qty = Quantity('1 m^2/s^-2'); // negative powers

shouldn’t that rather be

qty = Quantity('1 m^2*s^-2'); // negative powers

I know it’s meant to demonstrate usage but the former is no relevant physical dimension