node-red-contrib-toggle

raw JSON →
0.1.1 verified Sat May 09 auth: no javascript

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.

error Error: Cannot find module 'node-red-contrib-toggle'
cause Package not installed in Node-RED user directory (~/.node-red) or global.
fix
cd ~/.node-red && npm install node-red-contrib-toggle
error TypeError: Cannot read property 'registerType' of undefined
cause 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.
error Node not appearing in palette after install
cause Node-RED not restarted or dependencies missing.
fix
Restart Node-RED; verify package.json has 'node-red' in 'keywords' or 'node-red' section.
gotcha Node 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.
gotcha If 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.
deprecated No known deprecations in version 0.1.1.
breaking Breaking changes between versions may exist but are undocumented due to early stage.
fix Check release notes or source history for changes.
gotcha Pass-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.
npm install node-red-contrib-toggle
yarn add node-red-contrib-toggle
pnpm add node-red-contrib-toggle

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.