Dynamically changing node color or label


#1

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?

Thanks!


#3

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


#4

Hypothetically, "IF" there was an access to the runtime event emitter, it would be possible, no ?
Something like RED.events.emit("myCustomEvent")in the node JS file and something like RED.events.on("myCustomEvent", callback ) in the node HTML file ?


#5

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.


#6

I agree. There are already numerous ways to display "running" info in the NR editor: status, debug, console, ...