# Motion triggered week day timer?

**URL:** <https://discourse.nodered.org/t/motion-triggered-week-day-timer/7800>\
**Category:** General\
**Created:** [10 February 2019 13:36 UTC](https://discourse.nodered.org/t/motion-triggered-week-day-timer/7800 "2019-02-10T13:36:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dayve](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@Dayve](https://discourse.nodered.org/u/Dayve)\
**Post date:** [10 February 2019 13:36 UTC](https://discourse.nodered.org/t/motion-triggered-week-day-timer/7800/1 "2019-02-10T13:36:47Z")

</div>

Trying for a few days now to get a flow to work. A simple motion triggered flow to turn on a light if it is between 6am and 6:30 am only on week days.

Here is the working flow I have now that turns on the hall light but it is every day of the week.  
This must be possible just cannot wrap my head around it.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8af398d61904f5d44b652fe270e98b71697be820.png)

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [10 February 2019 13:56 UTC](https://discourse.nodered.org/t/motion-triggered-week-day-timer/7800/2 "2019-02-10T13:56:16Z")

</div>

Have a look at the `node-red-contrib-schedex` node. You can select the days you want.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [10 February 2019 14:12 UTC](https://discourse.nodered.org/t/motion-triggered-week-day-timer/7800/3 "2019-02-10T14:12:57Z")

</div>

If you look at the readme I'm not sure that the node accepts an input and acts as a "gate" dependant on the settings.

However what you could do is wire the schedex node up to a change node configured to set a global variable to true or false (click the msg bit to see the alternatives) (see [https://nodered.org/docs/writing-functions#storing-data](https://nodered.org/docs/writing-functions#storing-data))

Then in your PIR flow have a switch node that passes the message on only if the global variable is true

---

<div class="post-metadata">

**Author:** ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)\
**Post date:** [10 February 2019 14:20 UTC](https://discourse.nodered.org/t/motion-triggered-week-day-timer/7800/4 "2019-02-10T14:20:05Z")

</div>

> [@ukmoose](#):
>
> I'm not sure that the node accepts an input and acts as a "gate" dependant on the settings.

Right! I used a similar approach as you proposed but to avoid globals I used a function:

```auto
[{"id":"c7ed599c.97b3c8","type":"schedex","z":"66646ca8.e97654","name":"","suspended":false,"lat":"52.2","lon":"0.12","ontime":"06:00","ontopic":"set","onpayload":"on","onoffset":0,"onrandomoffset":0,"offtime":"06:30","offtopic":"set","offpayload":"off","offoffset":0,"offrandomoffset":0,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":false,"sun":false,"x":270,"y":3780,"wires":[["eb90cd89.70812"]]},{"id":"8a49fbdc.d19608","type":"inject","z":"66646ca8.e97654","name":"","topic":"set","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":3780,"wires":[["c7ed599c.97b3c8"]]},{"id":"7d206aaa.44ab64","type":"debug","z":"66646ca8.e97654","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":3780,"wires":[]},{"id":"32fe4c0d.b4eff4","type":"inject","z":"66646ca8.e97654","name":"","topic":"set","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":3840,"wires":[["c7ed599c.97b3c8"]]},{"id":"eb90cd89.70812","type":"function","z":"66646ca8.e97654","name":"","func":"if (msg.topic === \"set\") {\n context.set('pass', msg.payload);\n msg = null;\n} else {\n var pass = context.get('pass') || 'off';\n if (pass === 'off' || msg.payload === 'off') {\n msg = null; \n }\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":3780,"wires":[["fdbc9a3e.f26ed8"]]},{"id":"bc46cb33.73cc58","type":"inject","z":"66646ca8.e97654","name":"","topic":"","payload":"my msg","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":3720,"wires":[["eb90cd89.70812"]]},{"id":"fdbc9a3e.f26ed8","type":"trigger","z":"66646ca8.e97654","op1":"on","op2":"off","op1type":"str","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":600,"y":3780,"wires":[["7d206aaa.44ab64"]]}]

```

---

<div class="post-metadata">

**Author:** ![Dayve](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@Dayve](https://discourse.nodered.org/u/Dayve)\
**Post date:** [10 February 2019 17:48 UTC](https://discourse.nodered.org/t/motion-triggered-week-day-timer/7800/5 "2019-02-10T17:48:02Z")

</div>

That is perfect. thank you.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [11 February 2019 00:30 UTC](https://discourse.nodered.org/t/motion-triggered-week-day-timer/7800/6 "2019-02-11T00:30:14Z")

</div>

The same flow, using `node-red-contrib-simple-gate`. No coding, no context variable.

```auto
[{"id":"e86dc6a6.5069b","type":"gate","z":"99c0b0a.c5701d","name":"","controlTopic":"set","defaultState":"open","openCmd":"on","closeCmd":"off","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":450,"y":420,"wires":[["dfb4ebbc.2c98b"]]},{"id":"c317029e.ada1a","type":"schedex","z":"99c0b0a.c5701d","name":"","suspended":false,"lat":"52.2","lon":"0.12","ontime":"06:00","ontopic":"set","onpayload":"on","onoffset":0,"onrandomoffset":0,"offtime":"06:30","offtopic":"set","offpayload":"off","offoffset":0,"offrandomoffset":0,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":false,"sun":false,"x":270,"y":440,"wires":[["e86dc6a6.5069b"]]},{"id":"8d311e57.4b844","type":"inject","z":"99c0b0a.c5701d","name":"","topic":"set","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":420,"wires":[["c317029e.ada1a"]]},{"id":"12da01a1.19923e","type":"debug","z":"99c0b0a.c5701d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":420,"wires":[]},{"id":"df8cc3ba.1ba52","type":"inject","z":"99c0b0a.c5701d","name":"","topic":"set","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":480,"wires":[["c317029e.ada1a"]]},{"id":"f8a8eb37.c4ac78","type":"inject","z":"99c0b0a.c5701d","name":"","topic":"","payload":"my msg","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":290,"y":400,"wires":[["e86dc6a6.5069b"]]},{"id":"dfb4ebbc.2c98b","type":"trigger","z":"99c0b0a.c5701d","op1":"on","op2":"off","op1type":"str","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":580,"y":420,"wires":[["12da01a1.19923e"]]}]

```

---

<div class="post-metadata">

**Author:** ![Dayve](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@Dayve](https://discourse.nodered.org/u/Dayve)\
**Post date:** [12 February 2019 00:57 UTC](https://discourse.nodered.org/t/motion-triggered-week-day-timer/7800/7 "2019-02-12T00:57:08Z")

</div>

Very nice. Thank you.  
Now if I was to use an input select from home assistant to disable the flow completely how could I do that are is it possible?

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [12 February 2019 01:11 UTC](https://discourse.nodered.org/t/motion-triggered-week-day-timer/7800/8 "2019-02-12T01:11:58Z")

</div>

If understand what you want to do, just insert a `gate` node at the point where you want to stop the flow and set things up so that the HA message closes the gate. You can do that by some combination of configuring the `gate` node, defining the HA message and/or inserting a `change` node ahead of the gate. If you can't make it work, post your flow here so we can take a look.
