# Motion Sensor Light ON If within Time Range/Schedule

**URL:** <https://discourse.nodered.org/t/motion-sensor-light-on-if-within-time-range-schedule/72627>\
**Category:** General\
**Tags:** home-assistant\
**Created:** [23 December 2022 11:12 UTC](https://discourse.nodered.org/t/motion-sensor-light-on-if-within-time-range-schedule/72627 "2022-12-23T11:12:25Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 December 2022 12:20 UTC](https://discourse.nodered.org/t/motion-sensor-light-on-if-within-time-range-schedule/72627/2 "2022-12-23T12:20:45Z")

</div>

Hello @Step_By_Step, welcome to Node-red

You have two conditions: a) is it within the approved hours? and b) is motion sensed?  
Somehow you need to combine these.

The way I would approach it is with a node-red-contrib-simple-gate node. This lets you block or pass messages on a timetable:

 ![Untitled 3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/5/b50cd29debc898e70fcb49ca432fcf4a643aca27.jpeg)

```auto
[{"id":"d0e63953bdd549a5","type":"mqtt in","z":"d5a55d5358bf9c58","name":"Motion detected","topic":"stat/porch/sensors/PIR1","qos":"2","datatype":"auto-detect","broker":"754230cc.99c44","nl":false,"rap":true,"rh":0,"inputs":0,"x":260,"y":160,"wires":[["e5435415add6710f"]]},{"id":"e5435415add6710f","type":"gate","z":"d5a55d5358bf9c58","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memory","x":490,"y":120,"wires":[["6eb0bad255012539"]]},{"id":"61566b20373b9bd5","type":"inject","z":"d5a55d5358bf9c58","name":"Open gate at 19:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 19 * * *","once":false,"onceDelay":0.1,"topic":"control","payload":"open","payloadType":"str","x":240,"y":80,"wires":[["e5435415add6710f"]]},{"id":"c1aecf4b6f13579f","type":"inject","z":"d5a55d5358bf9c58","name":"Close gate at 23:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 23 * * *","once":false,"onceDelay":0.1,"topic":"control","payload":"close","payloadType":"str","x":240,"y":120,"wires":[["e5435415add6710f"]]},{"id":"6eb0bad255012539","type":"mqtt out","z":"d5a55d5358bf9c58","name":"Control Light","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"754230cc.99c44","x":670,"y":120,"wires":[]},{"id":"754230cc.99c44","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

```

I have just used inject nodes to open and close the gate but you might prefer node-red-contrib-cron-plus for better timing control, even including seasonal variability like "sunset plus 45 minutes".

I never bother with turning off my Tasmota controlled devices - one lamp and my coffee machine.  
Instead I use theTasmota's PulseTime1 option which automatically turns off after a set time.

eg If PulseTime1 is set to 700, the light will turn off 600 seconds after motion stops being detected.

---

_[View the full topic](https://discourse.nodered.org/t/motion-sensor-light-on-if-within-time-range-schedule/72627)._
