npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-red-contrib-toggle

v0.1.1

Published

Toggle switch node for Node-red

Downloads

1,182

Readme

node-red-contrib-toggle

Toggle switch node for Node-red.

This node is a companion for any switch (physical or virtual), storing its state and providing toggle operation without need of using function nodes or flow/global variables.

node-appearance
Fig. 1: Node appearance

Installation

In Node-RED (preferred)

  • Via Manage Palette -> Search for "node-red-contrib-toggle"

In a shell

  • go to the Node-RED installation folder, e.g.: ~/.node-red
  • run npm install node-red-contrib-toggle

Usage

Node Configuration

The node configuration sets the active on/off/toggle keywords as well as optional topic names.

node-settings
Fig. 2: Node properties

ON value / OFF value / Toggle value

These attributes can be of type

  • string
  • number
  • boolean

They are set to the values you want to be the keywords within msg.payload when the actions switch to ON, switch to OFF and toggle shall take place (execution command).

Remark: If you do not set a value to one of the attributes the according method (e.g. switch ON) can not be executed by the node (it needs a value to compare...).

On/Off topic resp. Toggle topic (optional)

If you set the topic attributes to a value, the input msg needs to contain the same topic name to execute On/Off resp. toggle in addition to the msg.payload value containing the execution command.

Pass through ON/OFF messages

The node has three pass through modes:

  • No - means that node sends an output msg only when state is toggled. ON/OFF input messages just update internal state of the node.
  • If changed - sends an output msg for ON/OFF input message only once it differs from the previous state. And obviously message is always sent for "toggle" message.
  • Always - the output msg is always sent as a reaction on an input msg.

Input

The input msg.payload contains the execution command to the node.
The value needs to be identical to the values you configured in the configuration dialog.

If a (string) value is set to the configuration attributes On/Off topic or Toggle topic, the msg.topic property must contain the same string value to execute the command given in msg.payload.

An example msg contents is shown for On/Off topic = "onofftopic":

node-settings
Fig. 3: Example msg when using topics

Output

The input msg is forwarded to the output, if a valid switch command was detected.
The configuration attribute pass through ON/OFF messages is taken into account.

Node status

The node status signals:

  • If the switch status is on it shows a green dot with the text ON.
  • If the switch status is off it shows a red dot with the text OFF.

Initially it shows no state.

Examples


Remark: Example flows are present in the examples subdirectory. In Node-RED they can be imported via the import function and then selecting Examples in the vertical tab menue.


Example 1: Basic ON/OFF usage

This example shows the basic usage of the on and off commands.
The configuration is set to boolean true resp. false to switch on resp. switch off and no toggle option.

BasicUsage.json
Fig. 4: Basic usage example

Example 2: Basic toggle usage

This example shows the basic usage of the toggle command.
The configuration is set to boolean true resp. false and to toggle with all other msg.payload/msg.topic combinations.

ToggleUsage.json
Fig. 5: Toggle usage example

Example 3: Usage with topics

This example shows the usage of topics.
The configuration is set to strings (switchON, switchOFF) to switch on resp. off and a string (toggleSTATE) to toggle the switch.
Additionally, the topics are set to onofftopic (for the commands switchON and switchOFF) and to toggletopic for the toggle operation (command toggleSTATE).

TopicUsage.json
Fig. 6: Topic usage example

Version history

v0.1.1 Toggle example added to docu
v0.1.0 Docu rework

v0.0.2 Docs updated

v0.0.1 Initial release

Credits