KNX byte datapoint to switch

Hi,

I have a KNX device that reports its mode with a datapoint of type “byte”. Possible values are 0, 1, 2 and 3. I want to manage these values in the UI with a switch with a corresponding mapping.

If I use a channel and an item of type “Number”, I get values with a decimal fraction, like “0.0”, “1.0” …

This is my configuration and it does not work (no button is shown as “selected” because “0.0” != “0” ):

// channel in "things" file
Type number : ch3_mode                    [ ga="5.005:<3/1/152" ]
// item in "items" file
Number Some_Mode "Mode"          { channel="knx:device:mdt:IB1:ch3_mode" }
// sitemap
Switch item=Some_Mode mappings=[0="Cool", 1="Heat", 2="Dry", 3="Vent", 4="Auto"]

I also tried using a string:

// channel in "things" file
Type string : ch3_mode                    [ ga="5.005:<3/1/152" ]
// item in "items" file
String Some_Mode "Mode"          { channel="knx:device:mdt:IB1:ch3_mode" }
// sitemap
Switch item=Some_Mode mappings=[0="Cool", 1="Heat", 2="Dry", 3="Vent", 4="Auto"]

This doesn’t work either. The item has values like “1970-01-01T00:00:00.000+0000” and “1970-01-01T00:00:01.000+0000” for the actual values “0” and “1”.

What is the correct way to map a KNX byte (integer) channel to a switch with mappings?

Edit: I am using OpenHab 2.5.

Welcome to the community!

Try with a dimmer.

Dimmer Some_Mode "Mode [%s]"          { channel="knx:device:mdt:IB1:ch3_mode" }

This is expected behaviour. The buttons respond to being poked, not Item updates.

Dimmer also returns “0.0”, “1.0” and so on as item state.

I managed to map the switch with the following configuration:

// channel in "things" file
Type number : ch3_mode           [ ga="5.005:<3/1/152" ]
// item in "items" file
Number Some_Mode "Mode"          { channel="knx:device:mdt:IB1:ch3_mode" }
// sitemap
Switch item=Some_Mode mappings=[0.0="Cool", 1.0="Heat", 2.0="Dry", 3.0="Vent", 4.0="Auto"]

The difference to my original snippet is the mapping in the sitemap, which uses now “0.0” instead of “0”.

If I use “0.0”, “1.0” and so on in the mapping in the sitemap (see my answer above) , the switch behaves as expected. Value “0” (or “0.0”) makes the button “Cool” red, value “1” makes the button “Heat” red.