Momentary Button with animated icon

I am trying to convert this to a momentary switch. I want the animated icon to run while the igniter runs and reset when the message comes back from the igniter circuit the delay substitutes.

I can't seem to inject the reset logic correctly to make it momentary.

Any help would be greatly appreciated.

[{"id":"9c27e8ba.02c398","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"711c541c.7108ac","type":"function","z":"9c27e8ba.02c398","name":"Push Button","func":"var state = context.get(\"STATE\")||0;\n\n//  Look for a !X message to get values.\nif (msg.payload != \"X\")     //Do this if the message is NOT \"X\"\n{\n    //\n    //  Background colours first.\n    //\n    context.set(\"ABGC\", msg.colourA);\n    context.set(\"BBGC\", msg.colourB);\n    //\n    //  Now do text.\n    //\n    context.set(\"Atxt\", msg.txtA);\n    context.set(\"Btxt\", msg.txtB);\n    //\n    //  Font colours.\n    //\n    context.set(\"AFC\",msg.txtclrA);\n    context.set(\"BFC\",msg.txtclrB);\n    //\n    //  Payloads.\n    //\n    context.set(\"PayloadA\", msg.payloadA);\n    context.set(\"PayloadB\", msg.payloadB);\n    //\n    //  Icons.\n    //\n    context.set(\"icon_on\", msg.icon_on);\n    context.set(\"icon_off\", msg.icon_off);\n    //\n    //  Topic.\n    //\n    if (msg.topicSET !== null)\n    {\n        context.set(\"Topic\",msg.topicSET);\n    } else\n    {\n        context.set(\"Topic\",\"~\");\n    }\n    return;\n}\n//      Now on to the real stuff.\nif (msg.payload == \"X\")\n{\n    state = (state + 1)% 2;\n    //node.warn(state);\n    context.set(\"STATE\",state);\n} else if (msg.payload == \"Y\") {\n    state = 0;\n    context.set(\"STATE\",state);\n}\nif (state === 0)\n{\n    //  Condition A\n    msg.payload = context.get(\"PayloadA\");\n    msg.colour = context.get(\"ABGC\");\n    msg.txt = context.get(\"icon_off\")+context.get(\"Atxt\");\n    msg.fontclr = context.get(\"AFC\");\n    msg.icon = context.get(\"icon_off\");\n} else\n{\n    //  Condition B\n    msg.payload = context.get(\"PayloadB\");\n    msg.colour = context.get(\"BBGC\");\n    msg.txt = context.get(\"icon_on\")+context.get(\"Btxt\");\n    msg.fontclr = context.get(\"BFC\");\n    msg.icon = context.get(\"icon_on\");\n}\nif (context.get(\"Topic\") == \"~\")\n{\n    msg.topic = \"\";\n} else\n{\n    msg.topic = context.get(\"Topic\");\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":580,"y":280,"wires":[["66b52f17.b7153","160a1fd1.09f1f","e57debbf.de80a8"]]},{"id":"66b52f17.b7153","type":"ui_button","z":"9c27e8ba.02c398","name":"Ignitor","group":"559f6812.e7fd18","order":4,"width":3,"height":2,"passthru":false,"label":"{{msg.txt}}","tooltip":"","color":"{{msg.fontclr}}","bgcolor":"{{msg.colour}}","icon":"","payload":"X","payloadType":"str","topic":"","x":560,"y":230,"wires":[["711c541c.7108ac"]]},{"id":"6354d2ea.97ef7c","type":"function","z":"9c27e8ba.02c398","name":"Setup","func":"msg = {\n    \"colourA\": \"red\",\n    \"colourB\": \"green\",\n    \"txtA\": \"Off\",\n    \"txtB\": \"On\",\n    \"txtclrA\": \"black\",\n    \"txtclrB\": \"white\",\n    \"payloadA\": \"0\",\n    \"payloadB\": \"1\",\n    \"icon_off\": '<i class=\"fa fa-2x fa-bomb\"></i> ',\n    \"icon_on\": '<i class=\"fa fa-spinner fa-pulse fa-3x fa-fw\"></i> ',\n    \"topicSET\": \"channel_6\"\n}\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":280,"wires":[["711c541c.7108ac"]]},{"id":"f7f727e4.35bab8","type":"link in","z":"9c27e8ba.02c398","name":"","links":["b83a013.f422","9f2b93b.9819f7"],"x":445,"y":340,"wires":[["711c541c.7108ac"]]},{"id":"9f2b93b.9819f7","type":"link out","z":"9c27e8ba.02c398","name":"","links":["6e70941f.08214c","f7f727e4.35bab8"],"x":855,"y":280,"wires":[]},{"id":"160a1fd1.09f1f","type":"delay","z":"9c27e8ba.02c398","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":760,"y":280,"wires":[["9f2b93b.9819f7"]]},{"id":"2c961667.b0e8ca","type":"inject","z":"9c27e8ba.02c398","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":280,"wires":[["6354d2ea.97ef7c"]]},{"id":"e57debbf.de80a8","type":"debug","z":"9c27e8ba.02c398","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":750,"y":340,"wires":[]},{"id":"559f6812.e7fd18","type":"ui_group","z":"","name":"Ignitor","tab":"91b245b1.b4ed7","order":4,"disp":true,"width":5,"collapse":false},{"id":"91b245b1.b4ed7","type":"ui_tab","z":"","name":"Pump Control Dashboard","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

On line 4 of your function you do
if (msg.payload != "X") //Do this if the message is NOT "X"
Then on line 41 within that function you do return;
So the reset (payload = Y) on line 49 will never get called.

But you may be better off using a trigger node rather than a delay - as you can extend or ignore extra button pushes with that.

Yes... It's what happens sometimes when you build on the code of others....Will fix and post final working code tomorrow. Any example code you think better to do this?

Did you like the animated icon? :slight_smile:

Well personally I would just use a simple switch...

[{"id":"7744a7c5.619038","type":"ui_switch","z":"45e6afd1.58e2b","name":"","label":"Ignitor","tooltip":"","group":"cc2d9c9b.71d6d","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"fa-pulse fa-3x fa-spinner","oncolor":"green","offvalue":"false","offvalueType":"bool","officon":"fa-bomb fa-3x","offcolor":"red","x":450,"y":680,"wires":[["ab182c3d.ec4a6"]]},{"id":"ab182c3d.ec4a6","type":"trigger","z":"45e6afd1.58e2b","op1":"","op2":"false","op1type":"pay","op2type":"bool","duration":"3","extend":false,"second":false,"units":"s","reset":"","bytopic":"all","outputs":1,"name":"","x":620,"y":680,"wires":[["d2719d3d.8abe7","7744a7c5.619038"]]},{"id":"d2719d3d.8abe7","type":"debug","z":"45e6afd1.58e2b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":810,"y":680,"wires":[]},{"id":"cc2d9c9b.71d6d","type":"ui_group","z":"","name":"High Speed Capture","tab":"79cdaba9.8accc4","order":2,"disp":true,"width":"5","collapse":false},{"id":"79cdaba9.8accc4","type":"ui_tab","z":"","name":"Pump Control Dashboard","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

Oh that's so perfect. I have to use a virtual wire tomorrow from the ignition circuit to validate it fired.

Also I had a problem knowing if my solenoid valves actually operated. So I am working on a simple coil that goes between the valve electromagnet to read the magnetic field and the spike the valve moving should trigger on a Pi-Plate DAC

I am dealing with Hydrogen and Oxygen combinations and need no room for assumptions.

You are helping me with the greenest technology on the planet. It is in the high 90% and a fuel cell is only in the 50% range.

Because we use water as the flexible piston. Its just the coolest way to harness chemistry.

We only make a small amount of gas on demand to guarantee no catastrophic danger. But the pump is engineered to 10K PSIA

1 Like

@dceejay FYI Dave, running that flow, once you press the button, it goes into a loop. If you watch the debug, every 3 seconds you get two debug entries both showing false.

By adding a switch (checking true/false) after the button node, you can send the true on to what ever and after three seconds it will send false back to the button to shut it off. That false gets to the switch and goes out the false leg of the flow escaping the possible looping.

[{"id":"a25c5368.ecf148","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"c14d1fce.f2bf8","type":"ui_switch","z":"a25c5368.ecf148","name":"","label":"Ignitor","tooltip":"","group":"f6749f28.98aba8","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"fa-pulse fa-3x fa-spinner","oncolor":"green","offvalue":"false","offvalueType":"bool","officon":"fa-bomb fa-3x","offcolor":"red","x":150,"y":140,"wires":[["928a57e1.d80138"]]},{"id":"b4340acf.810958","type":"trigger","z":"a25c5368.ecf148","op1":"","op2":"false","op1type":"pay","op2type":"bool","duration":"3","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":480,"y":140,"wires":[["d552c58b.5a0b78","c14d1fce.f2bf8"]]},{"id":"d552c58b.5a0b78","type":"debug","z":"a25c5368.ecf148","name":"trigger","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":140,"wires":[]},{"id":"928a57e1.d80138","type":"switch","z":"a25c5368.ecf148","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":140,"wires":[["b4340acf.810958"],["871d0922.a29d3"]]},{"id":"871d0922.a29d3","type":"debug","z":"a25c5368.ecf148","name":"switch-false","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":490,"y":220,"wires":[]},{"id":"f6749f28.98aba8","type":"ui_group","z":"","name":"High Speed Capture","tab":"2a6ec3b9.70aecc","order":2,"disp":true,"width":"5","collapse":false},{"id":"2a6ec3b9.70aecc","type":"ui_tab","z":"","name":"Pump Control Dashboard","icon":"dashboard","order":3,"disabled":false,"hidden":false}]
1 Like

I had just discovered that and it was bogging down node-red. I had to tear it out and reboot to clear it.

I will try yours now.. Thank you.

I just installed it. It works perfect. It drives a digital corvette coil driven from a Pi-Plate DAC2 board.
It provides a great high speed discharge arc.

1 Like