Dashboard Switch To Interrupt A Flow?

1,103 views
Skip to first unread message

rlno...@gmail.com

unread,
Aug 3, 2017, 10:14:21 PM8/3/17
to Node-RED
I have a rpi-gpio input node that is connected to a motion detector. Which is in turn connected to Pushover. I'm looking for a way to interrupt the flow from the rpi-gpio input node to Pushover in the form of a button on the Dashboard.

There have been a couple of case where something was falsing the detector and a dashboard button would be ideal to temporarily disable the flow while away from home. Using a form C relay with a rpi output node prior to connecting to the input is a thought but kind of messy.

Glenn

unread,
Aug 4, 2017, 1:44:27 AM8/4/17
to Node-RED
Maybe using a switch node?

The button sets variable with a value of stop and if the switch node doesn't see a stop value it continues otherwise it stops

Julian Knight

unread,
Aug 4, 2017, 4:07:00 AM8/4/17
to Node-RED
You will likely need to set a flow variable from a Dashboard switch or button. You will also want a trigger node after setting the variable - that should fire a second time after the interval you want to block your signal - resetting the variable. Then in the flow from the sensor, add something to only allow the message through if the variable is not true.

Cory Guynn

unread,
Aug 4, 2017, 4:50:37 AM8/4/17
to Node-RED
Here is a sample I use to gate my flows. I use a context variable that is toggled based on a "state" topic. I also use the Node's notification option to easily view the state.


Function Logic
var state = context.get("state") || "on";

// Display initial state status
if(state == "on"){
    node.status({fill:"green",shape:"dot",text:state});
}else{
    node.status({fill:"red",shape:"ring",text:state});
}

if(msg.topic == "state"){
    context.set("state",msg.payload);
    state = msg.payload;
    // update status
    if(state == "on"){
        node.status({fill:"green",shape:"dot",text:state});
    }else{
        node.status({fill:"red",shape:"ring",text:state});
    }
}else{
    if(state == "on"){
        return msg;
    }
}





