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

@zebrajaeger/node-red-contrib-universal-counter

v1.0.0

Published

Configurable universal counter node for Node-RED

Downloads

46

Readme

Universal Counter Node for Node-RED

The Universal Counter Node for Node-RED is a configurable counter that allows you to increment, decrement, and set values based on a defined range. This node supports multiple control methods through different input topics and enables fine-grained control over the counter's behavior.

Features

  • Configurable Range: You can define a range of values or specific values for the counter.
  • Increment and Decrement: The counter supports incrementing and decrementing by 1 or a custom value.
  • Set Initial Value: Set the initial value for the counter.
  • Flexible Input: Multiple input topics to control the counter state.
  • Reset Function: Reset the counter to its starting state.
  • State Tracking: Current value is tracked and output at each change.
  • Status Indicators: Visual status to indicate the state of the counter.

Installation

  1. Install the node in your Node-RED environment:

    npm install @zebrajaeger/node-red-contrib-universal-counter

Then restart Node-RED.

Configuration

Node Properties

Properties

  • Name: The name of the node.
  • Range*: A configurable range for the counter. You can specify ranges or individual values (e.g., 1..10, 5,7,9).
  • Initial Value: The initial value of the counter, which must be within the specified range.

Inputs

The Universal Counter node has one input, which expects a message with a topic and payload. The behavior is determined based on the topic:

  • r, rst, reset: Resets the counter and outputs the value from the range corresponding to index 0.
  • val, setValue: Sets the counter's value based on the provided payload. The value must exist within the defined range.
  • i, idx, setIndex: Sets the counter's index based on the provided payload (a number). The index must be valid within the defined range.
  • ++, inc, increment: Increments the counter by 1 or a specified value.
  • --, dec, decrement: Decrements the counter by 1 or a specified value.

Outputs

The node has one output that returns the current counter value.

Input Example

Send a message with the topic increment to increase the counter by 1:

{
  "topic": "increment"
}

Send a message with the topic setValue and a payload of 8 to set the counter to 8:

{
  "topic": "setValue",
  "payload": 8
}

Output Example

Send a message with the topic increment to increase the counter by 1:

{
  "payload": 8
}

Example Flow

Below is an example flow for using the Universal Counter node in Node-RED:

Example flow

[
    {
        "id": "ada1fd42d961c385",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "85d0673b4acf52e3",
        "type": "universal-counter",
        "z": "ada1fd42d961c385",
        "name": "",
        "range": "1..5,7,9",
        "initialValue": "2",
        "x": 750,
        "y": 420,
        "wires": [
            [
                "f08777574d2e58a9"
            ]
        ]
    },
    {
        "id": "f30256631cddd3bf",
        "type": "inject",
        "z": "ada1fd42d961c385",
        "name": "reset",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "reset",
        "x": 490,
        "y": 160,
        "wires": [
            [
                "85d0673b4acf52e3"
            ]
        ]
    },
    {
        "id": "3a4ac7e9829edefe",
        "type": "inject",
        "z": "ada1fd42d961c385",
        "name": "inc",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "++",
        "x": 490,
        "y": 220,
        "wires": [
            [
                "85d0673b4acf52e3"
            ]
        ]
    },
    {
        "id": "49439c55b89c7cde",
        "type": "inject",
        "z": "ada1fd42d961c385",
        "name": "dec",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "--",
        "x": 490,
        "y": 280,
        "wires": [
            [
                "85d0673b4acf52e3"
            ]
        ]
    },
    {
        "id": "6f0a2aa4fe576c5a",
        "type": "inject",
        "z": "ada1fd42d961c385",
        "name": "+3",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "++",
        "payload": "3",
        "payloadType": "num",
        "x": 490,
        "y": 340,
        "wires": [
            [
                "85d0673b4acf52e3"
            ]
        ]
    },
    {
        "id": "09143e879192b8b9",
        "type": "inject",
        "z": "ada1fd42d961c385",
        "name": "-3",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "--",
        "payload": "3",
        "payloadType": "num",
        "x": 490,
        "y": 400,
        "wires": [
            [
                "85d0673b4acf52e3"
            ]
        ]
    },
    {
        "id": "035811e7dd29efe8",
        "type": "inject",
        "z": "ada1fd42d961c385",
        "name": "+33",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "++",
        "payload": "33",
        "payloadType": "num",
        "x": 490,
        "y": 460,
        "wires": [
            [
                "85d0673b4acf52e3"
            ]
        ]
    },
    {
        "id": "57fedcc5ec42baec",
        "type": "inject",
        "z": "ada1fd42d961c385",
        "name": "i=3",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "setIndex",
        "payload": "3",
        "payloadType": "num",
        "x": 490,
        "y": 520,
        "wires": [
            [
                "85d0673b4acf52e3"
            ]
        ]
    },
    {
        "id": "b77e930df0e29c2b",
        "type": "inject",
        "z": "ada1fd42d961c385",
        "name": "v=3",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "setValue",
        "payload": "3",
        "payloadType": "num",
        "x": 490,
        "y": 580,
        "wires": [
            [
                "85d0673b4acf52e3"
            ]
        ]
    },
    {
        "id": "38faadea2dc1866d",
        "type": "inject",
        "z": "ada1fd42d961c385",
        "name": "!!! i=55",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "setIndex",
        "payload": "55",
        "payloadType": "num",
        "x": 490,
        "y": 640,
        "wires": [
            [
                "85d0673b4acf52e3"
            ]
        ]
    },
    {
        "id": "55cf54ddefa44d1c",
        "type": "inject",
        "z": "ada1fd42d961c385",
        "name": "!!! v=55",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "setValue",
        "payload": "55",
        "payloadType": "num",
        "x": 490,
        "y": 700,
        "wires": [
            [
                "85d0673b4acf52e3"
            ]
        ]
    },
    {
        "id": "f08777574d2e58a9",
        "type": "debug",
        "z": "ada1fd42d961c385",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 960,
        "y": 420,
        "wires": []
    }
]