Auto lights on/off (with no movement event from PIR sensor) using 2 x PIR sensors, a light level sensor and 3 minute of no movement delay before lights out

OK so this is my new current favourite use case, a development of the previous case: instead of 1 PIR sensor we now have 2, working together, at either end of the kitchen.

It’s been implemented it with Apilio and Tuya only so no need for IFTTT! It works much quicker and slicker with the Tuya kit - I really recommend the Sonoff zigbee 3.0 PIR devices as they are super quick (see my rather too proud video here).

Hardware being used

  1. 2 x Sonoff Zigbee 3.0 PIR sensors which send a message at the end of a movement detection timeout period, with an inbuilt hardware timeout of 1min. So if there’s no motion after the initial “PIR” trigger the sensor status is “NONE” after one minute.

  2. a separate Tuya Zigbee light level sensor

  3. All running through a Tuya Zigbee hub

The goal is to keep the lights on all the time there’s been motion detected but then turn lights off as soon as possible after no motion. In this case I’m turning off after 3 minutes of no movement.

I set up two identical trigger conditions for each PIR sensor, radio-motion-positive and radio-motion-negative and fridge-motion-positive with fridge-motion-negative.

The motion positive trigger condition turns TRUE on PIR status from the motion sensor.

The motion negative trigger condition turns TRUE on NONE status from the sensor but critically there’s a 3 minute delay added so Apilio only actually considers the condition to be FALSE 3 minutes after the sensor initially returns NONE. This sets the timer after which the lights go out if there’s no motion.

There’s a third condition to check the light level from a light sensor is under 100 Lux - I don’t want the lights to switch on if unnecessary.

So then I have the first (of two) logicblocks, this one controlling lights on. If there’s a PIR event from either PIR sensor (radio or fridge) then the radio-motion-positive or fridge-motion-positive conditions will trigger the logicblock evaluation. I’m using “complex” logic through the following statement AND(kitchen-light-level-under-100,OR(fridge-motion-positive,radio-motion-positive)) to check if either sensor sends PIR that the light level is also below 100 Lux.

The second logicblock controls lights off. This logicblock is triggered by either the radio-motion-negative or fridge-motion-negative trigger condition. The logicblock will only evaluate TRUE if both PIR sensors have been at state NONE (i.e. no PIR event) for over three minutes and, if so, the positive action chain will then turn off the lights.

Works super well the whole time unless I’m typing at my PC when it occasionally goes dark as there’s no enough motion to trigger the PR. I guess I need to type a bit more enthusiastically!

The next thing I would like to change the timeouts according to the time of day. I’d love to be able to use a variable to set the delay/time out but I’m not sure the :mage: is willing to make that magic just yet. “Too many other plans for the time being”, he says!

All clear? Let me know if you have any questions!

3 Likes