Best structure for motion and door sensor triggers


#1

The use case it’s simple room occupancy based on motion sensor and open close sensor (presume all rooms have only one of each).

I want to turn the lights on if motion is detected.
Turn lights off if no motion
Keep lights on if motion detected after the door sensor is closed until door is opened again.

I can do the basic on/off based on one sensor but what’s the best way to structure multiple sensors? I looked for examples but couldn’t see this anywhere although there must be plenty of people using it!


#2

just a quick question about the above…
What if your lights are never OFF as long as there is motion in the room?? Does it have to be door open close related?

it’s also possible with open-close sensor but you need to start using variables… are you cool with that?


#3

Doesn’t have to be open close based it’s more to cover the lying on the sofa or being in shower scenarios where the door is closed and you’re definitely in the room but you can’t detect motion so it’s more a back up. Happy to use variables with a little guidance, I’m still learning!


#4

Makes sense, when you are sitting in the room and watching tv etc motion can’t be detected all the time…
Here is a simple draft that works with door open close sensor.

Create a global variable @lightsmnotioncontrol

IF door open close changes to CLOSED
Set variable @lightsmnotioncontrol = true

IF motion sensor CHANGES TO ACTIVE (trigger)
OR
IF door open close sensor CHANGES TO OPEN
With 
Lights 
Do turn ON

IF motion sensor stay inactive for 5 minutes
and 
IF @lightsmnotioncontrol = false
Lights 
Do turn OFF

IF door open close sensor CHANGES to CLOSED
then
With lights
do turn OFF
set variable @lightsmnotioncontrol = false

this is a very quick draft and I haven’t tested because i’m not home FYI.
pls let me know if you have any questions and anyone else pls dive in if you have better, shorter ways of doing this…