Comments
You can use your Fediverse (e.g., Mastodon) account to reply to this post .
The open source release networld-to/philips-hue-client implements a Philips Hue API v2 library in golang.
The Philips Hue API is provided by a local, physical bridge device that is connected to the network via ethernet cable (not PoE powered). The released golang library implements the second generation of this local Philips Hue API. For more information checkout the README.md.
Point the domain philips-hue.home.arpa
to your Philips Hue Bridge IP (not
necessary, but simplifies access). Make sure you have an appropriate Philips Hue
Bridge configuration under ~/.philips-hue.json
. It should look like this:
{"bridge":"philips-hue.home.arpa","username":"THIS_IS_YOUR_PASSWORD","devicetype":"node-philips-hue"}
Instructions and helper code how to setup a new username is coming soon.
To test the library run the client via the following command.
# Comment or uncomment the appropriate lines in client/main.go and run
$ go run client/main.go
Use the philips-hue-client
in your application. Create a main.go
or any
other go file that uses the library, see example below.
package main
import (
"fmt"
"log"
"github.com/networld-to/philips-hue-client/bridge"
)
func main() {
groups, _, err := bridge.GetGroups()
if err != nil {
log.Fatal(err)
}
fmt.Println(bridge.ChangeGroupState(groups.Data[0].ID, bridge.BRIGHT_WARM_GREEN_ON))
}
Run the following commands. This assumes that there is a file that is using this library, see example snippet above.
# Initializes your go module. Change to a name of your liking, e.g. github.com/yourusername/yourmodulename
$ go mod init your/go/mod
$ go mod tidy
$ go run main.go