I’ve created four Channels: two for duration (so the unit is s), and two which just give a number of a count (one is a maximum, the other the actual count). But I can’t figure out how to create the Channel. What I have now, is this:
<channel-type id="APICallsRemainingThisDuration" advanced="true">
<item-type>Number:Dimensionless</item-type>
<label>API Calls remaining</label>
<description>Number of API calls remaining before the maximum is reached</description>
<tags>
<tag>Status</tag>
</tags>
<state readOnly="true" pattern="%d"/>
</channel-type>
I update that Channel by something like this:
updateState(channelName, new QuantityType<>(value, Units.ONE));
But then when this is the update instruction:
updateState(channelName, new QuantityType<>(3738, Units.ONE));
If it’s just a plain number then don’t apply the dimension. However, counter what you might think, Dimensionless isn’t “without dimension”. That’s the name of the dimension for ratios. Therefore, you should only use Number:Dimensionless for ratios (i.e. percent, decibel, or ONE which is a simple ratio).
What I think is happening is the Channel is reporting the number in a unit of ONE. But the Item has a unit of %.
X ONE == X*100 %
The count is being converted to percent by multiplying by 100.
This Channel represents a count, not a ratio. Therefore, the type should be Number, not Number:Dimensionless.
Maybe that’s something that can be mentioned in the documentation? I was thinking of making a PR, but a lot of the subtleties in the documentation are beyond me, so I don’t feel confident adding anything anywhere…
To express measured values in a scientific correct unit the framework supports units of measurement. By using quantified decimal values in state updates and commands, the framework is able to automatically convert values to a desired unit which may be defined by the system locale or on a per-use-basis.
And under the list of units it lists three units supported by Dimensionless.
Dimensionless
Percent
%
Dimensionless
Parts per Million
ppm
Dimensionless
Decibel
dB
I’m not sure why ONE isn’t listed too. It should be. But if Dimensionless meant “no dimension” then it wouldn’t make sense to list these units under it.
Note, the name “Dimensionless” came from the upstream library OH uses for this. We didn’t invent that name.
If you go to the Items page you see that Number and Number:Dimension are listed separately.
Number
Stores values in number format, takes an optional dimension suffix
Decimal, Refresh
Number:
like Number, additional dimension information for unit support
Quantity, Refresh
I’m not sure where an addition to the docs would go to explain that “Dimensionless” is a Number with a ratio as it’s units.
I could see a new unit being added for “Count” but all the units I can think of are kind of obscure and not all that useful (does anyone doing home automation need to count things in dozens or score?).