openhab / openhab-webui

Web UIs of openHAB
Eclipse Public License 2.0
215 stars 237 forks source link

Group SUM does not display units under Properties, is one of the group members is undefined #1879

Open dilyanpalauzov opened 1 year ago

dilyanpalauzov commented 1 year ago

I have this item

Group:Number:SUM gReletaWatts "Abc [%d VA]" ["Power", "Measurement"]

In a sitemap (Basic UI) it is displayed as Text element correctly - a number followed by VA.

In Main UI 3.4.2, Overview -> Properties -> Power the units are not shown, if one of the components of gReletaWatts is unset. The number is displayed however correctly, the undifined items are counted as zero.

rkoshak commented 1 year ago

In a sitemap (Basic UI) it is displayed as Text element correctly - a number followed by VA.

That's because you told it to in the label. [%d VA] means show the state as an integer followed by the literal string VA. That does not set the units for the Item nor is that used anywhere in MainUI.

To define the pattern to show the state in MainUI you need to add State Description metadata to the Item and set the pattern to the same as what you have between the [ ] in your Item label. That will always show the value with the VA following it.

Note, the Item type is just Number so this Group Item does not carry units and there are inconsistencies in how numbers with units and those without are handled by plain Number Items. In OH 4 there is a complete rework on how units are managed which should make this behave more consistently (in this case your Group Item will not carry units because it's just a Number, not a Number:Power.

I recommend closing this because in OH 3 it's working as designed (i.e. you need to set the state description pattern to change how the value is shown in MainUI) and once the changes to UoM handling is merged into OH 4 reopen it if the Group:Number still sometimes shows the VA even if all it's members have units.

Yes, that's the real error here. Because it's defined as Group:Number instead of Group:Number:Power it should never show the VA in MainUI unless the state description pattern is set to show it, which it isn't in this case.

dilyanpalauzov commented 1 year ago

https://www.openhab.org/docs/configuration/items.html#state-presentation says that the information between [ and ] it items is used by the UIs (plural). Moreover it is unclear from the explanation above how to add "State Description" to the item using a configuration .items file.

I was not aware that after Group:Number and before :SUM there can be a dimension. The change https://github.com/openhab/openhab-docs/pull/2078 shall make this clearer.

rkoshak commented 1 year ago

it items is used by the UIs (plural)

Yes, at the time that was written it's was used by ClassicUI, BasicUI, HABPanel, and HABot.

Now there is no ClassicUI and MainUI uses the State Description Item metadata instead. Maybe the docs should be updated to say "most UIs".

Moreover it is unclear from the explanation above how to add "State Description" to the item using a configuration .items file.

You don't have to add it to the Items in the .items file. Since the State Description is only used by MainUI (in OH 4, in OH 3 the pattern field can also impact the default unit of the Item) you may as well add it there.

If you want to add it to the Item in a .items file see https://www.openhab.org/docs/concepts/items.html#item-metadata. I'm not sure if all the fields of the stateDescription metadata are in the docs yet so the easiest is to add the metadata through MainUI, click on the "Code" tab and you'll see the metadata as YAML. For example

value: " "
config:
  pattern: "%.0f %%"

which, following the link above would translate to

stateDescription=""[pattern="%.0f %%"]

When it comes to defining default widgets the metadata gets really complex so I recommend not defining those through .items files.

dilyanpalauzov commented 1 year ago

Thanks for your answer. Today I still have the group-item (Group:Number:Power:SUM abc "ABC [%d VA]" ["Power", "Measurement"] ). It does not have a state description, contains an Item (Number:Power sth "i_am_null" (abc) ["Power", "Measurement"] ), which item has state/value NULL. The group contains also an additional item. In Main UI the group item displayed with a number followed by VA. So apparently the [%d VA] presentation from .items file is used in Main UI/Semantic Web. It sometimes works and sometimes does not work in OH3.4.2.

Can this item-related metadata be stored in both jsondb and files, when the the item is stored in a file? What happens, if the item-file contains no meta data (state description), then metadata is added over Main UI to jsondb and finally different metadata is added to the item̀-file?

https://community.openhab.org/t/oh3-add-metadata-to-items-via-configuration-files/112843 describes how to add metadata to .itemm files.