Wasp mode lighting with Node-RED and Home Assistant

“Wasp mode” is a generic term for lights management in a room with one or more doors and one or more motion / occupancy sensors.

The idea behind a wasp mode sensor goes like this:

  • When a door is open or a sensor detects presence / motion / occupancy, the lights are turned on for a brief period of time.
  • When all doors are subsequently closed, if presence / motion / occupancy remains or reactivates, wasp mode is turned on, and all lights remain on until the next time a door is open.
  • Once everyone exits the room (irrespective of door state), all lights are turned off after a while.

I’ve devised a Node-RED wasp mode subflow which you can use to create a Home Assistant sensor entity. This sensor entity can then be used to drive your automations and turn lights on / off. Its inputs are Node-RED HA entities of the opening, motion or occupancy sensors class (detected by name in msg.topic). Its primary output is a msg whose payload says on due to... or off due to..., with occupancies and openings as attributes of the msg object; two more outputs emit messages when the light is meant to go from off to on, or from on to off. The timeout can be adjusted with the subflow property “delay” — you will want to bump this to more than 3 minutes for lazy sensors like the IKEA TRADFRI ones, but ideally it is always longer than the time it takes for the sensor to flip from “occupancy detected” to “occupancy clear” (or motion equivalent).

The flow is here:

Here’s how it looks like:

You can then hook this to a Node-RED HA sensor entity, such that this entity appears in Home Assistant. You can also directly drive automations from Node-RED if you so choose. The post linked above has examples.

I’m trying to implement this but I can’t quite figure out how you "chops off the payload to either on or off " with a change node. I managed to figure out a regular expression to find ‘on’ as the first word - (?:^|\W)on(?:$|\W) but if I substitute ‘on’, I also get the rest of the message payload passed on.

Can you offer any help? I haven’t been able to find anything VIA google, and I’d like to learn how to do this. Thanks!

I finally figured this out, if anyone else happens to be searching for the answer. This takes whatever you put into it and returns just the first word.

That works.

I myself just use a template in my Home Assistant automation that uses .split()[0] on the string instead. That way I can see "on due to wasp mode" / off with 0 occupancies... as the state of the entity, which is useful for debugging.

1 Like