Motion triggered week day timer?


#1

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.


#2

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


#3

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)

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


#4

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

[{"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"]]}]

#5

That is perfect. thank you.


#6

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

[{"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"]]}]

#7

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?


#8

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.