Number item and percentage

Hi all,
I was wondering for quite some time why a number item when feed by a PercentType would always be displayed as a value between 0 and 1 e.g. 0.24 and not 24.
This seems to be idependant of the UI.
Example using BasicUI and KNX:

Number ventilPosition "Ventilposition [%.2f %%]"    (gVentilPos) { channel="knx:device:bridge:regler:ventilPosition" }

displayed is 0.24 % expected: 24.00 %

Only when I modify the to have PercentType.class as an accepted type I’ll get the expected result. Since this seems to be around for a long time and I couldn’t find anything in this forum: am I missing something here?

Change to

    private static final List<Class<? extends State>> ACCEPTED_DATA_TYPES = List.of(DecimalType.class,
            **PercentType.class,** QuantityType.class, UnDefType.class);
    private static final List<Class<? extends Command>> ACCEPTED_COMMAND_TYPES = List.of(DecimalType.class,
            **PercentType.class,** QuantityType.class, RefreshType.class);

What’s the channel type? Linking different channel/Item types might be expected tolead to odd results.

It’s number.

Here’s the thing:

 Thing device regler "Heizungsregler" @ "Heizungsregler" [
    ] {
        Type number : ventilPosition  "Ventilposition" [ ga="5.001:<8/3/11" ]

Okay, so that’s straightforward, it’s just a number channel, that’s what the KNX channel gives you.

I think you should be using a Dimmer Item and dimmer channel for that DPT? (or rollershutters)

I sure got that. But …, making number item accept PercentType solves this (my) issue.
I’m just not sure why this wasn’t done before and if this change would have side effects.

Doesn’t make a lot of sense.
There is a Number:Dimensionless Item type exactly intended for arbitrary “ratios” like % or ppm.
But for actuators like dimmers, speed controls, positioners, where it is limited to 0-100% this is exactly what the dimmer/rollershutter types are for.

I don’t really agree. A number is a number even if it has a range.
But nevertheless thank you for the discussion!

I’ll keep that change on my fork.

You do get a number, you just don’t like it. 0.25 is the same as 25% but expressed without units, it’s just a factor.

We don’t have to agree; if you think there’s merit in it, pop in an enhancement request on Github for openHAB core.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.