Node-Red Flow Samples/Sharing

Wanted to post this here from the Node-RED thread.. more JSONATA fun!

Cross posting a solution for downloading the latest HE backup (not a new backup) with Node-red and appending the timestamp of the backup to the file name. The flow is in the post below:

UPDATE: I found a cleaner way of getting to the last row of the backup table by using different CSS selectors (the posted flow uses the "TD" tag and loops through the resulting array to get the date/time of the backup). The method below returns the data of the last row (latest backup) directly.

4 Likes

Because I can't seem to let the whole multi-tap thing go... here is a simple subflow that encapsulates the timed-counter & switch so you can separate single/double/triple/quadruple+ taps after a button press .. Also you set the timing in the properties of the subflow instance node.. default is 450 ms. Note: On my system (C-4) Lutron 5 button picos the 2 & 4 buttons seem to need a bit longer time for multi tap at 700 ms..

Not shown on this partial sequence is "Increase" and "Decrease" Levels - Thanks to multi tap I can control dimming on 2 different sets of lights with one set of up/down buttons.. of course you have to be careful and not click up or down too fast when accessing single tap set.. but it's pretty intuitive once you get the hang of it.

Make sure you install the "node-red-contrib-timed-counter" node before importing this...

Button Taps

[{"id":"d0e305e1.7ad558","type":"subflow","name":"Button Taps","info":"","category":"","in":[{"x":50,"y":30,"wires":[{"id":"4e584c74.8f1724"}]}],"out":[{"x":640,"y":40,"wires":[{"id":"959b5260.c1c1c","port":0}]},{"x":640,"y":100,"wires":[{"id":"959b5260.c1c1c","port":1}]},{"x":640,"y":160,"wires":[{"id":"959b5260.c1c1c","port":2}]},{"x":640,"y":220,"wires":[{"id":"959b5260.c1c1c","port":3}]}],"env":[{"name":"TIME_LIMIT_MS","type":"num","value":"450"}],"color":"#E2D96E","inputLabels":["Button Press"],"outputLabels":["Single Tap","Double Tap","Triple Tap","Quad+ Tap"],"icon":"node-red-dashboard/ui_button.png","status":{"x":640,"y":280,"wires":[{"id":"b4ba35d5.020018","port":0}]}},{"id":"959b5260.c1c1c","type":"switch","z":"d0e305e1.7ad558","name":"Single Tap \\n Double Tap \\n Triple Tap \\n Quad+ Tap","property":"count","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"str"},{"t":"gte","v":"4","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":430,"y":80,"wires":[[],[],[],[]]},{"id":"4e584c74.8f1724","type":"timed-counter","z":"d0e305e1.7ad558","name":"","timelimit":"${TIME_LIMIT_MS}","timeunit":1,"withhold":true,"fixedtimeout":false,"pertopic":false,"x":200,"y":80,"wires":[["959b5260.c1c1c","b4ba35d5.020018"]]},{"id":"b4ba35d5.020018","type":"function","z":"d0e305e1.7ad558","name":"set status payload","func":"\nvar payload = {\n\"fill\": \"green\",\n\"shape\":\"dot\",\n\"text\": ( msg.count == 1 ? \"Single\" : (msg.count == 2 ? \"Double\": (msg.count == 3 ? \"Triple\": (msg.count == 4 ? \"Quadruple\": msg.count.toString() )))) + \" Tap\"\n};\n\nmsg.payload = payload;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":410,"y":160,"wires":[[]]},{"id":"72661f7b.08887","type":"subflow:d0e305e1.7ad558","z":"af91369d.586338","name":"","x":880,"y":1980,"wires":[[],[],[],[]]}]


EDIT: Latest is here...

4 Likes

That's a nice little node. It removes the need for about 5 standard nodes. Thanks!

1 Like

This is a generic suggestion/tip. If you stop NodeRED by killing it, then it is preferred to use SIGINT over SIGKILL. SIGINT flushes all writes to disk before exiting the NR process cleanly, while SIGKILL terminates the process abruptly.

Edit: This is particularly important if your flows rely on storing context data on the local filesystem.

5 Likes

@mike - Have been having fun playing around with finite state machines. Wanted to post an image of my simple sequence I've done to handle timed lighting controls based on home/away + guests.

I am using the "node-red-contrib-finite-state-machine" node vs "node-red-contrib-state-machine" node - I kinda like the ability to code in the transitions via JSON. Also note - I left out the actual light control part. For that I have separate sublows for each state and am using the "node-red-contrib-presence-faker" node to control timing/on/off etc...

As an aside - I'm a really "fascinating" and "interesting" guy apparently at least according to my wife. :laughing: :thinking: :cry:

4 Likes

A totally non-biased view. :stuck_out_tongue_winking_eye:

Sadly my wife's comments are usually sarcastic and more often accurate in their intent than I would care to admit.. ah well what does she know about the thrill of Finite State Machine transitions anyway?

:rofl:

1 Like

I suggest you ask her.
:rofl:

Well I tried and that's why I ended up posting here.. :rofl:

3 Likes

That looks good. I might transition. The one I use has a start up error that I asked about here.

1 Like

I did not really test the node-red-contrib-state-machine node because I mistakenly thought you were referring to the node-red-contrib-finite-statemachine node and installed that instead. Since I was able to get it to work and it was updated more recently I decided to keep it instead.

You should be able to easily port your sequence over though.. except for the JSON config bit they seem very similar.

Oh did you check out this one? Looks like you can update from your node and not worry about anything.

That does look interesting. How does one delete a node type when it's in use? It doesnt seem intuitive (to me).

@mike - probably via the command line and npm... would back everything up first though.

Something like this from the Node-RED directory:

npm uninstall node-red-contrib-state-machine
npm i node-red-contrib-persistent-fsm

Then restart - I had to do something similar for the Alexa CakeBread node update.

1 Like

Thanks, that was perfect. I initially tried it in the wrong Node Red directory, but had a second go in the right directory. It all works, without hours of fixing. Thanks!

1 Like

Has anyone got a flow to get the wan IP address of their router? Was just looking at the Remote Admin thread and got me to thinking this would be useful if you don't have a static address assigned by your ISP and you could get an email or notification when the address changes.

Yep.

[{"id":"a09b3bd.8915bc8","type":"inject","z":"5c6662a7.2c252c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3600","crontab":"","once":true,"onceDelay":"120","topic":"","payload":"","payloadType":"date","x":190,"y":160,"wires":[["3f7a6cc3.64ad74"]]},{"id":"5864920b.31491c","type":"switch","z":"5c6662a7.2c252c","name":"","property":"payload.publicIPv4","propertyType":"msg","rules":[{"t":"eq","v":"publicIP","vt":"flow"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":530,"y":160,"wires":[["444aaea.c21305"],["596f2616.aaedd8","cb730a2e.6d1518","d88731a4.c8589"]]},{"id":"596f2616.aaedd8","type":"change","z":"5c6662a7.2c252c","name":"Store IPv4 ","rules":[{"t":"set","p":"publicIP","pt":"flow","to":"payload.publicIPv4","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":160,"wires":[[]]},{"id":"cb730a2e.6d1518","type":"change","z":"5c6662a7.2c252c","name":"Pushover","rules":[{"t":"set","p":"device","pt":"msg","to":"Mike","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"\"IP Address changed to \" & $.payload.publicIPv4 & \"\"","tot":"jsonata"},{"t":"set","p":"sound","pt":"msg","to":"none","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":200,"wires":[["bcec03a0.1f11f"]]},{"id":"3f7a6cc3.64ad74","type":"ip","z":"5c6662a7.2c252c","name":"ip","https":false,"timeout":"5000","internalIPv4":true,"internalIPv6":true,"publicIPv4":true,"publicIPv6":false,"x":370,"y":160,"wires":[["5864920b.31491c"]]},{"id":"444aaea.c21305","type":"rbe","z":"5c6662a7.2c252c","name":"","func":"rbei","gap":"","start":"","inout":"out","septopics":false,"property":"payload.publicIPv4","x":770,"y":120,"wires":[["f2678e98.6865c"]]}]
2 Likes

Thanks - is that the node-red-contrib-ip node?

Yes. node-red-contrib-ip

I also have a pushover notification coming out of the top switch, which I removed....it notifies me of the change in public IP address.

3 Likes