Node Red with Xiaomi Aqara Motion Sensors

Having trouble integrating Xiaomi sensors to your tradfri IKEA smart lights?

I have an upstairs and downstairs hallway which I was trying to automate so I no longer needed to switch the light on any more!

Xiaomi sensors have an internal timer of around 1/2 minutes which leaves a nasty blind spot where it doesnt look for more motions within this period but for the purposes of turning on my lights I can live with this.

My flow..

The flow basically checks for motion triggers turning on and off from home assistant when motion is triggered it starts a 30 second timeout to try offset the internal timer of the xiaomi sensor, then proceeds to turn on the light if the light sensor is at an acceptable light level - this is also great for not turning on the lights when its already bright enough inside.

The 30 second timer keeps a loop which gets reset every time something new happens - if during that time the sensor is still on it leaves the light up but if the motion sensor is off then it will try to turn off the lights.

If you import my flow below into your node-red set-up and reconfigure to point at your own home assistant instance as well as redo the xiaomi sensors and lights you should be good to go!

Node Red Flow Import

[{"id":"4b280c35.fffb7c","type":"switch","z":"64cbc266.5f84ec","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":439,"y":327,"wires":[["36ea3843.65631","ea58464b.091ad"],["ea58464b.091ad"]]},{"id":"3436967.4e79f6a","type":"comment","z":"64cbc266.5f84ec","name":"Upstairs Lights - Turn On and Off based on motion","info":"","x":407,"y":217,"wires":[]},{"id":"9e5cebbb.c0b0b8","type":"api-call-service","z":"64cbc266.5f84ec","name":"Turn off Upstairs Lights","server":"29c649b5.6aa756","service_domain":"light","service":"turn_off","data":"{\"entity_id\":\"light.landing_lights\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":930,"y":340,"wires":[[]]},{"id":"ea58464b.091ad","type":"stoptimer","z":"64cbc266.5f84ec","duration":"30","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":663,"y":335,"wires":[["652fad71.7b209c"],[]]},{"id":"36ea3843.65631","type":"api-current-state","z":"64cbc266.5f84ec","name":"Light Already On?","server":"29c649b5.6aa756","outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.landing_lights","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":609,"y":266,"wires":[["ae6a1ab2.0e589"],[]]},{"id":"652fad71.7b209c","type":"api-current-state","z":"64cbc266.5f84ec","name":"Motion Sensor still on?","server":"29c649b5.6aa756","outputs":1,"halt_if":"","override_topic":true,"entity_id":"binary_sensor.motion_sensor_158d000222e342","override_payload":true,"x":543,"y":428,"wires":[["4d6a890a.d36f48"]]},{"id":"4d6a890a.d36f48","type":"switch","z":"64cbc266.5f84ec","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":733,"y":428,"wires":[["ea58464b.091ad"],["9e5cebbb.c0b0b8"]]},{"id":"ae6a1ab2.0e589","type":"api-current-state","z":"64cbc266.5f84ec","name":"Lumincity Check","server":"29c649b5.6aa756","outputs":1,"halt_if":"","override_topic":true,"entity_id":"sensor.illumination_158d000222e342","override_payload":true,"x":847,"y":173,"wires":[["daee6258.357c5"]]},{"id":"daee6258.357c5","type":"switch","z":"64cbc266.5f84ec","name":"Check illumination reading","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"40","vt":"num"},{"t":"lt","v":"40","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1103,"y":254,"wires":[[],["857f7c10.2a0c4"]],"outputLabels":["bright","dark"]},{"id":"d46befde.18113","type":"comment","z":"64cbc266.5f84ec","name":"Sensory Luminicity - if brighter than 40 do nothing","info":"","x":1225,"y":185,"wires":[]},{"id":"857f7c10.2a0c4","type":"api-call-service","z":"64cbc266.5f84ec","name":"Turn on Upstairs Lights","server":"29c649b5.6aa756","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.landing_lights\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":1402,"y":261,"wires":[[]]},{"id":"f9deeb64.db703","type":"server-state-changed","z":"64cbc266.5f84ec","name":"Upstairs Motion","server":"29c649b5.6aa756","entityidfilter":"binary_sensor.motion_sensor_158d000222e342","entityidfiltertype":"substring","haltifstate":"","outputs":1,"x":140,"y":320,"wires":[["4b280c35.fffb7c"]]},{"id":"29c649b5.6aa756","type":"server","z":"","name":"Home Assistant","legacy":true,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

This is by no means a perfect solution but does the job for me, If you have a better way please leave a comment below as I would love to know!