{"id":13808955,"url":"https://github.com/openhue/openhue-go","last_synced_at":"2025-04-05T21:07:34.595Z","repository":{"id":246858570,"uuid":"824320329","full_name":"openhue/openhue-go","owner":"openhue","description":"OpenHue Go is a library written in Golang for interacting with the Philips Hue smart lighting systems","archived":false,"fork":false,"pushed_at":"2025-03-13T00:59:25.000Z","size":353,"stargazers_count":127,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T20:05:12.332Z","etag":null,"topics":["go","golang","iot","library","openhue","philips-hue"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openhue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-04T21:27:12.000Z","updated_at":"2025-03-22T19:57:42.000Z","dependencies_parsed_at":"2024-12-16T05:14:59.590Z","dependency_job_id":null,"html_url":"https://github.com/openhue/openhue-go","commit_stats":null,"previous_names":["openhue/openhue-go"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openhue%2Fopenhue-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openhue%2Fopenhue-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openhue%2Fopenhue-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openhue%2Fopenhue-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openhue","download_url":"https://codeload.github.com/openhue/openhue-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399877,"owners_count":20932876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","iot","library","openhue","philips-hue"],"created_at":"2024-08-04T01:01:55.970Z","updated_at":"2025-04-05T21:07:34.578Z","avatar_url":"https://github.com/openhue.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# OpenHue Go\n![OpenHue Go Logo Medium Size](./docs/logo-md.png)\n\n[![Build](https://github.com/openhue/openhue-go/actions/workflows/build.yml/badge.svg)](https://github.com/openhue/openhue-go/actions/workflows/build.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/openhue/openhue-go)](https://goreportcard.com/report/github.com/openhue/openhue-go)\n[![Maintainability](https://api.codeclimate.com/v1/badges/ad99c96b6cbb59d2b81b/maintainability)](https://codeclimate.com/github/openhue/openhue-go/maintainability)\n[![Go Reference](https://pkg.go.dev/badge/github.com/openhue/openhue-go.svg)](https://pkg.go.dev/github.com/openhue/openhue-go)\n\n## Overview\nOpenHue Go is a library written in Goland for interacting with the Philips Hue smart lighting systems.\nThis project is based on the [OpenHue API](https://github.com/openhue/openhue-api) specification. \nTherefore, most of its code is automatically generated thanks to the [oapi-codegen](https://github.com/oapi-codegen/oapi-codegen) project.\n\n## Usage\nUse the following command to import the library: \n```shell\ngo get -u github.com/openhue/openhue-go\n```\nAnd check the following example that toggles all the rooms of your house:\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/openhue/openhue-go\"\n\t\"log\"\n)\n\nfunc main() {\n\n\thome, _ := openhue.NewHome(openhue.LoadConfNoError())\n\trooms, _ := home.GetRooms()\n\n\tfor id, room := range rooms {\n\n\t\tfmt.Printf(\"\u003e Toggling room %s (%s)\\n\", *room.Metadata.Name, id)\n\n\t\tfor serviceId, serviceType := range room.GetServices() {\n\n\t\t\tif serviceType == openhue.ResourceIdentifierRtypeGroupedLight {\n\t\t\t\tgroupedLight, _ := home.GetGroupedLightById(serviceId)\n\n\t\t\t\thome.UpdateGroupedLight(*groupedLight.Id, openhue.GroupedLightPut{\n\t\t\t\t\tOn: groupedLight.Toggle(),\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\u003e [!NOTE]  \n\u003e The `openhue.LoadConf()` function allows loading the configuration from the well-known configuration file.\n\u003e Please refer to [this guide](https://www.openhue.io/cli/setup#manual-configuration) for more information.\n\n### Bridge Discovery\nBridge Discovery on the local network has been made easy through the `BridgeDiscovery` helper: \n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/openhue/openhue-go\"\n\t\"log\"\n\t\"time\"\n)\n\nfunc main() {\n\n\tbridge, err := openhue.NewBridgeDiscovery(openhue.WithTimeout(1 * time.Second)).Discover()\n\topenhue.CheckErr(err)\n\n\tfmt.Println(bridge) // Output: Bridge{instance: \"Hue Bridge - 1A3E4F\", host: \"ecb5fa1a3e4f.local.\", ip: \"192.168.1.xx\"}\n}\n```\nThe `BridgeDiscovery.Discover()` function will first try to discover your local bridge via mDNS, \nand if that fails then it tries using [discovery.meethue.com](https://discovery.meethue.com) URL.\n\nOptions:\n- `openhue.WithTimeout` allows setting the mDNS discovery timeout. Default value is `5` seconds.\n- `openhue.WithDisabledUrlDiscovery` allows disabling the URL discovery.\n\n### Authentication\nBridge authentication has been make simple via the `Authenticator` interface:\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/openhue/openhue-go\"\n\t\"time\"\n)\n\nfunc main() {\n\n\tbridge, err := openhue.NewBridgeDiscovery(openhue.WithTimeout(1 * time.Second)).Discover()\n\topenhue.CheckErr(err)\n\n\tauthenticator, err := openhue.NewAuthenticator(bridge.IpAddress)\n\topenhue.CheckErr(err)\n\n\tfmt.Println(\"Press the link button\")\n\n\tvar key string\n\tfor len(key) == 0 {\n\n\t\t// try to authenticate\n\t\tapiKey, retry, err := authenticator.Authenticate()\n\n\t\tif err != nil \u0026\u0026 retry {\n\t\t\t// link button not pressed\n\t\t\tfmt.Printf(\".\")\n\t\t\ttime.Sleep(500 * time.Millisecond)\n\t\t} else if err != nil \u0026\u0026 !retry {\n\t\t\t// there is a real error\n\t\t\topenhue.CheckErr(err)\n\t\t} else {\n\t\t\tkey = apiKey\n\t\t}\n\t}\n\n\tfmt.Println(\"\\n\", key)\n}\n```\nIn this example, we wait until the link button is pressed on the bridge. \nThe `Authenticator.Authenticate()` function returns three values:\n- `apiKey string` that is not empty when `retry = false` and `err == nil`\n- `retry bool` which indicates that the link button has not been pressed\n- `err error` which contains the error details\n\n**You can consider the authentication has failed whenever the `retry` value is `false` and the `err` is not `nil`.**\n\n## License\n[![GitHub License](https://img.shields.io/github/license/openhue/openhue-cli)](https://github.com/openhue/openhue-cli/blob/main/LICENSE)\n\nOpenHue is distributed under the [Apache License 2.0](http://www.apache.org/licenses/),\nmaking it open and free for anyone to use and contribute to.\nSee the [license](./LICENSE) file for detailed terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenhue%2Fopenhue-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenhue%2Fopenhue-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenhue%2Fopenhue-go/lists"}