{"id":20611841,"url":"https://github.com/qjake/sharphue","last_synced_at":"2025-04-15T05:42:50.596Z","repository":{"id":11146537,"uuid":"13514221","full_name":"qJake/SharpHue","owner":"qJake","description":"A .NET library for the Philips Hue lighting system.","archived":false,"fork":false,"pushed_at":"2016-02-21T00:38:07.000Z","size":2584,"stargazers_count":28,"open_issues_count":3,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T05:42:39.562Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qJake.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-12T02:27:28.000Z","updated_at":"2023-11-09T08:17:25.000Z","dependencies_parsed_at":"2022-08-28T10:22:03.549Z","dependency_job_id":null,"html_url":"https://github.com/qJake/SharpHue","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qJake%2FSharpHue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qJake%2FSharpHue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qJake%2FSharpHue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qJake%2FSharpHue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qJake","download_url":"https://codeload.github.com/qJake/SharpHue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016307,"owners_count":21198828,"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":[],"created_at":"2024-11-16T10:22:17.990Z","updated_at":"2025-04-15T05:42:50.579Z","avatar_url":"https://github.com/qJake.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SharpHue\n\nAn open-source .NET library for the Philips Hue lighting system.  \n**Current Version:** 1.1\n\n## Implementation Status\n\nThe following Hue APIs are currently supported:\n\n\u003e - [X] Light API\n\u003e - [X] Configuration / Whitelist API\n\u003e - [ ] Group API\n\u003e - [ ] Schedules API\n\u003e - [ ] Sensors API\n\u003e - [ ] Rules API\n\n## Examples\n\n### Configuration initialization\n\nFirst, you must initialize the API configuration, so that the API knows your username and/or device IP. There are three ways to do this.\n\n#### 1. Register new user\n\n```cs\nConfigruation.AddUser();\n```\n\nThis will first attempt to locate your bridge device automatically using Philips' discovery service, then register a new user with the Bridge. **NOTE:** You must press the button on the bridge before you call this method, and once you press the button you have 30 seconds to call this method.\n\nAfter this method returns, if there were no errors or exceptions, the `Configuration.Username` property will contain the newly registered username, in case you need to refer to it.\n\n#### 2. Initialize with existing user\n\n```cs\nConfiguration.Initialize(\"Username Here\");\n```\n\nThis will first attempt to locate your bridge device automatically using Philips' discovery service, then initialize the API with the specified preexisting username.\n\n#### 3. Initialize with existing user and manually-defined IP\n\n```cs\nConfiguration.Initialize(\"Username Here\", IPAddress.Parse(\"192.68.x.x\"));\n```\n\nThis will initialize the API with the specified preexisting username, and will explicitly use the IP address given, bypassing the Philips' discovery service.\n\n### Retrieving Lights\n\n```cs\nLightCollection lights = new LightCollection();\n```\n\nThis will retrieve all lights and their associated light state information. If you already have a `LightCollection` and want to refresh it, simply call `lights.Refresh()`.\n\nOnce you have a light collection, you can reference lights either by index:\n\n```cs\nlights[1]\n```\n\nOr by name:\n\n```cs\nlights[\"Kitchen Light 1\"]\n```\n\nLights also contain state information. To get the current hue of light 2:\n\n```cs\nlights[2].State.Hue\n```\n\n**NOTE:** Accessing a `LightCollection` by index is **one-based**, not **zero-based** like most arrays. Attempting to retrieve `lights[0]` will return `null`.\n\n### Enumerating Lights\n\n`LightCollection` implements `IReadOnlyCollection\u003cT\u003e` using `Light` as its generic parameter, so if you have a `LightCollection`, you can do anything you can do with other enumerators, including LINQ:\n\n```cs\nvar UpstairsLightsOn = (from l in lights\n                        where l.Name.StartsWith(\"2F\")\n                        where l.State.IsOn\n                        select l).ToList();\n```\n\n### Setting Light State\n\n#### Using JSON\n\nTo update the state of a light, you can pass in a `JObject` directly with your own state information:\n\n```cs\nvar state = new JObject(new JProperty(\"on\", true));\nlights[3].SetState(state);\n```\n\nOr even just write your own JSON:\n\n```cs\nvar json = JObject.Parse(\"{on: true, ct: 137, bri: 255, effect: \\\"colorloop\\\"}\");\nlights[5].SetState(json);\n```\n\nUsing a `JObject` is required for basic JSON validation (so that a non-JSON string isn't passed in and sent to the device).\n\n#### Using `LightStateBuilder`\n\nAn easier way to build a new state is to use the provided `LightStateBuilder` class:\n\n```cs\n// Build a new light state\nLightStateBuilder builder = new LightStateBuilder()\n                            .TurnOn()\n                            .Saturation(128)\n                            .Brightness(128)\n                            .Effect(LightEffect.ColorLoop);\n                            \n// Apply the state to one or more lights\nlights[1].SetState(builder);\nlights[4].SetState(builder);\n```\n\nYou use the light state builder by chaining various methods, then pass the builder into whichever light(s) you want to update using `SetState()`.\n\n#### Using `LightStateBuilder` Exclusively\n\nYou can also just use a LightStateBuilder directly, to apply a new state to one or more lights:\n\n```cs\n  new LightStateBuilder()\n      .For(lights[1], lights[3]) // Specifies one or more lights which this new state is for\n// Or .For(lights, 1, 3)\n      .TurnOn()                  // Turns on the light(s)\n      .ColorTemperature(137)     // Sets the color temperature to 6500K\n      .Brightness(255)           // Set the brightness to maximum\n      .Apply();                  // Send the light state that was just built to the lights specified in .For()\n```\n\nYou can also apply a new state to every single light using `.ForAll()`:\n\n```cs\n// Party Mode\nnew LightStateBuilder()\n    .ForAll()\n    .TurnOn()\n    .Effect(LightEffect.ColorLoop)\n    .Brightness(255)\n    .Apply();\n```\n\nOrder matters! Always call `.Apply()` last, because you cannot call any more methods after Apply (it returns `void`). Also, if you are using `.Apply()`, be sure to call either `.For()` or `.ForAll()`, otherwise an exception will be thrown.\n\n## Contributing\n\nReport bugs, request features, or fork it, code it yourself, and send me a pull request!\n\n## Credits\n\nUses the [Newtonsoft.Json](http://json.codeplex.com/) library for JSON handling.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqjake%2Fsharphue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqjake%2Fsharphue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqjake%2Fsharphue/lists"}