Hi!
I'm looking to automate my lights with motion sensor, but it needs to be overridable from the light switch itself (in case I want to spend more time in the room than the motion sensor timer gives).
The situation looks as following:
- the light switch is a eWeLink ZB-SW01. Every time I press it, it toggles the lights and this behaviour cannot be changed (i.e. I cannot press the switch and not toggle the lights),
- the motion sensor is SONOFF SNZB-03,
- both are connected via Zigbee2MQTT to Home Assistant.
Here's what I want to achieve:
- When I enter the room, I want the lights to turn ON and then after 5 minutes turn OFF,
- When I enter the room and press the switch on the wall, I want the lights to remain ON until I turn it OFF manually on the wall or from HA panel OR 60 minutes pass by.
Point 1 is really straightforward. But point 2 is more complex: The usual situation will be:
- Me entering the room
- Motion sensor turns ON the lights
- I press the wall switch, so lights are toggled OFF
- Node-RED turns the lights ON again
I want to use the HA events: state
and call-service
nodes, however calling the service to toggle the lights, triggers the events: state
node - however, I can differentiate what was the origin of the event by checking the msg.data.old_state.context.user_id
(it's equal to null
if I press the switch on the wall).
I do not want to use poll: state
nodes, because of efficiency, speed and latency.
I'd prefer not to use HA input_boolean
's and keep all the flags/semaphores within Node-RED.
How to do it, the Node-RED way?