How do you organize common actions and tasks with node red

Have been using HASS for years now, back in the python venv days and have been recently struggling with consistency across my automations (and mountain of entities of course). I leverage node red for 99% of my automations and was curious how everyone organizes and keeps track of common actions or automations they might be triggering from multiple places. for example:

running the robot vacuum - i have an action to vacuum 3 specific rooms, lets say mudroom, kitchen, family room. Now there are obviously multiple ways this can be achieved (not limited to)

  • hass script invoked by call service node from node red
  • node red “send command” nodes copied and pasted to each trigger location
  • node red “actions” flow and link to a single “send command” node from each place where it will be triggered from
  • etc

ideally i would like a single source of truth so that as changes are made i dont have to chase down where that entity was used or where it might be used but at the same time i’m trying to avoid too many layers of obfuscation and bloat. i am interested to see how others have setup their structure and their flows from a conceptual level.

sometimes miss the days of yaml files with “find and replace” :slight_smile:

My Node Red automations are grouped into separate Flows (tabs) such as “Lights”, “AC/Heatpump”,“Presence”, and “Security”. This helps, and I can usually find what I’m looking for. But there are definitely overlaps and cross-flow situations such as when i adjust the lights based on security settings.

Recently I’ve started using a few Link Out and Link In nodes to help consolidate. For example, I have a Change Node that sets the message content followed by a Link Out node in quite a few different locations all connected to a single Link In node that is followed by the service calls that do the actual notification of my phone. In theory, this means that I can change the method/process/tools for my phone notifications just in one place. But I haven’t used this new method long enough to see if this will really provide much of a benefit over time.

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.

I do the same as @PecosKidd. I also use subflows.

So, my current flows (tabs) are: Timed Events, State Change Events, Alarms, Warnings, Notifications, and Test (an area where I can test flows). The majority of my link out connectors go from Alarms and Warnings to Notifications. The subflows are for common and/or complex flows (function nodes) that are reused across flows.

This helps me to keep organized and able to manage “common” stuff but I too am curious how others manage this.

I searched for “style” guides for Node-Red but my quick and dirty search did not produce anything worthwhile. Are there any style guides?

For the most part I just create a separate flow for each task, name them accordingly, and arrange them (tabs) alphabetically to make things easier to find. I’ve currently got 46 flows, and while there is overlap for some (things like lights that can be activated by motion, doors opening, presence, time of day or manually with remotes), I find it fairly easy to know where to look when something needs updated.

I have about 10 sub-flows, and those mostly arise for common/repetitive tasks like TTS notifications, or when a particular flow get’s so complicated that it helps to make it visually less cluttered.

When I need to update an entitiy that might be used in multiple locations, or just to check if I’ve missed anything, I sometimes stop Node Red and do a search/replace in the flows.json file.

I also have a flow named ‘Examples’ where I’ll keep samples of functions or nodes used to solve specific tasks, with a Comment Node for each to explain what it does. This allows for an easy copy/paste and saves a lot of poking around in the flows to find where I previously solved a problem.

@mightybosstone i started heading down this route but quickly got scared of the amount of tabs and finding things!

this is an interesting take. i do like being able to use java script vs yaml automation and i could put a lot more weight into the function node. recently i have played around with using “events” with a custom json object to route commands to the right places through switch nodes. seems like i could easily be collapse into a single function node and just expand as needed. thank you for the link, this is super helpful as i have never seen a function node this “large”.

here is an exampled of the event that gets triggered with a custom “event” object
bananana 2024-02-13 13-54-16

and then it gets routed to the appropriate call service node

i have also decided to start using groups, i have avoided them for so long because they are “manual” in the sense that i have to add things to it myself. i want to add a new water sensor and have it automatically added to the group because of a set of rules and i think it is time to just build a flow in node red to do this.

In the side panel info tab, you can search all flows by entities or any regular expression.

Screenshot 2024-02-13 134819

The number of a node in a debug message can also be entered in the search bar and it will take you to that node.

image

1 Like

well shit, i never knew that existed, that is super helpful. has node red slowed down for you with all of the flows? does it take longer to deploy and things?

When I click deploy there can be a little drag, a second or so. The actual execution of the automations is near instantaneous.

To be clear there is no noticeable difference between execution in HA vs nodered.

i guess i have always been worried about a mess of flows but otherwise it would just be a mess of scripts in hass. at least with flows you can have some level of organization

The side panel holds a lot of information. I find the debug panel a lot easier to use than looking at traces. There is a section in the side pane called context. It holds all the home assistant states in the global section. (hit the little refresh icon to populate).

There you can see all the different information that an entity holds and then just copy a path vs switching pages in dev tools. Also if you are storing varibles, you can see their values and whether or not they are updating as a flow executes.

All that info and I can still have my automation open and editable.

Edit: I might add nodered is a stand alone project, many people use it as their only automation system. There is also an industrial/commercial branch called flow fuse, so nodered is more than capable of handling anything we throw at it.

Same here - I had no idea you could search like that!

Thanks!

wow i have been missing so much, this is so useful for debugging. well i definitely am not as worried about flow sprawl as i was before, thank you

interesting about flow fuse, i was aware of apache nifi https://nifi.apache.org/ but this looks like it could be a direct challenger

This is what I was getting at before, it’s not just a flow based automation tool but a great learning aide as well. It reminds me a lot of scratch, a limited node based coding system for primarily teaching children.

It’s also the first thing you learn with harvard’s cs50(free class btw) intro to computer science, so it’s not just for kids. It’s a simple, fun way to learn how to make complicated actions based on simple logic statements.