I’d have expected that numbers formated as percent in the items file would be converted (displayed as a multiple of 100). Is my expectation or something in my code wrong?
Number Heizung_Stellwert_EG_Flur "Heizung Stellwert EG Flur [%d]" (EG_Flur, Temperatur, Temperatur_EG) {channel="knx:device:MDTBridge:MDT_AKH_EG:Kanal_C_stell"}
Number Heizung_Stellwert_EG_Flur_test "Heizung Test Stellwert EG Flur [%d %%]" (EG_Flur, Temperatur, Temperatur_EG) {channel="knx:device:MDTBridge:MDT_AKH_EG:Kanal_C_stell"}
Heizung_Stellwert_EG_Flur delivers 1.0 (=100%) [as expected]
Heizung_Stellwert_EG_Flur_test delivers 1 % (instead of 100%)
Source KNX channel delivers a percentage which is recognized by openHAB as 1.0 (seen in log from ItemStateChangedEvent)
Am I missing something or is the conversion not working?
The % sign is like a degrees or $, it’s just a display unit. The decimal value you give it just has the % tacked on the end, there’s no mathematical calculation as part of using that sign. Your value has to have been converted into the percentage first.
I’ve got the same problem. KNX1 binding is working well with DPT 5.001, 8bit unsigned percentage values, but KNX2 binding stores the value as a float between 0 and 1. That’s ok, but I have not found at least one pattern to show the “real” percentage value between 0 and 100.
Right now I do not know any trick to convert the value into percentage values. It’s really annoying creating rules or lambdas for that purpose, isn’t it?
Yes, definitly. That was exactly the purpose of my question. I try to avoid rules for tivial things wherever possible (exec binding is anoying there as well with its missing feature to return a number instead of string only)
Okay, a Number Item is a Number Item and knows nothing about percentages.
You can’t put a value “1.0” into it and expect it to be recognized as meaning 100%. It’s just a number. You can choose to display it with a % symbol, but it’s still just a number.
Why KNX represents 100% as 1.0, I do not know. Question for KNX protocol -designer. It’s not unreasonable to use a fraction to express it, 0.0 - 0.5 - 1.0 instead of 0% 50% 100%. But that’s the rules of KNX and we can’t change that.
What OpenHAB provides you with is an Item type called Dimmer. This understands percentages, as well as ON/OFF. When you link that kind of Item to a KNX channel with percentages, the binding is smart enough to sort out the conversion between KNX idea of a portion and OpenHABs.
Whether the Item is really a light dimmer, or a heater, or a motor speed control is pretty irrelevant. You can label it what you like. ‘Dimmer’ is just shorthand for ‘a thing that works in a 0% to 100% range’
Number Heizung_Stellwert_EG_Flur_test "Heizung Test Stellwert EG Flur [%d %%]"
[%d %%] is not formatting anything as a percentage. It just says display the number with a % sign. No conversion would be carried out if you decided to display it with the word ‘percent’, or a $ sign.
The Number type Item cannot know how to do percentage conversions, For any given data source, 100% might be 1.0 , or 100 , or 255 etc.
Anyway, clearly the OH KNX binding knows what to do with percentages, as we can tell by the way it works properly with Dimmer type OH Items.
An obvious thing to do is to use a Dimmer type OH Item with a dimmer KNX channel. I guess you have some reason not to do that. What is your KNX channel device type defined as?
An alternative might be where some bindings allow the use of a transform between raw data and OH Item useful for conversions. So far as I know, KNX binding does not support transforms.
Another alternative might be to use the new-ish units of measurement feature of OH. Percentage can be assigned as a QuantityType to a Number Item.
It’s the binding that does the work of initial conversion, so you would need the
KNX-2 binding to support UoM .
I do not think the binding yet supports UoM, but it would seem like a useful feature to raise an enhancement request for.
Has anyone a solution for that? Using OH 2.4 M4 and there is no change. Also have a MDT AKH and the percentage is delivered between 0.01 and 1.00 and the KNX2 Binding does not convert this.
I ran into the same issues after migrating from KNX 1.x binding to KNX 2.x binding. As rossko57 mentioned …
[%d %%] is not formatting anything as a percentage. It just says display the number with a % sign. No conversion would be carried out if you decided to display it with the word ‘percent’, or a $ sign.
The Number type Item cannot know how to do percentage conversions, For any given data source, 100% might be 1.0 , or 100 , or 255 etc
It looks to me, like any relative value, KNX DPT 5.x, will be processed as values between 0.00 and 1.00, All of my MDT actors relative values are represented that way running KNX 2.x binding: Heating actors, rollershutters, dimmers, etc.
The openHAB sitemap elements are running as expected without any changes. If you really have to show percentage values as numbers from 0 up 100, I guess, you’ll have to write down some rules for the items’ values you want to convert. I’d do so with lambdas for converting values from 0.00 up 1.00 to 0 up to 100 and vice versa.
But to be honest: Where do I have to show percentage values as numbers? For UIs I decided to show gauges or graphs, right? So I just had to modify my Graphana panels to show the information as expected. That was quite easy.
I’ll let you know if I find out any other solution, ok?
Hm, DPT 5.001 is defined as Percentage, so I would expect the binding to pass the value in the correct format to OH, so that it receives a percentage value and not a fraction (decimal).
As there are other Posts available, reporting Problems with passing values to DPT 5.001, maybe there is actually some minor bug in the binding? I have created an issue on Github (https://github.com/openhab/openhab2-addons/issues/4146), maybe somebody from the Magician Team (aka developers :-)) can have a look?
I played around and changed ga from 5.001 to 9.001 and now I was able to see the data on the bus but with two decimal digits as described above, I think this is related to KNX datatype.
This does not solved my issue
After changing everythig to a dimmer I was able to see the data in percent :
Type number : Lueftung_Humidity_Extract [ ga=5.001:<30/1/31 ]
The items are defined as: Number:Dimensionless Lueftung_Humidity_Extract "Extract [%d %%]" (gLueftung, gLueftung_Humidity) { channel="knx:device:bridge:lueftung_medium_poll:Lueftung_Humidity_Extract" }
Openhab reads in the value as float: 16:21:01.019 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Lueftung_Humidity_Extract' changed from NULL to 0.57 %
results in an error: 16:26:40.228 [WARN ] [se.internal.SseItemStatesEventBuilder] - Exception while formatting value '0.57 %' of item Lueftung_Humidity_Extract with format '%d %%': d != java.math.BigDecimal