"Adjacent room" motion automations in Node-RED

I’m an impatient person and I don’t like it when lights take a second or two to come on when you walk into a room. So I have set up automations such that when you enter a room, it will turn on lights at 25% in all adjacent, unoccupied rooms. Then if you walk into one of those rooms, it marks itself as occupied, and sets its light level to 100%. Occupied rooms only turn off when no motion is detected inside the room for 10 minutes, and ignore any motion events in adjacent rooms. Rooms in the half-lit state will turn off as soon as motion stops in the adjacent room.

I think this would get pretty complicated if I had multiple entrances to each room, but in my apartment I’ve only done this so far with rooms that have only one way in and out.

Here’s a Node-RED flow:

The key element is a flow context variable called occupied. This prevents the end-of-motion in the hallway from turning off the lights in the shower room when I’ve walked from the hall into the shower. It also controls what the brightness level should be when the lights are turned on:

{
   "brightness_pct": $max([
        $entities("input_select.system_mode").state = "Night" ? 10 : (
               $flowContext("occupied") = false ? 25 : 100
        ),
        $entities("light.bathroom").attributes.brightness_pct
    ])
}

So at night, the light is at 10% regardless of whether you’re in the room or not. During the day, it’s 25% if an ‘adjacent room’ triggers it and 100% if its own sensor triggers it. This setup reminds me a bit of playing an adventure game. The lighting shows me where I can move next from whereever I am :slight_smile:

I’m quite pleased with this and wondered whether anyone had any feedback.