Convert String to "contact" to use with Homekit

I use OH 2.5.4 on a PC Engines Board running ubuntu 20.04
I have a modbus-conection to my intrusion-system to get information about door and window contacts. To link to a readable format i use the following .map

32769=offen
32768=zu
32770=Sabotage
32772=Deaktiviert
32777=Alarm offen
32776=Alarm geschlossen
NULL=unknown

Things-config:
Bridge poller holding [ start=10011, length=4, refresh=5000, type=“holding” ] {

  •    Thing data AL_RK_EINGANG [ readStart="10011", readValueType="uint16", readTransform="MAP(EMA.map)" ]*
    

Items-config:
String AL_RK_EINGANG “Eingang RK” (EMA, EMA_EG) [“ContactSensor”] { channel=“modbus:data:ema:holding:AL_RK_EINGANG:string”}

This configuration works fine for OpenHab while in HomeKit this contact allways is show as closed.

Do I have to convert this Item from string to contact? If so, how can I manage this?
Thanks for any hint.

A Contact type Item can have only states OPEN and CLOSED (well, and NULL or UNDEF)

How would you like to to map your six different states to those two choices?

I think I would create another modbus data Thing, using the same register, but with a different MAP to your choice of OPEN/CLOSED, and link this new data Thing to a Contact Item for Homekit to look at.

HomeKit can use string item as ContactSensor but it expects value “Open” or “Opened” for OPEN, everything else considered as CLOSED. currently these values, “Open” and “Opened” cannot be changed or configured.

What you can do is to create a new contact item for homekit and a rule to updated it.
e.g.
item

Contact door "Door" ["ContactSensor"]

and rule

rule "AL_RK_EINGANG received update"
when
    Item AL_RK_EINGANG received update
then
    if(AL_RK_EINGANG.state.toString.contains("offen")) {
        door.postUpdate(OPEN)
    }
    else {
        door.postUpdate(CLOSED)
    }
end
1 Like

This works perfectly! Many thanks!

Sorry, I forgot to describe my intent.
I only want to know if all doors and windows are closed. So for homekit I don’t care about the other status.