/go.hue

A Go library to manage your Philips Hue devices

Primary LanguageGo

go.hue - An easy to use API to manage your Philips Hue

GoDoc Build Status Go Report Card

For documentation, check out the link to godoc above.

Examples

Register a new device

To start using the hue API, you first need to register your device.

package main
import "fmt"
import "github.com/stefanwichmann/go.hue"

func main() {
	bridges, _ := hue.DiscoverBridges(false)
	bridge := bridges[0] //Use the first bridge found

	//Remember to push the button on your hue first
	err := bridge.CreateUser("my nifty app")
	if err != nil {
		fmt.Printf("Device registration failed: %v\n", err)
	}
	fmt.Printf("Registered new device => %+v\n", bridge)
}

Turn on all the lights

package main
import "github.com/stefanwichmann/go.hue"

func main() {
	bridge := hue.NewBridge("your-ip-address", "your-device-name")
	lights, _ := bridge.GetAllLights()

	for _, light := range lights {
		light.On()
	}
}

Disco Time! Switch all lights into colorloop

package main
import "github.com/stefanwichmann/go.hue"

func main() {
	bridge := hue.NewBridge("your-ip-address", "your-device-name")
	lights, _ := bridge.GetAllLights()

	for _, light := range lights {
		light.ColorLoop()
	}
}

Access lights by name

package main
import "github.com/stefanwichmann/go.hue"

func main() {
	bridge := hue.NewBridge("your-ip-address", "your-device-name")
	light, _ := bridge.FindLightByName("Bathroom Light")
	light.On()
}