Xiaomi Door Sensor, channel, item group --> Window open alarm

Hi everybody

I equiped all of my doors and windows with Xiaomi door/window sensors a year a go. It works great! As winter arrives quite fast and the heating works heavily, I would like to use the timer functionality of the sensors to alarm, when a window remains open for longer than 5 minutes.

Therefore I set the Item

Number WindowSwitch_AlarmTimer <clock> { channel="mihome:sensor_magnet:<ID>:isOpenAlarmTimer" }

via system start rule to 5 minutes for every sensor.

When using the alarm in a rule, rule trigger seems to be

Channel "mihome:sensor_magnet:<ID>:isOpenAlarm" triggered ALARM

–> a channel and not an item.

Because I have a lot of sensors, I intended to use the group item and functions for grouping these channels and write the notification rule once (makes adding new items easier).

As groups work for Items now my question:

Is ist possible to define an Item like?

Something Xi_TFS_Eingang_Alarm "Eingangsalarm"  <contact> (gTFS) { channel="mihome:sensor_magnet:158d00027b3547:isOpenAlarm" }

What would be the type of the item?

Thanks a lot in advance


You will see this in the PaperUI under the channel

For example:


This channel can be liked to a Switch item

Hello vzorglub

Thanks a lot for your help.

Unfortunately this is not possible… Under my thing, I see all the possible channels. All of them are likable to an Item except isOpenAlarm… linking is denied.

I have defined all things and items manually in .things and .items files… I could try to define manually… but I don’t want to shoot the server…

Thx Jan

hi @dark_mc, you cannot group event channels. easiest way would be to write the rule with “or” conditions:

rule "<RULE_NAME>"

Hi Dimalo

Thanks a lot for your reply… I did it finally with OR as you are suggesting. Unfortunately this has the disadvantage, that I’m not able to identify within the rule, which of the channels has fired to write a specific message like “Window A open for too long” or “Window B open for too long”.

Maybee I have to write a rule for every channel for specific messages…


Take a look at the design pattern “working with groups in rules”.

Here is how I solved this:

Contact DoorSensor1_Status_WC "Fenster WC [MAP(de.map):%s]" <window> (gContact)  { channel="mihome:sensor_magnet:xiaomi:DoorSensor1:isOpen"}
Contact DoorSensor2_Status_Wohnzimmer "Tür Küche [MAP(de.map):%s]" <window> (gContact)  { channel="mihome:sensor_magnet:xiaomi:DoorSensor2:isOpen" }


rule "Fenster Alarm"
    Channel "mihome:sensor_magnet:xiaomi:DoorSensor1:isOpenAlarm" triggered ALARM or
    Channel "mihome:sensor_magnet:xiaomi:DoorSensor2:isOpenAlarm" triggered ALARM
    //format event
	var String chnl = String::format("%s", receivedEvent)
	//get ID
    val contact = chnl.split(":").get(3)
	//find contact switch for ID
    val contactSwitch = gContact.members.findFirst[ t | t.name.split("_").get(0) == contact ] as ContactItem
	//get room name
    val room = contactSwitch.name.split("_").get(2) 
    logInfo("contact", "Fenster im "+ room +" hat Alarm getriggert!")

Hej @jimSelf

Thanks a lot for this very interesting solution!

Unfortunately after moving to OH3 my isOpenAlarm trigger isn’t working anymore! As far as I was able to identify via log Xiaomi Contact Sensor is firing, but within OH3 the trigger is not processed…
See OH3: Xiaomi Sensor Channel isOpenAlarm not working anymore?

Have you experienced the same problem?


No, I haven’t migrated or even tried OH3 yet…
Have you tried to add some more logging to your rule to track down the issue? Especially adding an else statement with a log message to make sure, the if comparison still works as expected?

I have OH3 (Build #2142) and this channel is working:
2021-01-16 15:17:12.803 [INFO ] [openhab.event.ChannelTriggeredEvent ] - mihome:sensor_magnet_aq2:f0b429cc84c0:158d0001xxxxx:isOpenAlarm triggered ALARM
I have seen this in the log in many previous versions of OH3.

Hi All

Thanks a lot for you replies!

@ip-ua : you are using the Aqara Sensor Magnet (square ones) I’m using the Mi home ones (round). I tied to add the _aq2 extension to mines, but this does not work at all…

@jimSelf : Yes I tried this, the defined rule is not firing.

rule "TFS Reminder Wohnen links"
    Channel "mihome:sensor_magnet:7811dcxxxx:158d000xxxx:isOpenAlarm" triggered ALARM
    logInfo("Fensteralarm", "Rule for WohnenLinks fired")
    var naOutdoorTemp6 = (Netatmo_Outdoor_Temperature.state as Number)
    //logInfo("Test für Rule", "Netatmo ist: " + naOutdoorTemp6 + " der Eckwert ist: " + Cv_TFS_Alarm_Temperature)
    if (naOutdoorTemp6.state < Cv_TFS_Alarm_Temperature) {
        sendBroadcastNotification("TFS Reminder: Wohnzimmerfenster links schliessen")
        logInfo("TFS Reminder", "Wohnzimmerfenster links schliessen")

But I know, that the isOpenAlarm is firing:

2021-01-17 14:46:06.809 [TRACE] [internal.handler.XiaomiBridgeHandler] - Received message {"cmd":"report","model":"magnet","sid":"158d0001xxxx","short_id":9500,"data":"{\"no_close\":\"60\"}"}
2021-01-17 14:46:06.811 [TRACE] [internal.handler.XiaomiBridgeHandler] - Updated "last time seen" for device 158d0001xxxx
2021-01-17 14:46:06.820 [DEBUG] [rnal.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"report","model":"magnet","sid":"158d0001xxxx","short_id":9500,"data":"{\"no_close\":\"60\"}"}

It seems that this alarm does not reach the rules…



  version: 3.1.0
  buildString: "Build #2147"
locale: de_CH
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 11.0.9
  javaVendor: Azul Systems, Inc.
  javaVendorVersion: Zulu11.43+88-CA
  osName: Linux
  osVersion: 5.4.83-v7l+
  osArchitecture: arm
  availableProcessors: 4
  freeMemory: 97586648
  totalMemory: 256225280
  - deconz
  - hue
  - lametrictime
  - mihome
  - miio
  - mystrom
  - netatmo
  - sonos