Setting a timer

723 views
Skip to first unread message

Brandon J

unread,
Apr 21, 2016, 11:11:18 AM4/21/16
to Node-RED
Hi there,

I'm working on a flow for a garage door controller using Node-RED, Blynk, and Raspberry Pi. I already have it set up to detect the status of the Reed Switch, wether it's high or low. However, I would also like to set up a notification if it's been HIGH or open for 5 minutes.

How can I set up a timer for 5 minutes in the future, when the reed switch goes high?

Thanks

Nicholas O'Leary

unread,
Apr 21, 2016, 11:25:40 AM4/21/16
to Node-RED Mailing List
Have a look at the trigger node - you can use that to trigger a message a some point in the future unless it gets cancelled by another message.

Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
For more options, visit https://groups.google.com/d/optout.

Brandon J

unread,
Apr 21, 2016, 8:55:16 PM4/21/16
to Node-RED
Nick that was a big help, thanks! I have one more challenge now. I find myself needing to sort of 're-execute' the whole flow. The flow all starts with reading in GPIO 22 which is the reed switch, and everything goes from that. I've looked at using the inject node to re-execute the whole flow but can't figure it out.

Also is there a way to read the status of node from a different node?

Thanks

Julian Knight

unread,
Apr 22, 2016, 3:33:58 AM4/22/16
to Node-RED
Hi Brandon, maybe you'd like to post your flow so we can see how you've engineered it? I'm sure someone will be able to assist.

In terms of status, I assume you've tried the status node? "Send status messages from other nodes on the same tab." ;-)

Dave C-J

unread,
Apr 22, 2016, 3:46:16 AM4/22/16
to node...@googlegroups.com
Brandon, you can use the global context to share state between different functions if you need to.
It depends why you want to re-execute the flow - just once ? or regularly ? If once you could use the feedback from a trigger. If regularly then yes an inject probably best. 

Brandon J

unread,
Apr 22, 2016, 11:04:10 PM4/22/16
to Node-RED
Thanks for the reply. Here is a screenshot of the flow: http://i.imgur.com/DtZynVr.png

The reason I'm needing to re-execute the whole flow is primarily for the LCD message. Sometimes it displays the wrong status and if I can just periodically check the status of the magnet, then I can always be sending the correct message to the LCD. 

Thanks

Dave C-J

unread,
Apr 23, 2016, 7:03:38 AM4/23/16
to Node-RED
Brandon,

so what I would do... is hold some state in that first function node...
     context.dooropen = context.dooropen || 0;
then when the gpio value comes in use it to also set context.doorvalue.
Then add an inject node with a topic set to something (eg "ping") and set it to repeat every 10 seconds or whatever makes sense.
And in the function node add a test early on to check where the message came from
    if (msg.topic === "ping) { return  [null,{payload:context.doorvalue},null]; }
ie if it was an inject just send out the existing state to the second output... 
obvious I guess you don't just send the state but hopefully you get the idea.

Brandon J

unread,
Apr 27, 2016, 8:48:00 PM4/27/16
to Node-RED
Dave,

For some reason I cannot get the context to work properly, can you provide a decent example of that? I know the syntax has changed a bit from how you mentioned, but don't think it's invalid yet.

Thanks

Brandon J

unread,
Apr 28, 2016, 11:15:33 PM4/28/16
to Node-RED
Well I got everything working the way I had hoped! Thank you all for your help.

I do have a question though. I've just installed the project into the garage and ran all the wires for the magnet and everything. Interestingly, the magnet status is sort of transmitting intermittently. It makes the Blynk LCD widget flicker between garage open and its previous status. In testing, this works fine. I'm actually suspecting this to be the length of 22gauge wire that it's going through. I don't know the exact length, but it is pretty long. I'm positive that if I was to shorten it, it would work fine. But is there a way I can sort of increase the range? Thicker wire?

Thanks

Dave C-J

unread,
Apr 29, 2016, 2:24:38 AM4/29/16
to node...@googlegroups.com

Hi, what is the exact circuit writing you have for the mag switch and gpio ? Maybe a different value pull up or down resistor may help.

Brandon J

unread,
Apr 29, 2016, 8:42:12 AM4/29/16
to Node-RED
Dave,

Here is an image of the flow at this point: http://i.imgur.com/S3YK9IK.png

On the garage buttons (pins 24 and 26) I don't have options for using resistors like I do on the magnet input node.

Brandon J

unread,
Apr 29, 2016, 1:54:45 PM4/29/16
to Node-RED
Also, I've just plugged in some shorter wires like in my test setup (around 6 inches) and it works fine. It must be the length of the wire! I need to find a way to get that signal to travel further.

Brandon J

unread,
Apr 29, 2016, 11:23:02 PM4/29/16
to Node-RED
After some frustration and lots of research, the issue turned out to be not length of wire, but rather noise on the line over that distance. I installed a capacitor to filter that out and it's a steady signal now.

Thanks!

Walter Kraembring

unread,
Apr 30, 2016, 12:45:21 AM4/30/16
to Node-RED
Do you use a twisted wire pair?

Julian Knight

unread,
Apr 30, 2016, 9:26:15 AM4/30/16
to Node-RED
Ah yes, any run of unshielded wire is going to act as an aerial. I used to live 20mi or so from a very large, major BBC transmitter, it caused mayhem for some people with even fillings and pipes/radiators picking up and repeating signals!

I think you could have used a choke to help reduce the noise as well?
Reply all
Reply to author
Forward
0 new messages