Organizing presence on the motion sensor in Home Assistant
Let’s say you have
home assistant
Zigbee2MQTT installed in it
Node-RED installed in it
the desire that the light would be on all this when someone is in the room
Of course you can buy TS0601it’s cool, it can work as a router, but it requires a separate power supply and spams quite a lot with messages
Therefore, you can use a timer and get by with only a motion sensor. It looks like this
“Motion bathroom” – subscription to the motion sensor topic
“Switch occupancy” – branching by data from json
“state_right – ON” – generating a message for turning on the right switch (I have it there WS-EUK02 and the light is only on the right, the function looks like this
msg.payload = {"state_right": "ON"};
return msg;
“Reset timer” looks like this
var msg = { reset:true };
return msg;
“state_right – OFF” – generating json off
msg.payload = {"state_right": "OFF"};
return msg;
“delay 15m” – delay for 15 minutes
Well, “Switch bathroom set” – sending messages (mqtt out) to the switch topic zigbee2mqtt/switch_bathroom/set
All components are standard from Node-Red. mqtt in/out from network, the rest is all from functions
Everything works stupidly, as is clear from the diagram
If there is movement, the light turns on and the delay timer resets to count from zero
If there is no movement, the timer starts and if there was no movement for 15 minutes, the light is turned off.
A couple of downsides to this solution:
If you lie in the bathroom / sit on the potty and do not move, then the timer will turn off the light in 15 minutes 🙂 This is rare, but it happens
The light will always be on for 15 minutes even if you are gone and you do not need it