Hello
Thanks to @knolleary for prompting me on twitter to pop some ideas down here on the forum. And a request for help!
New Node-RED convert here, and I have a "there are many ways to skin a cat" kind of question. Getting overwhelmed with the possible number of ways of doing it, so hoped someone could give me some practical suggestions. I think this may be more of a generic programming question than specific to Node-RED, but hopeful that there might be a Node-RED flavoured solution. Or that you might be kind enough to help me regardless.
I have around 40 light circuits to automate*, some switched, some dimmed, some RGBW. My question is not about driving the actuators from within Node-RED but more about how to go about designing the flows.
I'm moving a system over from openHAB to Node-RED, and I'm basing the flows around controlling lighting zones from a home-brew panel (check out my panel featured on Automated Home website - pics of it installed and general concept)
The panel (Arduino Mega) deals only with MQTT. It has no hard-coded values or configurations, it uses my own simple ZeroConfig style of boot sequence. It's currently working in the state described below, using openHAB to pull the puppet-strings, but I want to implement it in Node-RED and make it better.
When it boots, here's what happens:
-
Arduino sends its MAC address on an MQTT topic dedicated to ZeroConfig:
home/megasetup
-
Automation hub (i.e. Node-RED) sends back configuration info on a topic dedicated to that controller:
home/megasetup/DEEDBAFEFEED
... this is done in sequence
- payload =
ZONENAME LG_Bedroom
(name of zone) - payload =
ZONEVECT bedroom
(this is used to tell the Arduino on what topic to start publishing its commands to control lights, this translates tohome/bedroom/light/xyz
) - payload =
ZONESENS 25
(some other stuff to customise this panel - this particular item sets the touch sensitivity for proximity sensing)
- After this, the Arduino then sends messages in sequence asking for two types of information: configuration info and current values. It does so on the topic it has just learned about:
- topic
home/bedroom/megacmd
circuit_count_please
circuit 1 name please
-
circuit 2 name please
etc. light preset 1 name please
-
light preset 2 name please
etc. -
circuit 1 level please
etc. album title please
album artist please
song title please
-
playpause status please
...
and a whole LOAD of other things, moving into heating, weather, room temperature / humidity sensors etc.!
-
The automation hub responds with answers to these requests. It doesn't matter when it responds - it will simply fill out the values then display them on the screen at any point from there onwards in the sketch. Each response is on a dedicated topic.
-
Then when you press buttons etc., the Arduino sends commands on a single topic for that particular controller,
home/bedroom/megacmd
(thebedroom
part it learnt about in ZeroConfig)
- example, when the dimmer is turned, it fires off a load of
light_1_up
orlight_2_down
commands, whatever circuit is selected. The automation hub must then get the current light level, add 2 to it, set it back into a variable, and of course actuate the change by sending an RF message (or in the case of my new home, it will be sending another MQTT message to the DMX controller Arduino). This happens quickly so the user sees the light dimming up gradually.
In openHAB I was able - just about - to programatically query the items in a group to determine how many light circuits there were, and it determined their names by looking at the "item" name. Item name would be LG_Bedroom_Ceiling
, and it split the string and therefore the circuit name would be sent out as "Ceiling".
Presets needed storing: the names of 5 presets (Sleep, Bedtime, Working, Reading, Full) and each preset stored arrays of values for each light. Obviously the array length is determined by the number of circuits in that zone.
Incidentally one main reason to move away form openHAB for rules processing is that I find OH slow and unreliable. Occasionally there seem to be timing issue in responding to requests, mainly because of the rule processing engine. This is running on a virtual server on a proper Dell server with fast SSDs in RAID 10, and with 128GB RAM ... so yeh. I tried.
My question is this. How should I approach this, generally. How do I define these items in Node-RED, so that I can e.g. dynamically query the number of curcuits in a zone? That should be easy. But what about this: how to dynamically assign values for stored light values within presets, given the number of circuits in a given zone can vary? Right now in openHAB I have a ridiculous amount of static variables like so:
I literally wouldn't know where to start in defining these dynamically. I'm not a great software designer, I just play and hack and make things work the best I can - mostly in an awkward way.
Should I be highly programmatic, which essentially takes away from the visual nature of Node-RED and hides the detail in functions?
Should I keep it visual and more static, but there will be a lot of repetition, and every time I need to add a circuit I need to remember to update the circuit number variable, as well as updating all the presets for that zone, etc.?
And are there any obvious things I should start with, that Node-RED is just screaming out to be used for in this context?
Sorry for such a high level question. It's definitely not "stack exchange" ready and I'm taking the name of this forum to heart ("discourse") But I'd very much appreciate an exchange of ideas!
I'm most keen on setting this up so it's easy to change configuration later, and maybe even be able to document it for a less technical person to try and change later if necessary.
Finally - massive curveball. I may decide it's best to store as much of the definition of the lighting system (e.g. presets, circuit definitions, etc.) in an Arduino, and be able to somehow configure this from time to time using Node-RED as a configuration proxy. This strikes me as more reliable, and would mean that if a server went down, the lighting would still work. Better in the event that a server could fail at some stage. Should I push for that, or abandon the idea and make it depend on a server with an OS?
Thanks
Mat
(*) Incidentally I don't have all of these circuits yet, but I have the DMX dimmers and a shell of a house that is being built! Right now I'm using LightwaveRF actuators in my "test home" which is a smaller flat....