Skip to content

firstthumb/go-hue

Repository files navigation

go-hue

*** Work In Progress ***

GitHub code size in bytes GitHub go.mod Go version GitHub closed pull requests GitHub pull requests GitHub issues GitHub contributors License: BSD

go-hue is a Go client library for accessing the Philips Hue API

Install

go get github.com/firstthumb/go-hue

Authentication

Philips Hue uses local and remote authorization. First you need to create user.

Usage

Import the package into your project.

import "github.com/firstthumb/go-hue"

Use existing user and access Hue services. For example:

// Discover your network and finds the first bridge
host, _ := hue.Discover()
client := hue.NewClient(host, "<YOUR USER TOKEN>", nil)
lights, resp, err := client.Light.GetAll(context.Background())

Or create user. Don't forget to save the clientId

// You must press Philips Hue bridge button before
host, _ := hue.Discover()
client, _ := hue.CreateUser(host, "<CLIENT_NAME>", nil)
client.GetClientID() // Save clientID for next time
lights, resp, err := client.Light.GetAll(context.Background())

Supports remote API

// Create your clientId and clientSecret at https://developers.meethue.com/my-apps/
// set your environment variables HUE_CLIENT_ID, HUE_CLIENT_SECRET and HUE_APP_ID
// use the same callback url defined in your app
auth := hue.NewAuthenticator("http://localhost:8181/callback")
client, err := auth.Authenticate()
if err != nil {
  panic(err)
}
	
username, err := client.CreateRemoteUser()
if err != nil {
  panic(err)
}
	
client.Login(username)
result, _, _ := client.Light.GetAll(context.Background())
lights, _ := json.Marshal(result)
fmt.Println(string(lights))

More Examples

Coverage

Currently the following services are supported:

  • Remote API
    • Remote Login
  • Lights API
    • Get all lights
    • Get new lights
    • Search for new lights
    • Get light attributes and state
    • Set light attributes (rename)
    • Set light state
    • Delete lights
  • Groups API
    • Get all groups
    • Create group
    • Get group attributes
    • Set group attributes
    • Set group state
    • Delete group
  • Schedules API
  • Scenes API

Show your support

Give a ⭐️ if this project helped you!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published