The latest monster to rise from the slab:
All that, for this:
This convoluted beast lets me control a 4-channel Modbus controlled PWM/CV dimmer from a Node-RED dashboard, and programmatically - as well as by physical push buttons connected directly to the dimmer, which allows the dimmer to operate stand-alone when the computer (or network) is down. The Modbus registers on the dimmer are used as the definitive source for channel values (read every 5s), but I also store level and "state" for each channel in Node-RED, as well as min/max level allowed, so the UI remembers the slider positions when a channel is off (channel level = 0). The lowest slider setting does not represent "off", but the minimum level at which the connected LEDs produce light. Conversely, the highest slider setting is not necessarily "255", but the level where light output stops increasing - which may save a bit of power. These limits are enforced also for the physical buttons, albeit with a 5s lag - and only as long as the computer is running. UI actions inhibit Modbus polling for a moment, to prevent the state being changed by an incoming update before the UI action has completed. Slider movements are "pared" down to the last message in 500ms windows, to stop bus writes from piling up. An important feature is that it handles all four channels/registers in each Modbus read/write operation - which cuts bus traffic significantly.
Happy to answer questions - and to get suggestions for improvements!
modbus_dimmer_control_flow.json (17.3 KB)