An open API service indexing awesome lists of open source software.

https://github.com/firstthumb/go-hue


https://github.com/firstthumb/go-hue

Last synced: 4 months ago
JSON representation

Awesome Lists containing this project

README

          

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](https://developers.meethue.com/develop/hue-api/)

## Install

```sh
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.

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

Use existing user and access Hue services. For example:

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

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

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

Supports remote API

```Go
// 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](https://github.com/firstthumb/go-hue/tree/main/example)

## Coverage

Currently the following services are supported:

- [x] [Remote API](https://developers.meethue.com/develop/hue-api/remote-api-quick-start-guide/)
- [x] Remote Login
- [x] [Lights API](https://developers.meethue.com/develop/hue-api/lights-api/)
- [x] Get all lights
- [x] Get new lights
- [x] Search for new lights
- [x] Get light attributes and state
- [x] Set light attributes (rename)
- [x] Set light state
- [x] Delete lights
- [x] [Groups API](https://developers.meethue.com/develop/hue-api/groupds-api/)
- [x] Get all groups
- [x] Create group
- [x] Get group attributes
- [x] Set group attributes
- [x] Set group state
- [x] Delete group
- [ ] [Schedules API](https://developers.meethue.com/develop/hue-api/3-schedules-api/)
- [ ] [Scenes API](https://developers.meethue.com/develop/hue-api/4-scenes/)

## Show your support

Give a ⭐️ if this project helped you!