This is a feature request, unless it is already possible, although I have not found out how to do this in the forums or documentation.
The screenshots show I have an item which is a number. It is extracted from JSON using the JSONPath transformation. The value is in bytes per second of my internet download speed.
I’d like to convert the number into Megabytes per second, i.e. do a maths operation (divide) on the number.
I know how I would’ve done this in the foo.items and bar.rules files way of doing things, but now I am on OH3 I would prefer to stick to doing everything through the UI.
I feel like doing a maths operation on a number should be possible through the UI; if it is how do I do it, if not where should I propose this as a feature request?
Screenshots below, if it helps!
Thanks in advance
Do you want to do that before or after you put your new state in an Item?
Essentially you areasking for a transformation, a long standing feature of openHAB.
There is no way to input maths expressions by point’n’click,nor likely to be. You have to type it somewhere. For now, 'somewhere’is either a ruleor a transform file.
To answer your specific question though, no, there is no way to do math on the state of an Item using only point-and-click rules. You’d have to create a rule and use a Script Action where you can do the math and update the Items as necessary.
But that’s not the only solution. You could create a rule through the UI. But you’ll have to use a Script Action and type in the math and the Item update you want.
The key is we want to get this number into an Item of type Number:DataTransferRate. Once it’s in that type of Item you can see the value and do math with the Item in any compatible unit you want to.
Let’s assume the straight forward approach works. You will change the Speedtest_Download Item to be of type Number:DataTransferRate. With any luck it will treat the value as bits/s. Then define the State Description metadata on the Item to be something like
Download %d Mibits/s as the display state. The conversion between bits/s to megabits/s will be done for you through the magic of Units of Measurement where ever the Item is shown in MainUI. But the Item will retain it’s state as bits/s.
The less straight forward approach will again be a simple rule that takes the value returned by your Exec binding and updates a proxy Number:DataTransferRate Item appending " bits/s" to the state so the Item knows what units to use. Then set the display state metadata as described above. But you won’t be able to do that through point-and-click either. You’ll need to use a Script Action.
There are already three different ways to achieve what you are after, one of which can be done completely through point-and-click in the UI (assuming linking the result from the Exec binding to a Number:DataTransferRate works). I can’t imagine adding a fourth way will make openHAB more usable.
Or you could leave transformation to UoM, using a quantity type of data transfer rate, forcing it’s transformation via expected unit in item label.