{"id":8065,"date":"2020-04-03T21:22:54","date_gmt":"2020-04-03T21:22:54","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=8065"},"modified":"2020-04-03T21:22:54","modified_gmt":"2020-04-03T21:22:54","slug":"controlling-a-philips-hue","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/controlling-a-philips-hue\/","title":{"rendered":"Controlling a Philips Hue"},"content":{"rendered":"<p>First off, the Philips Hue bridge exposes a web server, so take a look at the wireless connections on your network (see also <a href=\"https:\/\/developers.meethue.com\/develop\/get-started-2\/\" rel=\"noopener noreferrer\" target=\"_blank\">How to develop for Hue<\/a>) for other methods of locating your Hue bridge on the network.<\/p>\n<p>Much of the information in this post is taken from <a href=\"https:\/\/developers.meethue.com\/develop\/get-started-2\/\" rel=\"noopener noreferrer\" target=\"_blank\">How to develop for Hue?<\/a>. More information is available if you register as a Philips Hue developer.<\/p>\n<p>Once you&#8217;ve located your bridge IP address you can use a web browser to connect the CLIP API Debugger, i.e.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nhttps:\/\/&lt;bridge ip address&gt;\/debug\/clip.html\r\n<\/pre>\n<p><strong>The Hue bridge API<\/strong><\/p>\n<p>The first thing we need to do is a key for interacting with the device. The Hue actually calls this your username and it&#8217;s a randomly generated string, once we have this we have an authorise user. <\/p>\n<p>So for example if you try to use any command without a key you&#8217;ll get a response along the following lines<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n&#x5B;\r\n  {\r\n    &quot;error&quot;: {\r\n      &quot;type&quot;: 1,\r\n      &quot;address&quot;: &quot;\/&quot;,\r\n      &quot;description&quot;: &quot;unauthorized user&quot;\r\n    }\r\n  }\r\n]\r\n<\/pre>\n<p><strong><em>Creating our user<\/em><\/strong><\/p>\n<p>To get our username and thus create an authorized user, we use the following API<\/p>\n<ul>\n<li>Method: POST<\/li>\n<li>Url: \/api<\/li>\n<li>Body: {&#8220;devicetype&#8221;:&#8221;my_hue_app#my_name&#8221;}<\/li>\n<\/ul>\n<p>The &#8220;my_hue_app#my_name&#8221; appears to simply be a unique resource name. Before you run this command you should press the link button on the Hue bridge then execute this HTTP request.<\/p>\n<p>If all works correctly you should get a response like this<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n&#x5B;\r\n  {\r\n    &quot;success&quot;: {\r\n      &quot;username&quot;: &quot;sYA1egf8VZteeIWnXmlIdrxFE3uHgUr-jk2Vrt12&quot;\r\n    }\r\n  }\r\n]\r\n<\/pre>\n<p>Now we use the username value (i.e. sYA1egf8VZteeIWnXmlIdrxFE3uHgUr-jk2Vrt12) in our method calls going forward.<\/p>\n<p><strong><em>Getting more information<\/em><\/strong><\/p>\n<ul>\n<li>Method: GET\n<li>\n<li>Url: \/api\/sYA1egf8VZteeIWnXmlIdrxFE3uHgUr-jk2Vrt12<\/li>\n<\/ul>\n<p>This will return a JSON response (which it too large to include here) including information on the available lights, their state, brightness, hue etc. along with stored scenes.<\/p>\n<p><strong><em>Getting light information<\/em><\/strong><\/p>\n<ul>\n<li>Method: GET<\/li>\n<li>Url: https:\/\/<bridge ip address>\/api\/sYA1egf8VZteeIWnXmlIdrxFE3uHgUr-jk2Vrt12\/lights<\/li>\n<\/ul>\n<p>If successful, this will return light specific information, such as state, name, brightness etc.<\/p>\n<p><strong><em>Getting light information for a specific light<\/em><\/strong><\/p>\n<p>If we want to just get information for a specific light, we use it&#8217;s ID, by simply appending it the the previous URL, for example we&#8217;ll get information for light 1<\/p>\n<ul>\n<li>Method: GET<\/li>\n<li>Url: https:\/\/<bridge ip address>\/api\/sYA1egf8VZteeIWnXmlIdrxFE3uHgUr-jk2Vrt12\/lights\/1<\/li>\n<\/ul>\n<p><strong><em>Turning a light on and off<\/em><\/strong><\/p>\n<p>To change the state of a light we append <em>state<\/em> to the previous URL, for example<\/p>\n<ul>\n<li>Method: PUT<\/li>\n<li>Url: https:\/\/<bridge ip address>\/api\/sYA1egf8VZteeIWnXmlIdrxFE3uHgUr-jk2Vrt12\/lights\/1\/state<\/li>\n<li>Body: {&#8220;on&#8221;:false}<\/li>\n<\/ul>\n<p>We should get a response similar to the one below<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n&#x5B;\r\n  {\r\n    &quot;success&quot;: {\r\n      &quot;\/lights\/1\/state\/on&quot;: false\r\n    }\r\n  }\r\n]\r\n<\/pre>\n<p><strong><em>More than just on and off<\/em><\/strong><\/p>\n<ul>\n<li>Method: PUT<\/li>\n<li>Url: https:\/\/<bridge ip address>\/api\/sYA1egf8VZteeIWnXmlIdrxFE3uHgUr-jk2Vrt12\/lights\/1\/state<\/li>\n<li>Body: {&#8220;on&#8221;:true, &#8220;sat&#8221;:254, &#8220;bri&#8221;:254,&#8221;hue&#8221;:10000}<\/li>\n<\/ul>\n<p>After executing this, you&#8217;ll get a response similar to the following<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n&#x5B;\r\n  {\r\n    &quot;success&quot;: {\r\n      &quot;\/lights\/2\/state\/on&quot;: true\r\n    }\r\n  },\r\n  {\r\n    &quot;success&quot;: {\r\n      &quot;\/lights\/2\/state\/hue&quot;: 10000\r\n    }\r\n  },\r\n  {\r\n    &quot;success&quot;: {\r\n      &quot;\/lights\/2\/state\/sat&quot;: 254\r\n    }\r\n  },\r\n  {\r\n    &quot;success&quot;: {\r\n      &quot;\/lights\/2\/state\/bri&quot;: 254\r\n    }\r\n  }\r\n]\r\n<\/pre>\n<p><strong>C#\/.NET Libraries<\/strong><\/p>\n<p>There are also several .NET libraries for interacting with the Hue, that allows us a better API experience, such as <\/p>\n<ul>\n<li>https:\/\/github.com\/Q42\/Q42.HueApi<\/li>\n<li>https:\/\/github.com\/cDima\/Hue<\/li>\n<li>https:\/\/github.com\/qJake\/SharpHue<\/li>\n<\/ul>\n<p><strong>References<\/strong><\/p>\n<p><a href=\"https:\/\/developers.meethue.com\/\" rel=\"noopener noreferrer\" target=\"_blank\">Become a Philips Hue Developer to light up your ideas<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>First off, the Philips Hue bridge exposes a web server, so take a look at the wireless connections on your network (see also How to develop for Hue) for other methods of locating your Hue bridge on the network. Much of the information in this post is taken from How to develop for Hue?. More [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[291],"tags":[],"class_list":["post-8065","post","type-post","status-publish","format-standard","hentry","category-philips-hue"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=8065"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8065\/revisions"}],"predecessor-version":[{"id":8081,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8065\/revisions\/8081"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=8065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=8065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=8065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}