Allow/disallow flow during a specific time peroid (sleeping hours)

Hi, '

Hope you've been well.

I have a flow here, which basically is a notification system reading off a sensor (in this case, weather-based).

Currently, the way it is set up is that if sensor reports a value above (or below) the set threshold, potentially dangerous situation (but not always a dangerous situration), it will send a message payload AND a audio notification on my google home speakers. Once the value goes back below/above the threshold, it resets the messaging system and send another message that it now safe/good.

How do I block the audio aspect of this for a certain time periof of the day? For example, I do not want to be notified of heavy rain duing the time of 11 pm to 6 am (sleeeping hours).

Here's a overview of the flow, where the green is message payload text, and the blue squares are google home speakers in our rooms. I'd like to put block on the blue squares for that time period. I don't know if cronplus can do this, I'm not certain how to set it up

sure it can. and there are other nodes that will permit you to do it in line.

But here is how to block/allow based on time...


[{"id":"cd7521f5.10b9c","type":"inject","z":"a73202046ef1075d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":650,"y":400,"wires":[["c1e35392.abf13"]]},{"id":"c7e7a1c1.45b11","type":"debug","z":"a73202046ef1075d","name":"--> to speakers -->","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":990,"y":400,"wires":[]},{"id":"786630c0.b0ed4","type":"inject","z":"a73202046ef1075d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"_block","payload":"true","payloadType":"bool","x":640,"y":320,"wires":[["c1e35392.abf13"]]},{"id":"f5819368.a7c6f","type":"inject","z":"a73202046ef1075d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"_block","payload":"false","payloadType":"bool","x":650,"y":280,"wires":[["c1e35392.abf13"]]},{"id":"c1e35392.abf13","type":"function","z":"a73202046ef1075d","name":"gate","func":"var block = context.get(\"block\") || false;\nif (msg.topic == \"_block\") {\n    block = msg.payload;\n    context.set(\"block\", block);\n    var stat = {\n        fill: block ? \"red\" : \"green\",\n        shape: block ? \"dot\": \"ring\",\n        text: block ? \"Blocked\" : \"Unblocked\"\n    }\n    node.status(stat)\n    return null;\n}\n\nif(block) return null; //halt flow\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":810,"y":400,"wires":[["c7e7a1c1.45b11"]]},{"id":"57a2fd76f90edf19","type":"cronplus","z":"a73202046ef1075d","name":"block/unblock schedule","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"At8pm","topic":"_block","payloadType":"bool","payload":"true","expressionType":"cron","expression":"0 0 20 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"At6am","topic":"_block","payloadType":"bool","payload":"false","expressionType":"cron","expression":"0 0 6 * * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":610,"y":220,"wires":[["c1e35392.abf13"]]}]

I use the 'time range switch' node.


1 Like

oh thats great, thank you @dougle03 and @Steve-Mcl for your replies!

The time range switch option is brilliantly simple! Here's how I set it up:

the wake hours are from 06:00 to 22:00 so then I just placed the this node after the fucntion node and then dragged the speakers that I do want to be alerted during wake hours to the "within" port (i.e. my kid's room), and all others can be 24/7 so I by-passed this node and left as is. After deploying, the time time range node is yellow...just curious what that means...should it be green since I'm within that time now? please see photo

1 Like

also, im just curiious, if a payload is sent during sleeping hours (outside time range), does it get queued or just deleted? For example, I don't want that, say there were 5 alerts sent during bedtime, then at exactly 6 am, they all get sent and said on the google speaker...

When the time is outside the time range, the message gets routed to output 2. You can choose to ignore that or do something with it - up to you. But it is not "queued" as far as I know.

1 Like

My entire Node Red system relies on feeding voice over my house speakers (installed when the house was built). Almost everything results in a voice message being created (weather alerts, doors open too long, alarm system, internet speed results, solar system notices, door bell, cottage things. etc...). I even have my system detect when motion first occurs in the morning (great room only) and then wait a bit (20 - 30 mins) to announce weather or special event days (anniversaries, birthdays, etc.. are stored in a CSV file) but if motion occurs BEFORE Quiet Time is finished then the announcement waits until after Quiet Time expires. I do a lot with it.

You might consider creating a global variable that you can use throughout your NR application in any number of processes. In my system I set the "Quiet Time" via Dashboard, creating the variable [boolean]), then my wife can change it or there are times when I need "Jessie" (the voice) to be silent for an hour or two, so I can manually make her silent as well.

Using this variable you can decide what to do during "Quiet Time". Creating this Dashboard setup is pretty complicated though with the validation of times (what if QT start is set to after QT end? IE: end 10pm, start at 8am?) however you can do the same thing simply in a NR tab.

Here's an example of how easy it can be (when Dashboard is not involved):
Set QT

... and the code for it.

[{"id":"5cd73c1ea1d316fc","type":"inject","z":"d867d702.3f5658","name":"08 AM off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 08 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":430,"y":395,"wires":[["7e66b5252f600a3a"]]},{"id":"1b5c31cae0795183","type":"inject","z":"d867d702.3f5658","name":"10 AM on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 22 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":430,"y":435,"wires":[["7e66b5252f600a3a"]]},{"id":"7e66b5252f600a3a","type":"function","z":"d867d702.3f5658","name":"Set QT","func":"if (msg.payload) context.globalQuietTime = true\nelse             context.globalQuietTime = false;\nnode.status({ fill: \"grey\", shape: \"ring\", text: \"QT: \" + context.globalQuietTime});\nreturn;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":595,"y":415,"wires":[[]]}]
1 Like

Well, if you use thetime range switch and it happens outside the valid time.... and so the message is sent to the second output.....

You can then do what you want with the message.

Be it queuing it or deleting it.

That's outside the scope of the node.

There are nodes to queue messages if you want.

1 Like

thank you very much, that makes sense that it gets sent to the second output.

@StrongTown that quite elegant. I may try to implement that myself. Thanks for sharing.

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