currently I am trying to update the state of an item with type Number:Dimensionless. The logging shows that I get the correct number (19) but when I update the state of my item a value of 0.19 is shown.
Is this the intended behavior for percentage values?
If yes could you please give me a hint how I can format it in the UI to show it as ‘19 %’?
2023-04-02 14:32:20.184 [INFO ] [inding.devolo.internal.DevoloHandler] - try to update channel stats-cpu
2023-04-02 14:32:20.184 [INFO ] [inding.devolo.internal.DevoloHandler] - new value 19 for channel stats-cpu
2023-04-02 14:32:20.185 [INFO ] [inding.devolo.internal.DevoloHandler] - int value 19 for channel stats-cpu
In code I set the value as follows:
...
case STATS_CPU_CHANNEL:
value = dataState.getProperty(STATS_CPU_KEY);
logger.info("new value {} for channel {}", value, channelID);
int cpuLoad = Integer.valueOf(value);
logger.info("int value {} for channel {}", cpuLoad, channelID);
state = new PercentType(cpuLoad);
updateState(channelID, state);
break;
Add a literal ‘%’ to your log command.
Don’t confuse your debug output with all the conversion stuff going on when you display an item in a widget or sitemap.
I don’t want to add the ‘%’ to my log comments.
I would like that the state of the item is displayed as ‘19 %’ in a UI widget.
Changing the state description pattern for example to ‘%d%%’ (with or without a space) still shows 0.19.
Any idea what I am doing wrong?
I use the 4.0.0-SNAPSHOT docker image: openHAB 4.0.0 Build #3387
Query the item via API results in the following JSON document: