How to change the item's UoM in MainUI?


Number:Power     Solar_AC_Power                "Solar Power [%.2f W]" 

In the main UI, I’d like to show this number in “W” unit if it’s less than 1000, and in “kW” unit if it’s greater than 1000W. Is there a nice way of doing this without going through parseInt and using conditionals and adding the unit back as a string concatenation?

No, you can pick one unit or the other. There is no way to apply an expression for this in the State Description Pattern.

However, you can override the default widgets and use an expression. I believe by default it uses W as the units. So you can set the State Description Pattern to use kW. Then in the expression use the items.Solar_AC_Power.state when it’s under 1000 and items.Solar_AC_Power.displayState when it’s over 1000.

Thanks for the tip! That’s handy to know.

In my case though, I couldn’t use kW in the state description. It has to be W to match the incoming data from the binding. I ended up creating a virtual String item, and updating their values using a rule and the UI code just displays the virtual item’s state.

With a sitemap based UI, you could set up two alternative display lines with [state presentation] in different units, and then use visibility= option to show/hide one or other depending if state >1000 W

Not sure how you replicate that in MainUI, it’s probably easier there to code one ‘smart’ widget.

That shouldn’t matter. The whole point of using UoM is that it’s able to handle converting between units. The State Description metadata only changes how the Item appears in MainUI.

What’s the binding and how is it configured.

You would use an expression for the part of the widget that displays the Items state. It’s super powerful and way more flexible than sitemaps.