go-hue is a Go client library for accessing the Philips Hue API
go get github.com/firstthumb/go-hue
Philips Hue uses local and remote authorization. First you need to create user.
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))
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
Give a ⭐️ if this project helped you!