Motion Sensor Rule with Illumination - Problem with Sensor

Hey guys,

I am pretty new to openHAB and I am just at the start of everything. I tried to write my first rule and it is working really well, but I got an error in my log. I am not familiar with java and so on, it is just reading and try to understand for me. Most of the topics are quite old and refer to openHAB <2.0.

Here is the rule:

var Timer FloorLightTimer = null

rule "Floor Light MotionSensor"
when
    Item MotionSensor_MotionStatusFloor changed to ON //MotionSensor turns Off after 1 minute and can then be triggered again - not sure...
then
	if ( Gateway_AmbientLight.state < 500) { //500 should be okay - 1100 for testing
		logInfo("FloorMotion","Motion detected and it is dark")
		if ( Gateway_LightSwitch.state==OFF ) {
				logInfo("FloorMotion","Turning lights on")
			sendCommand (Gateway_LightSwitch, ON)
			Thread::sleep(60000)
			sendCommand (MotionSensor_MotionStatusFloor, OFF)
				logInfo("FloorMotion","Set Motion Sensor to off")
			FloorLightTimer = createTimer(now.plusSeconds(60)) [|
				sendCommand(Gateway_LightSwitch, OFF)
					logInfo("Floor Light","Turning triggered lights off")
				FloorLightTimer.cancel
                FloorLightTimer = null ]
		} 
		else {
			FloorLightTimer.reschedule(now.plusSeconds(120))
				logInfo("FloorMotion","Reschedule timer")
			Thread::sleep(60000)
			sendCommand (MotionSensor_MotionStatusFloor, OFF)
				logInfo("FloorMotion","Set Motion Sensor to off")
		}}
	else {
		logInfo("FloorMotion","Motion detected, but it is light enough")	
	}
end

And here the log:

14:58:23.448 [INFO ] [marthome.event.ItemStateChangedEvent] - MotionSensor_MotionStatusFloor changed from OFF to ON
14:58:23.464 [INFO ] [marthome.event.ItemStateChangedEvent] - MotionSensor_LastMotionFloor changed from 2017-08-20T14:55:08.243+0200 to 2017-08-20T14:58:23.442+0200
14:58:24.152 [INFO ] [e.smarthome.model.script.FloorMotion] - Motion detected and it is dark
14:58:24.155 [INFO ] [e.smarthome.model.script.FloorMotion] - Turning lights on
14:58:24.161 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Gateway_LightSwitch' received command ON
14:58:24.166 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_LightSwitch changed from OFF to ON
14:58:24.203 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_Brightness changed from 0 to 100
14:58:24.208 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_AmbientLight changed from 741 to 747
14:58:25.077 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_AmbientLight changed from 747 to 755
14:58:31.054 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_AmbientLight changed from 755 to 803
14:58:34.059 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_AmbientLight changed from 803 to 839
14:58:50.025 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_AmbientLight changed from 839 to 963
14:59:21.957 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_AmbientLight changed from 963 to 1030
14:59:24.167 [INFO ] [e.smarthome.model.script.FloorMotion] - Set Motion Sensor to off
14:59:24.168 [ERROR] [me.handler.XiaomiSensorMotionHandler] - Channel mihome:sensor_motion:XXXXXXXX:motion does not exist
14:59:24.169 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'MotionSensor_MotionStatusFloor' received command OFF
14:59:24.178 [INFO ] [marthome.event.ItemStateChangedEvent] - MotionSensor_MotionStatusFloor changed from ON to OFF
14:59:33.943 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_AmbientLight changed from 1030 to 1079
14:59:35.187 [INFO ] [marthome.event.ItemStateChangedEvent] - MotionSensor_MotionStatusFloor changed from OFF to ON
14:59:35.197 [INFO ] [e.smarthome.model.script.FloorMotion] - Motion detected, but it is light enough
14:59:35.204 [INFO ] [marthome.event.ItemStateChangedEvent] - MotionSensor_LastMotionFloor changed from 2017-08-20T14:58:23.442+0200 to 2017-08-20T14:59:35.174+0200
14:59:35.932 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_AmbientLight changed from 1079 to 1056
14:59:51.900 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_AmbientLight changed from 1056 to 958
14:59:56.896 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_AmbientLight changed from 958 to 992
15:00:04.885 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_AmbientLight changed from 992 to 1017
15:00:24.174 [INFO ] [e.smarthome.model.script.Floor Light] - Turning triggered lights off
15:00:24.181 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Gateway_LightSwitch' received command OFF
15:00:24.194 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_LightSwitch changed from ON to OFF
15:00:24.215 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_Brightness changed from 100 to 0

I just replaced the real sensor-id with “XXXXX” - do I need to do that btw?
I am concerned about the channel, which does not exist, but in the end it changes. I added this because I think that the sensor is stuck to on when the timer runs - at least I think it does (found out at testing).

My hardware: pi 3 with openHAB, Xiaomi Gateway as light and Xiaomi Motion Sensor.

Thank you in advance.

Greetings
Andreas


Edit:

I just tested my conclusion. I guess there need to be a change in the documentation of the Xiaomi binding. Here is the log:

15:09:09.490 [INFO ] [marthome.event.ItemStateChangedEvent] - MotionSensor_MotionStatusFloor changed from OFF to ON
15:09:09.501 [INFO ] [marthome.event.ItemStateChangedEvent] - MotionSensor_LastMotionFloor changed from 2017-08-20T14:59:35.174+0200 to 2017-08-20T15:09:09.481+0200
15:09:09.911 [INFO ] [e.smarthome.model.script.FloorMotion] - Turning lights on
15:09:09.917 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Gateway_LightSwitch' received command ON
15:09:09.922 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_LightSwitch changed from OFF to ON
15:09:09.936 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_Brightness changed from 0 to 100
15:11:09.492 [INFO ] [marthome.event.ItemStateChangedEvent] - MotionSensor_MotionStatusFloor changed from ON to OFF
15:14:09.925 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Gateway_LightSwitch' received command OFF
15:14:09.930 [INFO ] [e.smarthome.model.script.Floor Light] - Turning triggered lights off
15:14:09.951 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_LightSwitch changed from ON to OFF
15:14:09.955 [INFO ] [marthome.event.ItemStateChangedEvent] - Gateway_Brightness changed from 100 to 0

Tested with that:

var Timer FloorLightTimer = null

rule "Floor Light MotionSensor"
when
    Item MotionSensor_MotionStatusFloor changed to ON //MotionSensor turns Off after 1 minute and can then be triggered again - not sure...
then
	if ( Gateway_LightSwitch.state==OFF ) {
				logInfo("FloorMotion","Turning lights on")
			sendCommand (Gateway_LightSwitch, ON)
			FloorLightTimer = createTimer(now.plusSeconds(300)) [|
				sendCommand(Gateway_LightSwitch, OFF)
					logInfo("Floor Light","Turning triggered lights off")
				FloorLightTimer.cancel
                FloorLightTimer = null ]
		} 
	else {
		logInfo("FloorMotion","Nothing to do")	
	}
end

But I would still like to know why that channel does not exist, but he can change it.


Edit: There is a value to set when the motion sensor will alarm again and the default is 2 minutes, minimum is 1 minute - here is a post about it: Mi(Xiaomi) Smart home bindings?