Flow
[{"id":"b4e4d9ee.93b458","type":"debug","z":"e4f38591.2bd518","name":"Gated Flow Data","active":true,"console":"false","complete":"true","x":630,"y":140,"wires":[]},{"id":"54f28527.00ee2c","type":"inject","z":"e4f38591.2bd518","name":"","topic":"state","payload":"on","payloadType":"str","repeat":"","crontab":"","once":true,"x":180,"y":180,"wires":[["d8744d0e.71c98"]]},{"id":"d3f36679.cfa508","type":"inject","z":"e4f38591.2bd518","name":"","topic":"state","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"x":180,"y":220,"wires":[["d8744d0e.71c98"]]},{"id":"4dea7961.6a9858","type":"inject","z":"e4f38591.2bd518","name":"Sample Data","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":190,"y":140,"wires":[["d8744d0e.71c98"]]},{"id":"1ddb616c.3268bf","type":"comment","z":"e4f38591.2bd518","name":"Sample Flow Toggle","info":"","x":150,"y":100,"wires":[]},{"id":"d8744d0e.71c98","type":"function","z":"e4f38591.2bd518","name":"Flow On/Off","func":"var state = context.get(\"state\") || \"on\";\n\n// Display initial state status\nif(state == \"on\"){\n    node.status({fill:\"green\",shape:\"dot\",text:state});\n}else{\n    node.status({fill:\"red\",shape:\"ring\",text:state});\n}\n\nif(msg.topic == \"state\"){\n    context.set(\"state\",msg.payload);\n    state = msg.payload;\n    // update status\n    if(state == \"on\"){\n        node.status({fill:\"green\",shape:\"dot\",text:state});\n    }else{\n        node.status({fill:\"red\",shape:\"ring\",text:state});\n    }\n}else{\n    if(state == \"on\"){\n        return msg;\n    }\n}\n","outputs":1,"noerr":0,"x":410,"y":140,"wires":[["b4e4d9ee.93b458"]]}]



I've also written a version that uses the Dashboard UI toggle button. It will use a Link node to receive the input from whatever flow I want.




Flow
[{"id":"9b30c49d.23c808","type":"link in","z":"e4f38591.2bd518","name":"LED Matrix Body","links":[],"x":115,"y":440,"wires":[["78b4f577.bbb37c"]]},{"id":"78b4f577.bbb37c","type":"function","z":"e4f38591.2bd518","name":"Flow On/Off","func":"var state = context.get(\"state\") || \"on\";\n\n// Display initial state status\nif(state ==\"on\"){\n    node.status({fill:\"green\",shape:\"dot\",text:state});\n}else{\n    node.status({fill:\"red\",shape:\"ring\",text:state});\n}\n\nif(msg.topic == \"state\"){\n    context.set(\"state\",msg.payload);\n    state = msg.payload;\n    // update status\n    if(state == \"on\"){\n        node.status({fill:\"green\",shape:\"dot\",text:state});\n    }else{\n        node.status({fill:\"red\",shape:\"ring\",text:state});\n    }\n}else{\n    if(state == \"on\"){\n        return msg;\n    }\n}\n","outputs":1,"noerr":0,"x":312.4999942779541,"y":437.5,"wires":[["f089d4f2.540eb8"]]},{"id":"382c1f46.1a368","type":"ui_switch","z":"e4f38591.2bd518","name":"","label":"Dynamic Input","group":"db5b2edd.a99d6","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"state","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","x":322.4999942779541,"y":397.5,"wires":[["78b4f577.bbb37c"]]},{"id":"bd2a6c0a.e0d1c","type":"inject","z":"e4f38591.2bd518","name":"","topic":"state","payload":"on","payloadType":"str","repeat":"","crontab":"","once":true,"x":162.4999942779541,"y":357.5,"wires":[["382c1f46.1a368"]]},{"id":"69f9bd3d.49c5f4","type":"inject","z":"e4f38591.2bd518","name":"","topic":"state","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"x":162.4999942779541,"y":397.5,"wires":[["382c1f46.1a368"]]},{"id":"f089d4f2.540eb8","type":"debug","z":"e4f38591.2bd518","name":"","active":true,"console":"false","complete":"false","x":570,"y":440,"wires":[]},{"id":"319099d0.d0a5d6","type":"comment","z":"e4f38591.2bd518","name":"Sample Flow Toggle with UI and Link input","info":"","x":220,"y":320,"wires":[]},{"id":"db5b2edd.a99d6","type":"ui_group","z":"","name":"Flow Toggle","tab":"b405a340.8e78d","disp":true,"width":"6"},{"id":"b405a340.8e78d","type":"ui_tab","z":"","name":"Sandbox","icon":"dashboard"}]


Hope this helps!

Cory


My Tech Blog

Julian Knight

unread,
Aug 4, 2017, 11:55:39 AM8/4/17
to Node-RED
Sorry, I misunderstood the "temporary" part. You probably don't need the trigger.

An alternative that would be a lot more secure since you want to access from outside your home would be to use a "bot" with Telegram or similar. Easy enough to build using one of the contributed nodes and gives end-to-end security for free.

rlno...@gmail.com

unread,
Aug 4, 2017, 4:58:19 PM8/4/17
to Node-RED
Thanks for all of the suggestions. It appears to be more complicated than I thought to simply break the connection between two nodes using a dashboard button.

Julian Knight

unread,
Aug 4, 2017, 5:48:34 PM8/4/17
to Node-RED
There are undoubtedly several more ways to do it but the essence is that you need to maintain a flag in memory.

Bart Butenaers

unread,
Aug 5, 2017, 1:08:26 PM8/5/17
to Node-RED
Hi,

Perhaps the node-red-contrib-traffic node could be a (simpler) solution for your case?? I haven't used it yet, and I'm currently a few days computer-less (so I cannot test it at this moment). But it's only purpose is to pass and block messages.

I'm very curious whether it fits your needs, so please give feedback (if you should try it).

Kind regards,
Bart Butenaers

rlno...@gmail.com

unread,
Aug 6, 2017, 10:02:22 AM8/6/17
to Node-RED
Bart, Your traffic node appears to be exactly what I was looking for!  Initial testing indicates it works to solve my problem.

David Caparrós

unread,
Aug 7, 2017, 5:07:29 AM8/7/17
to Node-RED

Just another example of interrupt the flow based on conditions from different topics, the message that passes has different topic that the ones on the logic:



if (msg.topic == "time") {
context.state = msg.payload;
return null;
}
if (msg.topic == "auto") {
context.state2 = msg.payload;
return null;
}

if (msg.topic == "/ESP-7/Ana in/Analog") {
context.state3 = msg.payload;
return null;
}

if ((context.state == 1) && (context.state2 == 1) && (context.state3 <= 30)  )
  return msg;
else
  return null;
 




[{"id":"f7d8d565.056488","type":"function","z":"712ddec8.883c8","name":"Enabled","func":"\nif (msg.topic == \"time\") {\n\tcontext.state = msg.payload;\n\treturn null;\n}\nif (msg.topic == \"auto\") {\n\tcontext.state2 = msg.payload;\n\treturn null;\n}\n\nif (msg.topic == \"/ESP-7/Ana in/Analog\") {\n\tcontext.state3 = msg.payload;\n\treturn null;\n}\n\nif ((context.state == 1) && (context.state2 == 1) && (context.state3 <= 30)  )\n  return msg;\nelse\n  return null;\n ","outputs":1,"noerr":0,"x":800,"y":2800,"wires":[["851a6fdb.9e5d2"]]}]
Reply all
Reply to author
Forward
0 new messages