[SOLVED] Xiaomi Door sensor sometimes doesn't report

Tags: #<Tag:0x00007fc3edd72590> #<Tag:0x00007fc3edd72478> #<Tag:0x00007fc3edd723b0>

Hi,

I have the following item declared in openhab:

Contact DoorSensor "Door sensor" {channel="mihome:sensor_magnet:XXXXXXXXX:isOpen"}

With the following rule:

rule "Door Sensor OPEN"
when
  Item DoorSensor changed to OPEN
then
    sendTelegram("XXXXXX","Main Door "+ DoorSensor.state)
    executeCommandLine("XXXXX")
    Gateway_Brightness.sendCommand(100)
    sendCommand(Gateway_Volume, 40)
    sendCommand(Gateway_Sound, 10)
    createTimer(now.plusSeconds(10), [| 
    		sendCommand(Gateway_Sound, 10000)
    		sendCommand(Gateway_Volume, 0)
    		Gateway_Brightness.sendCommand(0)
	])
    
end

rule "Door Sensor CLOSED"
when
  Item DoorSensor changed to CLOSED
then
    sendTelegram("XXXXXXX","Main Door "+ DoorSensor.state)
end

I have configured the Xiaomi App to show a notification when the door opens.
Sometimes the sensor doesn’t fire the events with openHAB, but it reports notifications with the Xiaomi App.

Does anyone know why this happen?

[UPDATE]

I’m attaching two videos: are from the same moment. You can see the sensor does not report and later it starts reporting… This is strange right?

Post your log please.
Change to

sendTelegram("XXXXXX","Main Door "+ DoorSensor.state.toString)

Gateway_Brightness, Gateway_Volume and Gateway_Sound are number-items?

1 Like

What I’ve tried now is just only to bind the item and see in the log if it reports the item status. As you can see is not working always…

No rules nor items defined, just the PaperUI binding.

