# Motion detected light with overriding by ZigBee wall switch

**URL:** <https://discourse.nodered.org/t/motion-detected-light-with-overriding-by-zigbee-wall-switch/45299>\
**Category:** General\
**Created:** [6 May 2021 21:32 UTC](https://discourse.nodered.org/t/motion-detected-light-with-overriding-by-zigbee-wall-switch/45299 "2021-05-06T21:32:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shalak](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Shalak](https://discourse.nodered.org/u/Shalak)\
**Post date:** [6 May 2021 21:32 UTC](https://discourse.nodered.org/t/motion-detected-light-with-overriding-by-zigbee-wall-switch/45299/1 "2021-05-06T21:32:45Z")

</div>

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](https://www.zigbee2mqtt.io/devices/ZB-SW01.html#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](https://www.zigbee2mqtt.io/devices/SNZB-03.html#sonoff-snzb-03),
- both are connected via Zigbee2MQTT to Home Assistant.

Here's what I want to achieve:

1. When I enter the room, I want the lights to turn ON and then after 5 minutes turn OFF,
2. 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:

1. Me entering the room
2. Motion sensor turns ON the lights
3. I press the wall switch, so lights are toggled OFF
4. 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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 July 2021 21:33 UTC](https://discourse.nodered.org/t/motion-detected-light-with-overriding-by-zigbee-wall-switch/45299/2 "2021-07-05T21:33:18Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
