I have a door and motion sensor in my laundry. Basically what I would like to do is whenever the door opens between a certain time lights should turn on and if the door closes lights should turn off which is fairly simple but then I would like to add conditions or scenarios such as where if someone forgets to close the door and turn off the light and if no motion is detected the lights should turn off. Now if the door is already open and the lights are off they should turn on when someone walks in and follow the above condition to turn them off. The only thing with this is if someone is inside the laundry room and closes the door it will turn off the lights which never happens am I missing something here and what will be best way to set this up?
It could be better to do this in Room Lighting rather than Rule Machine. Something like this:
It may need tweaking. I guess that the door closing after entry may briefly turn the light off if the motion sensor isn't already active at the moment but it should work.
Edited: The 1 minute on the side door closing added as it's expected the motion sensor will trigger again before the minute expires. TBH you could probably just do away with the door contact turning off the light as the motion inactive will do it anyway.
If you want to use Rule Machine, I'd set it up similar to the following:
Required Expression
Between Two Times (this is your time period)
Triggers
Contact Door Opens
or
Motion Sensor Active
Actions
Turn on Light
Wait for Events: (1) Contact Door Closes and stays for 1 minute, or (2) Motion Sensor inactive and stays for 1 minute
Turn off Light
With the above (and some testing/tweaking), you'll get the desired behavior. Basically, the Required Expression limits the rule to only run during the desired time period. As for triggers, you will want either the door opening or the motion sensor going active. The latter trigger will help cover the situation of the door being open but the lights off when someone walks in.
As for the actions, obviously the first one turns on the light. The key is the Wait for Events. The rule will wait for either of the two things to become true before turning off the light in the next action. However, the thing about the Wait is that it will get cancelled and re-rescheduled every time the rule gets triggered. Basically, every time the motion sensor goes active again, the wait will reset.
With the above said, @johnwill1's example in Room Lighting will also work. Room Lighting is specifically designed for scenarios like this, but if you prefer, the above Rule Machine will work too.