==> /var/log/openhab2/events.log <==
2018-08-01 15:18:07.546 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from CLOSED to OPEN
2018-08-01 15:18:07.567 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_lastOpened changed from 2018-08-01T11:05:27.822+0200 to 2018-08-01T15:18:07.541+0200
2018-08-01 15:18:09.358 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from OPEN to CLOSED
2018-08-01 15:18:10.620 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from CLOSED to OPEN
2018-08-01 15:18:10.626 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_lastOpened changed from 2018-08-01T15:18:07.541+0200 to 2018-08-01T15:18:10.590+0200
2018-08-01 15:18:11.402 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from OPEN to CLOSED
2018-08-01 15:18:14.045 [vent.ItemStateChangedEvent] - MotionStatus2 changed from ON to OFF
2018-08-01 15:18:17.377 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from CLOSED to OPEN
2018-08-01 15:18:17.388 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_lastOpened changed from 2018-08-01T15:18:10.590+0200 to 2018-08-01T15:18:17.363+0200
2018-08-01 15:18:18.395 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from OPEN to CLOSED
2018-08-01 15:18:19.020 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from CLOSED to OPEN
2018-08-01 15:18:19.027 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_lastOpened changed from 2018-08-01T15:18:17.363+0200 to 2018-08-01T15:18:18.989+0200
2018-08-01 15:18:20.034 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from OPEN to CLOSED
2018-08-01 15:18:20.596 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from CLOSED to OPEN
2018-08-01 15:18:20.599 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_lastOpened changed from 2018-08-01T15:18:18.989+0200 to 2018-08-01T15:18:20.574+0200
2018-08-01 15:18:21.239 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from OPEN to CLOSED
2018-08-01 15:18:25.635 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from CLOSED to OPEN
2018-08-01 15:18:25.643 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_lastOpened changed from 2018-08-01T15:18:20.574+0200 to 2018-08-01T15:18:25.625+0200
2018-08-01 15:18:29.875 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from OPEN to CLOSED
2018-08-01 15:18:30.635 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from CLOSED to OPEN
2018-08-01 15:18:30.643 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_lastOpened changed from 2018-08-01T15:18:25.625+0200 to 2018-08-01T15:18:30.618+0200
2018-08-01 15:18:31.428 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from OPEN to CLOSED
2018-08-01 15:18:31.977 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from CLOSED to OPEN
2018-08-01 15:18:31.985 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_lastOpened changed from 2018-08-01T15:18:30.618+0200 to 2018-08-01T15:18:31.958+0200
2018-08-01 15:18:32.654 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from OPEN to CLOSED
2018-08-01 15:18:33.511 [vent.ItemStateChangedEvent] - network_pingdevice_10_0_0_85_latency changed from 140.0 to 151.0
2018-08-01 15:18:33.528 [vent.ItemStateChangedEvent] - network_pingdevice_10_0_0_85_lastseen changed from 2018-08-01T15:17:33.332+0200 to 2018-08-01T15:18:33.498+0200
2018-08-01 15:19:33.588 [vent.ItemStateChangedEvent] - network_pingdevice_10_0_0_85_latency changed from 151.0 to 24.0
2018-08-01 15:19:33.619 [vent.ItemStateChangedEvent] - network_pingdevice_10_0_0_85_lastseen changed from 2018-08-01T15:18:33.498+0200 to 2018-08-01T15:19:33.547+0200
2018-08-01 15:19:44.588 [vent.ItemStateChangedEvent] - MotionStatus1 changed from ON to OFF
2018-08-01 15:20:33.803 [vent.ItemStateChangedEvent] - network_pingdevice_10_0_0_85_latency changed from 24.0 to 156.0
2018-08-01 15:20:33.821 [vent.ItemStateChangedEvent] - network_pingdevice_10_0_0_85_lastseen changed from 2018-08-01T15:19:33.547+0200 to 2018-08-01T15:20:33.755+0200
2018-08-01 15:21:34.087 [vent.ItemStateChangedEvent] - network_pingdevice_10_0_0_85_latency changed from 156.0 to 282.0
2018-08-01 15:21:34.118 [vent.ItemStateChangedEvent] - network_pingdevice_10_0_0_85_lastseen changed from 2018-08-01T15:20:33.755+0200 to 2018-08-01T15:21:34.047+0200
2018-08-01 15:22:34.169 [vent.ItemStateChangedEvent] - network_pingdevice_10_0_0_85_latency changed from 282.0 to 19.0
2018-08-01 15:22:34.206 [vent.ItemStateChangedEvent] - network_pingdevice_10_0_0_85_lastseen changed from 2018-08-01T15:21:34.047+0200 to 2018-08-01T15:22:34.131+0200



2018-08-01 15:23:03.214 [vent.ItemStateChangedEvent] - TemperatureValue changed from 23.989999771118164 to 24.270000457763672
2018-08-01 15:23:03.269 [vent.ItemStateChangedEvent] - HumidityValue changed from 74.05999755859375 to 74.83999633789062
2018-08-01 15:23:12.375 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from CLOSED to OPEN
2018-08-01 15:23:12.388 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_lastOpened changed from 2018-08-01T15:18:31.958+0200 to 2018-08-01T15:23:12.353+0200
2018-08-01 15:23:12.659 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from OPEN to CLOSED
2018-08-01 15:23:12.860 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from CLOSED to OPEN
2018-08-01 15:23:12.871 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_lastOpened changed from 2018-08-01T15:23:12.353+0200 to 2018-08-01T15:23:12.832+0200
2018-08-01 15:23:13.236 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from OPEN to CLOSED
2018-08-01 15:23:34.279 [vent.ItemStateChangedEvent] - network_pingdevice_10_0_0_85_latency changed from 19.0 to 51.0
2018-08-01 15:23:34.327 [vent.ItemStateChangedEvent] - network_pingdevice_10_0_0_85_lastseen changed from 2018-08-01T15:22:34.131+0200 to 2018-08-01T15:23:34.237+0200
2018-08-01 15:23:40.831 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from CLOSED to OPEN
2018-08-01 15:23:40.840 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_lastOpened changed from 2018-08-01T15:23:12.832+0200 to 2018-08-01T15:23:40.809+0200
2018-08-01 15:23:41.958 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from OPEN to CLOSED
2018-08-01 15:23:42.823 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from CLOSED to OPEN
2018-08-01 15:23:42.833 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_lastOpened changed from 2018-08-01T15:23:40.809+0200 to 2018-08-01T15:23:42.782+0200
2018-08-01 15:23:43.797 [vent.ItemStateChangedEvent] - mihome_sensor_magnet_158d000213392e_isOpen changed from OPEN to CLOSED
rule "Door Sensor OPEN"
when
  Item DoorSensor changed to OPEN
