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-dynamic-dimmer

v1.4.0

Published

A dimmer node for Node-RED

Downloads

326

Readme

node-red-contrib-dynamic-dimmer

Coveralls github platform

The Dynamic Dimmer node for Node-RED was build to mimic the behavior of a physical dimmer switch. A typical use case for this node is the dimming of light bulbs (e.g. Ikea Trådfri bulbs) to a given brightness. In general, it allows a linear animation/easing of a value over a certain time frame.

Credits

How to use this node

Similar to a physical dimmer switch, you can specify the desired brightness, or any other parameter, with a input (msg.payload) between [0,1]. The node will then start to emit a series of values in a certain interval until the expected value is reached.

Node configuration

  • Minimum / Maximum value: the range of the the output values
  • Steps: the number of steps between the min and max
  • Event interval: the interval between the steps in ms

Example

Lets assume the following node configuration:

  • Minimum / Maximum value: 0 / 100
  • Steps: 10
  • Event interval: 200ms

When the node receives in the initial state on the input a message with e.g. msg.payload = 0.5 the node will emit 10, 20, 30, 40 and 50 on the output (to msg.payload) in a 200ms interval.

Advanced usage

Lets imagine that we want to make the dim speed of a light bulb depending on the time of the day. This use case would require to modify the node configuration (e.g. the event interval) at runtime. The dynamic dimmer node supports another input format to enable runtime modifications of the node config:

{
    "msg": {
        "payload":{
            "target": 0.5,
            "start": 0.1,
            "command": "DIM",
            "config": {
                "eventInterval": 600,
                "steps": 10,
                "minValue": 0,
                "maxValue": 100
            }
        }
    }
}

Please note that partial configuration updates are supported. Hence, you only need to provide the parameters which should be modified.

The command property

In general, the process of dimming has a very async behavior because one input event triggers a series of output events. For more control of ongoing operations the following commands were introduced:

  • DIM - this is the default operation and instructs the node to reach the target value. If there is already a dimming operation in progress, the node will switch to the new dim target value. The optional parameter start can be provided with values [0,1] to set the starting point of the dimming operation.
  • PAUSE - pause an ongoing dim operation (target should not be set)
  • SET - skips the dim operation and sets the dimmer immediately to the target value.
  • RESET - resets the node to it's initial configuration and sets the output to the minValue. If additional config properties are sent, it will merge them with the initial configuration.

Contribute

In case you want to improve this project please create a PR with your changes. Please make sure to add unit tests to verify your changes.

Local development and testing setup

Development scripts:

  • npm run build - obviously builds/transpiles the project
  • npm run test - runs the jest tests
  • npm run dev - at the time of writing a hot reloading of code changes is not supported by Node-RED. Hence, to test the node in a Node-RED instance npm run dev can be used to build the project and restart the docker container.

The node can be installed in the local Node-RED instance as follows:

# spin up node red
docker-compose up
mkdir data
# get the container id 
docker ps
# install the node in the container
docker exec -it <CONTAINER_ID> /bin/bash -c "cd /data && npm install ./node-red-contrib-dynamic-dimmer"