node-red-contrib-flowswitch 0.1.3

A Node-RED node that allows messages to pass through based on on/off state

npm install node-red-contrib-flowswitch

FlowSwitch Node for Node-RED

FlowSwitch is a custom node for Node-RED that allows you to control the flow of messages through your automation workflows. It acts as an switch: when on, it lets messages pass; when off, it blocks messages from continuing through. This makes it easy to dynamically enable or disable parts of your Node-RED flows without requiring a deploy.

Features

  • Dynamic control: Change the switch state via an input message.
  • UI indicator: Visual representation of the switch state (active/inactive) in the Node-RED editor.
  • Status output: A second output emits status changes (current on/off state).
  • Persistent state: The switch state can survive Node-RED redeploys and reboots when a persistent context store is configured.

Installation

To enable persistent state storage, add a persistent context store to your Node-RED settings.js. For example, to use the local filesystem store add:

contextStorage: {
    default: {
        module: "localfilesystem"
    }
},

Restart Node-RED after changing settings.js.

Usage

  • Send messages with msg.topic === "flowswitch" and set msg.payload to control the node.
    • Accepted payloads for ON: true, 1, "1", "ON", "On", "on", "yes"
    • Accepted payloads for OFF: false, 0, "0", "OFF", "Off", "off", "no"
    • Additional control commands:
      • toggle (case-insensitive): flip the current state.
      • query (case-insensitive): return the current state on the third output without changing it.
  • Outputs:
    1. First output: passes through the input message when the node is ON.
    2. Second output: emits last input message what received when node was ON
    3. Thirt output: emits a status message when the switch state changes (payload contains the new boolean state).
  • When the node is OFF, messages are blocked from the first output. The second output is used for state notifications.

Example Use Cases

  • Persistent UI switches: have a dashboard switch that retains its state across reboots and redeploys.
  • State source: maintain an authoritative on/off state for relays, automations or groups of flows.
  • Control gating: lock controls in a dashboard

License

This project is licensed under the MIT License.

Contribution

Contributions are welcome. Please fork the repository and submit a pull request to improve functionality or documentation.

Acknowledgements

This node was created to provide an easy way to maintain authoritative switch state and filter events across flows. It was adapted from ideas in the FlowGate node: https://github.com/gmag11/node-red-contrib-flowgate

Node Info

Version: 0.1.3
Updated 4 days ago
License: MIT
Rating: not yet rated

Categories

Actions

Rate:

Downloads

0 in the last week

Nodes

  • flowswitch

Keywords

  • node-red
  • toggle
  • flowswitch
  • StreamSwitch
  • node-red-contrib

Maintainers