通过 MQTT 更改 Node-RED UI 按钮颜色

Change Node-RED UI button color via MQTT

我在 raspberry pi 家庭安全网络上有一个红色节点流,使用 MQTT 作为消息总线。如何根据传入的 MQTT 消息更改 UI 按钮上的颜色?

我无法在任何地方找到有关如何执行此操作的任何示例。我想这将与 CSS 和 javascript 相关联,但我在这些领域很弱。

仪表板 ui 按钮的信息选项卡中描述了如何执行此操作:

The colours of the text and background may be set. They can also be set by a message property by setting the field to the name of the property, for example {{msg.background}}.

所以你可以通过这样配置按钮来设置按钮的背景:

然后将 msg.backgound 设置为您想要的颜色的消息传递给您(颜色可以是任何 CSS 颜色安全名称)。

您可以使用功能节点或更改节点将 background 属性 添加到 msg,然后再将其传递到 ui-button 节点。