Registry / web-framework / node-red-contrib-toggle

node-red-contrib-toggle

JSON →
library0.1.1jsnpmunverified

Toggle switch node for Node-RED that stores state and provides ON/OFF/toggle operations without function nodes or flow variables. Version 0.1.1 is current. Configuration supports string, number, or boolean payloads, optional topic filtering, and three pass-through modes: never, on change, or always. Output msg forwards on valid command with state indicated by node status (green/red dot). Compatible with Node-RED 1.x+. Differentiators: no coding required, state persistence across flows, simple visual interface.

npm install node-red-contrib-toggle
INSTALL
IMPORT
SIG · NODE-RED-CONTRIB-T
N
node-red-contrib-toggle
web-frameworkjavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import toggle from 'node-red-contrib-toggle';
const toggle = require('node-red-contrib-toggle');
Node-RED nodes are CommonJS modules; ESM import may not work depending on Node-RED version.
RED
const RED = require('node-red');
Node-RED runtime object required for node registration.
toggleNode
RED.nodes.registerType('toggle', toggleNode);
export function toggleNode() {}
Node-RED uses CommonJS and registerType, not ES modules.

Basic installation and usage of toggle node with inject nodes.

// Example: Create a flow using node-red-contrib-toggle // 1. Install: npm install node-red-contrib-toggle // 2. In Node-RED UI, drag a 'toggle' node onto canvas // 3. Configure: set ON value to true, OFF value to false, Toggle value to 'toggle' // 4. Connect an inject node (msg.payload = true) to turn on // 5. Connect another inject node (msg.payload = 'toggle') to toggle // 6. Deploy and see green dot when on, red when off.
Debug
Known issues
gotchaNode only processes messages if msg.topic matches configured topic (if set). Incoming messages without matching topic are ignored silently.
fix
Ensure msg.topic matches the 'On/Off topic' or 'Toggle topic' if configured, or leave topic fields empty.
affects: >=0.0.0
gotchaIf ON value or OFF value is not set, the corresponding command is ignored. Node will not switch to that state.
fix
Always configure both ON and OFF values if you need both operations.
affects: >=0.0.0
deprecatedNo known deprecations in version 0.1.1.
affects: 0.1.1
breakingBreaking changes between versions may exist but are undocumented due to early stage.
fix
Check release notes or source history for changes.
affects: >=0.0.0
gotchaPass-through modes: 'No' only outputs on toggle; 'If changed' outputs ON/OFF only if state changes; 'Always' outputs every valid input. Misunderstanding leads to missing outputs.
fix
Choose pass-through mode based on desired behavior: use 'Always' for immediate feedback, 'If changed' for state change only, 'No' for toggle-only.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'node-red-contrib-toggle'
Package not installed in Node-RED user directory (~/.node-red) or global.
fix
cd ~/.node-red && npm install node-red-contrib-toggle
TypeError: Cannot read property 'registerType' of undefined
Node-RED runtime not initialized before attempting to register node.
fix
Ensure node is loaded within Node-RED via standard node discovery; do not require() from standalone script.
Node not appearing in palette after install
Node-RED not restarted or dependencies missing.
fix
Restart Node-RED; verify package.json has 'node-red' in 'keywords' or 'node-red' section.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
node-redrequiredPeer dependency: requires Node-RED runtime to install and run nodes.
Agent activity
2 hits · last 30 days
node
2
Resources
node-red-contrib-toggle — npm install node-red-contrib-toggle · libregistry