I would like to dynamically change either the label or background color of nodes in a flow, when certain MQTT messages arrive. I know, that's slightly unusual, but I have a pretty specific use case where this makes sense (monitoring of a dozen or two of batch job states, where Node-RED is perfect as it allows for very powerful logic for controlling when/how each batch job is triggered).
I could probably use the UI elements of the dashboard.. but then I have to write custom html code etc. Don't want to go there, as Node-RED's regular flow view is very close to what I need.
The MQTT side works well, I can also change the node's status based on the MQTT messages (one strange thing there tho: no matter what I set the node's initial status to, it always shows up as green and "connected". Inherited from the MQTT config node somehow?).
The status indicators are kind of small though... I would prefer to have the node's background color change to red when certain error conditions occur, for example.
The docs are pretty clear that labels are not dynamically generated (https://nodered.org/docs/creating-nodes/appearance), but is that the case also for background color? I can't find anything in the docs stating this, giving me some hope it might be possible. Is it?
Hi @mountaindude - the node colour cannot be changed dynamically. The Editor is not meant to be used as a dashboard to reflect runtime state. The only thing the runtime can modify is the status indicator - https://nodered.org/docs/creating-nodes/status
Hypothetically, "IF" there was an access to the runtime event emitter, it would be possible, no ?
RED.events.emit("myCustomEvent")in the node JS file and something like
RED.events.on("myCustomEvent", callback ) in the node HTML file ?
hypothetically - If you really wanted to spend a lot of time sending things over websockets and killing whatever performance your Pi has left then ...
But as the editor is not a dashboard it won't be a problem.
I agree. There are already numerous ways to display "running" info in the NR editor: status, debug, console, ...
Hi @knolleary - I understand the background color cannot be changed dynamically at runtime as required by this topic. Would it be able to change the color when creating the flow by providing the color as a property of the node?
Our users want to use the same node in different flows for slightly different purpose. I understand now user can change the icons through the node setup, is it possible to change background color in the same way?
No, a node's colour cannot be changed, with one new exception - in 1.0, a Subflow node can have its colour set.
Thanks! I see it is not in the latest beta yet. I am looking forward to seeing it in the next beta or actual 1.0.
Hi. Sry to reopen such an old discussion, but I wanted to ask if there is still no (official) way in Node-RED 3 to dynamically change a node color or label.
I have an internal project where it would be nice to not only change the status but also the nodes groups color (= all nodes of a type in the active workspace).
I have found a semi-working way to do that by changing the nodes _def color and changing to another workflow tab.
The RED.view.redraw() alone doesn't do the trick, are there some flags which must be set?
Thanks in advance.
No, there isn't.
The "official" answer is that the Editor is not a status display. Of course, that message has somewhat been watered down over the years but it remains the case.
But then, the Editor IS "just" a web-page, a very complex and clever one to be sure, but still, you do get an amazing level of control over web pages.