Critique my flow, to switch off a light

Hi all,
I’ve been working on what should (and no doubt is) a very straight forward problem to solve, but due to me not really having a clue what I’m doing with NR I’m no doubt over complicating things. The problem I’m trying to solve is to simply turn off a light if it’s left on by accident.

The light is for our downstairs washroom and the switch is outside the door. I originally plumped for this and it worked, to a fashion but I quickly discovered from some screams that some people spend A LOOOOOOONG time in there.

So, I decided to insert some logic and a contact sensor in to the mix. With the help of @greenspace10 (I assume it’s one and the same person here) on Reddit I ended up with this:

But then I realised that not everyone (me) spends even 5 minutes in there and it messed up the flow if someone left before the timer ended.

And now, many, many, many tweaks later I have this monstrosity, but it works and I think accounts for any eventuality:

To try and explain; a typical use case would be;

  1. Light on
  2. Open door
  3. Shut door
  4. Do business
  5. Open door
  6. Shut door
  7. Switch off the light

But it turns out that people are weird and do all sorts of things. Like open the door then switch on the light. Switch on the light and do nothing at all. Go in there and spin around for 20 minutes, whilst singing show tunes. So, I’ve tried to account for everything and it seems to work. However, I am positive that there must be a better way to do this or a way to make the flow more efficient and so I come to you cool nerds to ask you to take a look and let me know how you would improve or change it please?

Due to character count, I’ve put the exported JSON on Pastebin:


Because I’ve done the same feature for the same reasons, let me give you my 2c.

If you want some fancy system disabling light as precisely as possible or even make the system turn lights on and off fully automatically you need a lot of sensors to cover all (corner) cases. btw counting on doors open/close events is pretty weak because it assumes doors are being closed everytime which must not be true

If your goal is just to make sure the light is not accidently left on for the the whole day then simple timer is enough. I went this way. we still use switches to turn light on and off, but in case we forget, HA do it on behalf of us after some arbitary time.
The time is set depending on room. lower floor toilet is set to 15mins (I figured out it’s too short for me :wink: but then I can turn it on again from mobile). Pantry and store room both are set to 5mins.
Ussually nobody spend more than this. If so, I programmed long push to disable the timer anyway.

The rest cases are too rare to spend resources on them. Long story short make it as simple as possible.

1 Like

I have HA automatically turn the lights off after X minutes.

I have something that stops the automatic shut offs for a few hours in case I need them longer (this is mostly used with Alexia).

I’ve just never had a need for anything more complex.

Yeah, I ended up reverting to just a timed duration and took your advice on the 15 minutes. The logic based on the contact sensor was…wrong. I’d still like to have it based on presence, but like you say it’s complex and needs multiple sensors.

Ah well, it was fun to play with Node Red.

Thanks for the reply.

Why not just have a motion sensor in the washroom together with a timer? If the light does go off, the person only needs to wave their arm.


Heh, your slightly overengineered automation reminds me of some of my own :grinning:

I ended up doing a big sweep across all my HA automations a while ago and basically trashed everything that seems too complex with too many corner cases, replacing it either with simple and functional alternatives or just ditching it altogether. Bathroom lighting was part of that too. In the end I just asked myself if I really needed such precise timing and a complex state machine, just to turn off a few LED lights with an insignificant power consumption (and a very long lifespan). Did I really care that much if they were on for another 10 minutes or even half an hour longer ? Nah, I just wanted to avoid them being on all night if me or my GF forgot about them.

So I ended up just using a motion sensor and the lights turn off if there wasn’t any movement for 30 minutes. Simple and effective.

1 Like

My first thought was to have a 5 minute timer coupled with a motion sensor, which would then loop to check for motion every minute. Stupidly, I thought that a contact sensor would be the easier and more accurate measure. I was wrong. Very, very wrong. :man_facepalming::joy:

Yep, I think I’ve learnt my lesson here. If anyone is still in there after 15 minutes they probably need a prompt to leave lol.

This is what i had in the past. Also I think your flow could be significantly simplified with a trigger node.
And agree unless you have a bunch of sensors lying around, not really worth the hassle.

1 Like