I just started revamping all my flows. After about a year hiatus, didn’t really add/no real problems. I came back and looked at my flows and it was impossible to see what they were doing.
I have a lot of jsonata going on and without opening each node, I have an idea but do not know exactly what it is doing. I realized that in essence, I was passing a message down a grape vine to make all these little changes along the way.
Because of that, these messages become really narrow or specialized for one specific purpose. This makes it hard to piggy back off an existing flow. Which in turn makes you create another flow. This is fine and is nodered’s intended purpose.
Dealing with all the little pieces, for me, gave me a strong understanding of the big picture. The entire event and all the information that comes with it. So why am I picking little specialized parts of it? Why not deal with all that data in a way that there is more flexibility?
Enter the function node. I know, we went to nodered to get away from coding. I don’t believe that is the case. I think working with all those little pieces leads you here. You might be thinking fine but I still don’t know how to code, well neither do I.
The strange thing, to a workable degree, I understand it. This is after a year break with no exposure. I don’t think this is just me, I think this would be true of any nodered user that often uses jsonata.
Java script just seems sooo much easier than HA’s jinja template syntax, I find it more consistant. WIth that I started with the raw event of my xvr with 10 security cameras. I grab the event and pull everything relevant into variables.
The function node allows you to add outputs and then build separate messages for each output. So I originally had one output for a snapshot & text message. Ten cameras can quickly overload a single snapshot call service, so I add another output that alternates feeding 2 separate call service nodes.
I broke out a dedicated tts output. Then I added a set of conditional cards that would display the last motion. It’s tied to an input number. Since I have the camera number isolated in a variable, I added an output that sends only that number.
I’ve been documenting it here. If you look at the revisions of camera.js
, It will highlight the blocks I added and they should be labeled for their purpose. I can’t say what I did is the right way but after a lot of trial and error, it all works as intended.
W3 is mainly what I used as reference. The main take away is work with varibles as much as possible. Also HA groups should be used in liu of actual entities as much as possible. It’s easy to change or add to them without having to change the entity you use in an automation.