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

@sebastianboehler/philipshue

v1.0.52

Published

Wrapper around the PhilipsHue REST API

Downloads

2

Readme

Philips Hue API Wrapper

This is a Typescript package that provides a simple and easy-to-use wrapper around the Philips Hue API. It allows you to control your Philips Hue lights and other devices from your code.

Installation

npm install @sebastianboehler/philipshue@latest

Usage

To use the package, import it in your code and create a new instance of the PhilipsHue class:

import PhilipsHue from 'philipsHue'
import express from 'express.js

const port = process.env.PORT || 3000
const redirect_path = `/philipsHue_callback`

const myPhilips = new PhilipsHue({
  redirect_uri: `http://localhost:${port}${redirect_path}`,
  CLIENT_ID: 'YOUR_CLIENT_ID',
  CLIENT_SECRET: 'YOUR_CLIENT_SECRET'
})

const app = express()

app.get('/login', (req, res) => {
  const oAuthUrl = myPhilips.getOAuthUrl()
  res.redirect(oAuthUrl)
});

app.get(redirect_path, async (req, res) => {
  const { code } = req.query
  if (!code) {
    res.json({
      success: false
    })
    return
  }
  const success = await myPhilips.getAccessToken(code.toString())
  if (success) = await myPhilips.createWhitelistUser()
  res.json({
    success
  })
});

app.get('/scenes', async (req, res) => {
  const scenes = await myPhilips.getScenesV2()
  res.json(scenes)
});

app.listen(port, () => {
  console.log(`Sever listening on port ${port}`)
});

Available methods

  • getOAuthurl() returns your oAuth url
  • getAccessToken(code: string, grant_type = 'authorization_code') stores access token, refresh token and expiration Date inside the class
  • refreshToken() renews your access token
  • createWhitelistUser whitelist your user
  • setLightState(id: string | number, state: LightStateV1) lets you change the states of your light, turn them on/off, change color etc.
  • shouldRefreshAccessToken(aboutToExpireInNextSeconds: number = 90) returns true if your access token is about to expire in next x seconds
  • setGroupState(id: string | number, state: LightStateV1 | {scene: string}) let you control whole groups in your home
  • getGroups() returns all groups in your home
  • getLightsV2() returns all lights in your home
  • getGroupsV2() returns all groups in your home
  • getScenesV2() returns all scenes
  • getSceneDetailsV2() get a scene by its id
  • getSmartScenesV2() returns all smart scenes
  • activateSceneV2(id: string) activate a scene
  • activateSmartSceneV2(id: string) activates a smart scene

Please note that not all methods from the V1 and V2 API are supported yet. I'll try to update it as often as possible and extended it by the missing functions.