then
  logInfo("___","rule Door Sensor OPEN"
  ...

rule "Door Sensor CLOSED"
when
  Item DoorSensor changed to CLOSED
then
  logInfo("___","rule Door Sensor CLOSED"
  ...

and post please, the log that the rule-file was refreshed correctly (and the folowing lines).

2018-08-01 14:31:57.557 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'xxx.rules'

The following item declared:

Contact TestDoorSensor "DoorSensor Testing" {channel="mihome:sensor_magnet:158d000213392e:isOpen"}

And now, the log.

2018-08-01 16:05:23.257 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.rules'
2018-08-01 16:05:34.796 [INFO ] [g.eclipse.smarthome.model.script.___] - rule Door Sensor OPEN
2018-08-01 16:05:35.127 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'default.rules', using it anyway:
The value of the local variable ts is not used
2018-08-01 16:05:35.363 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'default.rules'
2018-08-01 16:05:41.309 [INFO ] [g.eclipse.smarthome.model.script.___] - rule Door Sensor CLOSED
2018-08-01 16:05:43.655 [INFO ] [g.eclipse.smarthome.model.script.___] - rule Door Sensor OPEN
2018-08-01 16:05:44.384 [INFO ] [g.eclipse.smarthome.model.script.___] - rule Door Sensor CLOSED
2018-08-01 16:05:44.782 [INFO ] [g.eclipse.smarthome.model.script.___] - rule Door Sensor OPEN
2018-08-01 16:05:45.388 [INFO ] [g.eclipse.smarthome.model.script.___] - rule Door Sensor CLOSED
2018-08-01 16:05:45.573 [INFO ] [g.eclipse.smarthome.model.script.___] - rule Door Sensor OPEN
2018-08-01 16:05:46.136 [INFO ] [g.eclipse.smarthome.model.script.___] - rule Door Sensor CLOSED
2018-08-01 16:05:46.315 [INFO ] [g.eclipse.smarthome.model.script.___] - rule Door Sensor OPEN
2018-08-01 16:05:46.737 [INFO ] [g.eclipse.smarthome.model.script.___] - rule Door Sensor CLOSED

The problem I have is that sometimes rules are not executed as shown in the video. And this behavior is random. It can be something with the xiaomi hab?

Thanks

The DoorSensor state is changed every second to OPEN and CLOSED. If you don’t do that on another place in your rule, it comes from the channel.

Remove the binding configuration for this item in the items-file and do it only in the PaperUI. Use PaperUI / Control to see what happened.

Thanks for your reply @hr3.
That’s my first post with the video attached… Sometimes state changes and sometimes not…
I don’t know how to debug this issue…

@hr3 I can see sometimes

2018-08-03 12:51:12.089 [hingStatusInfoChangedEvent] - 'mihome:sensor_ht:XXXXXXXX' changed from ONLINE to OFFLINE

Do you know why is this?
Maybe this is the root cause for my sensor not working…?

Thanks

After a lot of investigation I came to the conclusion that there was a problem in my WiFi environment.

I checked with an OH binding the latency to my gateway, and it was something like this:

photo_2018-08-27_08-52-42

You can see it is always varying from 20ms to 400ms randomly.

I changed my WiFi access point to a different one, and here are the results with the latency:

chart

After that, I’ve checked in the log if they come OFFLINE again and no trace since my AP change.

So… it seems it’s solved!

Thanks

1 Like

I see I am not the only person that has Wi-Fi issue. Glad you solved!

I have pretty similar problem, that you did. Sometimes my sensor just doesn’t trigger OH, but it works correctly in Mi Home App. Though I don’t think this is the problem with high latency, because I can controll other devices in my home via the Gateway without any problem. The door sensor is the only problem here.