@bkmj/node-red-contrib-flow-switch
v0.1.0
Published
Un nœud Node-RED qui agit comme un interrupteur avec un bouton UI sur le nœud.
Readme
Node-RED Contrib Flow Switch
A Node-RED node that acts as a switch to control the passage of messages, with a UI button directly on the node and the ability to control it via incoming messages.
[Image of an example of the flow-switch node in Node-RED]
Features
- Integrated UI Button: Toggle the node's state (ON/OFF) directly from the Node-RED editor by clicking the node's button.
- Message Control: Change the node's state by sending a message with a specific
msg.topicandmsg.payload. - Configurable Deploy State:
- Choose to initialize the node with a specific state (ON or OFF) upon each deployment.
- Or, retain the node's last active state before deployment.
- Customizable Status Texts: Define the texts displayed below the node for the ON and OFF states.
- Control Message Passthrough: Option to allow the control message to pass through to the node's output after it has acted on the switch.
- Internationalization: Support for English (en-US) and Canadian French (fr-CA) for the configuration interface.
Installation
To install this node:
Via npm (Recommended):
- Navigate to your Node-RED user directory (typically
~/.node-red). - Run the following command:
npm install @bkmj/node-red-contrib-flow-switch - Restart Node-RED.
(Note: If this package is not yet published to npm, you would typically install it by cloning the Git repository directly into your
~/.node-red/nodesdirectory and then restarting Node-RED.)- Navigate to your Node-RED user directory (typically
Configuration
When you add a flow-switch node to your flow, you can configure the following properties in its edit panel:
- Name: An optional name for this node instance.
- Behavior on Deploy:
Use 'Initial state on deploy' value: The node will adopt the state defined below upon each deployment.Keep last active state: The node will remember its last active state (ON/OFF) before deployment and restore it.
- Initial state on deploy: The state (on/off) the node will adopt if the above option is selected.
- Pass through control message?: If checked, the message that was used to control the switch will be forwarded to the node's output. Otherwise, it is consumed.
Status Display (under the node)
- Text if ON: The text to display below the node when the switch is ON (default: "on").
- Text if OFF: The text to display below the node when the switch is OFF (default: "off").
Control by Message
- Control Topic: The
msg.topicthe node will listen to for commands (default: "control"). - Control Values (
msg.payload):- for ON: The
msg.payloadthat will activate the switch (default: "on"). - for OFF: The
msg.payloadthat will deactivate the switch (default: "off"). - for Toggle: The
msg.payloadthat will invert the switch's state (default: "toggle").
- for ON: The
Usage
Via the UI Button
Click the button on the right side of the node in the Node-RED editor to change the switch's active state. The status under the node will update.
By Message
- Configure the "Control Topic" in the node's edit panel (e.g.,
cmnd/mySwitch/state). - Configure the "Control Values" for ON, OFF, and Toggle actions.
- Send a message to the
flow-switchnode with:msg.topicmatching the configured "Control Topic".msg.payloadmatching one of the configured "Control Values".
Example:
If "Control Topic" is control and "Value for ON" is true:
An incoming message with msg.topic = "control" and msg.payload = true will turn the switch ON.
Flow Behavior
- If the switch is ON, incoming messages (that are not control messages) are passed to the output.
- If the switch is OFF, incoming messages (that are not control messages) are blocked.
- Control messages are consumed by the node (do not pass to the output) unless the "Pass through control message?" option is checked.
Development
Language Files
Translations are managed in the locales directory.
locales/en-US/flow-switch.jsonfor English.locales/fr-CA/flow-switch.jsonfor Canadian French.
Feel free to contribute with other translations!
License
This project is licensed under the Apache-2.0 License.
