openhab / openhab-webui

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

Humidity values in percentage on location card are rendered incorrectly for the badge #2161

Open FSeidinger opened 9 months ago

FSeidinger commented 9 months ago

Humidity values in percentage on location card are rendered incorrectly for badge and details

Given is an item defined to hold a humidity value. Then the item is rendered correctly in different places:

image image image

But is not rendered correctly for the badge in the location card:

image image

Here the value shows up as 1 %. Looks like it is wrongly scaled and tries to show 0.59 rounded up as 1 %.

But again rendered correctly in the details of the location card:

image

Expected behavior

The badge value should be rendered as 59 %.

Steps to reproduce

Define an item like as a dimensionless number:

label: Wohnzimmer Luftfeuchtigkeit
type: Number:Dimensionless
category: humidity
groupNames:
  - Wohnzimmer_Klima
  - Zentralfunktionen_Persistenz_Stuetzpunkte_Haeufig
groupType: None
function: null
tags:
  - Measurement
  - Humidity

with a State description formatting it as a percentage value:

value: " "
config:
  pattern: "%d %%"
  readOnly: true
  1. Open the openHAB main ui
  2. Switch to the location card
  3. Look at the badge of the humidity value
  4. Click on the card
  5. Look at the badge of the humidity value

Your environment

runtimeInfo:
  version: 4.0.3
  buildString: Release Build
locale: de-DE
systemInfo:
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 17.0.8.1
  javaVendor: Private Build
  osName: Linux
  osVersion: 5.15.0-87-generic
  osArchitecture: amd64
  availableProcessors: 1
  freeMemory: 144854240
  totalMemory: 515899392
  startLevel: 100
addons:
  - automation-jsscripting
  - binding-astro
  - binding-homematic
  - binding-icalendar
  - binding-knx
  - binding-lgwebos
  - binding-mqtt
  - binding-samsungtv
  - binding-unifi
  - binding-yamahareceiver
  - misc-openhabcloud
  - persistence-jdbc-postgresql
  - persistence-mapdb
  - transformation-jinja
  - transformation-jsonpath
  - transformation-map
  - transformation-scale
  - ui-habpanel
clientInfo:
  device:
    ios: false
    android: false
    androidChrome: false
    desktop: true
    iphone: false
    ipod: false
    ipad: false
    edge: false
    ie: false
    firefox: false
    macos: false
    windows: true
    cordova: false
    phonegap: false
    electron: false
    nwjs: false
    webView: false
    webview: false
    standalone: false
    os: windows
    pixelRatio: 1
    prefersColorScheme: light
  isSecureContext: true
  locationbarVisible: true
  menubarVisible: true
  navigator:
    cookieEnabled: true
    deviceMemory: 8
    hardwareConcurrency: 16
    language: de-DE
    languages:
      - de-DE
      - de
      - en-US
      - en
      - it-IT
    onLine: true
    platform: Win32
  screen:
    width: 2560
    height: 1440
    colorDepth: 24
  support:
    touch: false
    pointerEvents: true
    observer: true
    passiveListener: true
    gestures: false
    intersectionObserver: true
  themeOptions:
    dark: light
    filled: true
    pageTransitionAnimation: default
    bars: filled
    homeNavbar: default
    homeBackground: default
    expandableCardAnimation: default
  userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
    like Gecko) Chrome/119.0.0.0 Safari/537.36
timestamp: 2023-11-03T17:28:12.286Z

Browser console

Browser network traffic

image image

lolodomo commented 6 months ago

You just have to set unit to "%" for your item and it will work. This is a classical error for users moving from OH 3.4 to OH 4.x. IMHO, the issue can be closed.

FSeidinger commented 6 months ago

The unit is set to dimensionless and the state description to "%d %%". I changed it to "%d %" but still it shows the incorrect values on the badge.

lolodomo commented 6 months ago

The problem is not your state description but your item unit. Set item unit to "%".

FSeidinger commented 6 months ago

I do not know what you mean. There is no unit property on the item. Only a type and the type is "Number:Dimensionless" which is correct for percentage values. All other visualisations do not have a problem with showing the correct value. Only the badge does.

lolodomo commented 6 months ago

In case your item was created with Main UI, it is the 5th field named "Unit", just replace default value "one" by "%":

image

In case your item is defined in file, just set the unit like for example:

Number:Dimensionless HumiditeExt "Humidité extérieure [%d %%]" <humidity> [ "Measurement", "Humidity" ] {channel="netatmo:outdoor:compte:station:exterieur:humidity#value", unit="%"}
lolodomo commented 6 months ago

Unit is a metadata. When editing the item:

image

lolodomo commented 6 months ago

You could have asked and found help on the community forum.

FSeidinger commented 6 months ago

In case your item was created with Main UI, it is the 5th field named "Unit", just replace default value "one" by "%":

image

In case your item is defined in file, just set the unit like for example:

Number:Dimensionless HumiditeExt "Humidité extérieure [%d %%]" <humidity> [ "Measurement", "Humidity" ] {channel="netatmo:outdoor:compte:station:exterieur:humidity#value", unit="%"}

I guess that covers the the creation of new items with OH version 4.x. If you already have items and upgrade to OH 4.x then the items do not have a unit and on the edit page there is not unit property you can set. So I guess it is more or less a migration topic.

Unit is a metadata. When editing the item:

image

And that it is how it is presented to an upgraded item. It is no property, it is in reality a meta data type. And this is how the migration issue is solved. Not to enter or edit a property but adding a new meta date type.

Thanks for the solution. And If you point me in the right direction I would happily add a migration or documentation part for changing the unit for items that do not have any.

rkoshak commented 5 months ago

Thanks for the solution. And If you point me in the right direction I would happily add a migration or documentation part for changing the unit for items that do not have any.

This was discussed at some length in the breaking changes section of the release notes for OH 4.0. https://github.com/openhab/openhab-distro/releases/tag/4.0.0#breaking-changes-that-require-manual-interaction-after-the-upgrade including instructions for migration both managed and text file defined Items.