In short I am looking for guidelines/tips on how to keep larger / more complex projects manageable in Node-RED. What follows are details on my situation and where I run into these issues.
I'm using Node-RED primarily for home automation and I've been stuck on some things. I learned to program in Java and PHP. When thinking about code I tend to think in a 'divide and conquer' kind of approach where you go more and more detailed and don't want higher levels to have to worry about the details of an implementation. Practically speaking, I have 3 types of lights at home, but at the highest level, I just want to send the same commands to turn them on, off or toggle and then at a lower level that would get converted to what a specific light needs (and in the case of a toggle that's not supported by the light itself I might keep track of the light's state there).
I can sort of accomplish this by having a lights flow and then different flows for the different light types. But as I implement more and more I start needing a lot of flows and it feels like I am losing the general overview. Currently I have the actual logic for what to do when in one flow, so that I may more easily re-use bits of code as for example I may have several different ways to turn on a light (in the case of my bedroom a MyStrom button on the wall and an M5Stack Core on my nightstand). As I find myself doing more and more for my home automation especially the logic flow starts getting very complex with many lines crossing as I wouldn't want to have duplicate code. I realize I could probably create and re-use subflows, I am already doing that in places, but I fear that ultimately even that becomes very complex.
Most examples I have been able to find on how to do things in Node-RED have been small flows to demonstrate a node or principle, what I wonder is if there are some guidelines somewhere on how to structure larger projects?
Additionally I find myself wanting to keep track of a lot of states. I understand that I could use flow or global variables, or perhaps store them in MQTT. How do you generally approach this for larger projects? This is the reason I've been looking at adding Home Assistant into the mix, because as I understand it, it's pretty good at keeping track of states, but if I am honest every time I check it out the interface confuses me and I don't think my project structure would get any better with it in the mix. On the other hand it feels like if I was using MQTT for this I would sort of make my own limited HA. I do like the idea of everything working through MQTT as I could have a lot of small bits of code triggering on changes and then writing back their values, which might then be monitored by another bit of code (making it easy to re-use as you just need to set a value in MQTT). Downside is an outside dependency and communication speed, it feels like there should be a Node-RED internal way to do something similar.
I've been looking at using openHASP to create little dashboards to show on M5Stack Core2 devices I have on my walls. I know I will need to keep track of quite a few things and inserting this into my current setup is probably going to increase the complexity quite a lot, so hence my questions at this time as it may be wise to re-structure everything so that it becomes easier to add this and other functionalities in the future (controlling where music is playing through Foobar2000/HEOS is also on my wish list for example, another fairly complex addition if I want it controllable through these dashboards).
Thanks!