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

dash-hue-light-control

v1.5.1

Published

Turn on/off your hue light with Amazon dash button

Downloads

46

Readme

dash-hue-light-control

This program let you control your light with Amazon dash button. dash-hue-light-control support nodejs versions 7 and superiors. With this module you will basically be able to set a button that switch light with command line interface (cli) or programmatically on importing the module to your existing program.

To use this program you will need your dash button configured and ready plus have access (ip + token) to your hue light. I'm writing a cli/module helper to get a convenient way to have this.

Please, feel free to send me any feedback or open issues on the module github page.

Jeedom, Domoticz, etc

If you want me to create a compatible plugin for domotics software just get in touch with me. It would be a pleasure to improve my module and make it useable for your system.

Contents

Prerequisite

You need nodejs 7 or superior and a Unix system. This program does not works on Windows for now due to the use of libpcap. You will also need to setup your dash and have an access token to your hue bridge. You can follow the step 2 from this guide to configure your dash http://www.instructables.com/id/Amazon-Dash-Button-Hack. In order to have authorization to your bridge you will need to access its api and generate new user. Follow the official guide to help you in the process https://developers.meethue.com/documentation/getting-started.

Installation

# library needed for read requests from dash buttons
$ sudo apt-get install libpcap-dev
# actual program sources
# You may need sudo to install the module
$ npm install -g dash-hue-light-control

Usage

Just create a settings.json somewhere and use its location as argument:

$ sudo dash-hue-light-control start path/to/settings.json

The process will keep watching for your dash press action and control the light.

settings.json sample

This is the most basic config example

{
  "jwt": "FkXIos6bRxzyy54qsspHLa2MGx5-IQkWNLfIbn4",
  "bridge": "192.168.0.10",
  "configuration": {
    "dash": "b4:7c:9c:49:b4:d4",
    "targetId": "2",
    "mode": "toggle"
  }
}

The available modes are:

  • toggle
  • on
  • off

The toggle mode will either turn on or off your light depending on its current state.

By default you will target a light but there are other possibilities like groups.

{
  "jwt": "FkXIos6bRxzyy54qsspHLa2MGx5-IQkWNLfIbn4",
  "bridge": "192.168.0.10",
  "configuration": {
    "dash": "b4:7c:9c:49:b4:d4",
    "targetId": "2",
    "mode": "toggle",
    "target": "group"
  }
}

Also configuration can take an array of entry to handle several dash buttons.

Run it as a background process

In the real world you probably want to run this program as a background process and let it run forever. An easy way to do it is to download pm2 or other process manager and run the command sudo node index --settings=path/to/settings.json through this process manager. Refer to the dedicated doc for more info.

Here is an example with pm2:

$ npm install pm2 -g
$ sudo pm2 start dash-hue-light-control --name="hue-room" -- start ~/Documents/settings-hue-room.json

Note that you will probably need to run this as sudo as well because of PcapSession

Usage as a node module (programmatically)

You can import this program like any module and use it programmatically. For now the api is still rather light and will be improved over time.

const dashHueLightControl = require('dash-hue-light-control')
dashHueLightControl({
  "jwt": "FkXIos6bRxzyy54qsspHLa2MGx5-IQkWNLfIbn4",
  "bridge": "192.168.0.10",
  "configuration": {
      "dash": "b4:7c:9c:49:b4:d4",
      "targetId": "2",
      "mode": "toggle"
  }
})

Note about dash button

Due to how the button is designed (sleep, wake up, connect to wifi, arp, sleep, ...) there is a noticeable timeout between a press and its action. I cannot do anything about that and remember that this is a 2€ smart button after all.

  • Use DHCP Reservation on your Amazon Dash Button to lower the latency from ~5s to ~1s.
  • Dash buttons cannot be used for another ~10 seconds after they've been pressed. Thanks ricardo1980 for the tips.

Known issues

  • I once got two triggers for one button press (never had again). It happened after a long inactivity of my button. It basically turned the light on and off directly after. Never had again but I guess the button sometimes send more request. I will dig into the settings to see if I can avoid it.

Next updates

  • control the color/intensity/whatever
  • Use local user file to allow cli session when using mac address, etc

Contributors

Jamie Briers