{"id":1436,"date":"2018-04-02T18:33:10","date_gmt":"2018-04-02T18:33:10","guid":{"rendered":"https:\/\/zogspat.tk\/blog\/?p=1436"},"modified":"2018-04-02T18:33:10","modified_gmt":"2018-04-02T18:33:10","slug":"philips-hue-sensor-automation","status":"publish","type":"post","link":"https:\/\/the-plot.com\/blog\/?p=1436","title":{"rendered":"Philips&#8217; Hue Sensor Automation"},"content":{"rendered":"<p>I wrote about my first pass at the Philips&#8217; Hue API to customise the motion sensor functionality <a href=\"https:\/\/the-plot.com\/blog\/?p=1405\">back in December.<\/a>\u00a0At the time, I tested out my approach to force a third time slot [use of a nightlight setting for part of the the night] using a simple mobile app in Objective C. The approach isn&#8217;t that fancy: it&#8217;s basically 3 API PUT calls: two to rules, and then a third to a resourcelink all basically doing the same thing: inverting references to scenes [one for full brightness, and the other for the nightlight setting].<\/p>\n<p>At the time I thought it would be handy to use a Raspberry Pi using cron jobs to toggle it off and on, and the long and short of it, that&#8217;s what I&#8217;ve gone with. It&#8217;s a simple Python script [using the Requests module, which is great, to make the API calls], and it&#8217;s working really well so far.<\/p>\n<p>A couple of observations. First, I found an article on the Hue discussion forum &#8211; which I only found when I got a weird error and which, unfortunately I can&#8217;t find any more &#8211; that has what&#8217;s probably a more purist way of using the API to create extra slots. While it&#8217;s smarter than what I&#8217;m doing, unfortunately [and the author of the post does point this out] it has the effect of stopping the mobile app from working to set the sensor.<\/p>\n<p>Secondly, my approach is pretty brittle. Between writing the app and implementing the Python script the state had changed in the bridge: there was a new scene [not one we added &#8211; at least intentionally] which was causing the API calls to fail.<\/p>\n<p>Currently, my script is doing exactly what my mobile app did, which is creating the PUT payload for the API calls from files, and &#8216;hoping&#8217; that they work. What the Philips&#8217; mobile app does is to GET the various API resources and then PUT them back. I&#8217;ll do this when the current implementation breaks as it&#8217;s more trouble than it&#8217;s worth for now.<\/p>\n<p>I was telling someone at work [a proper developer] about my results with proxying via ZAP, which I had to revisit to figure out why my original implementation had stopped working, and he couldn&#8217;t believe the fact that the app is making around 55 API calls to effect a change in the sensor setup. Based on the diffs I looked at, It seems to pretty blindly do the GETting and PUTting where no changes have been made.<\/p>\n<p>I managed to completely corrupt the setup on the bridge by playing the &#8216;I wonder what will happen if I do this?&#8217; game: I deleted the scene that was breaking my API calls. I ended up having to do a factory reset &#8211; about a five minute job for me, but worth bearing in mind if you are playing with this stuff and have a more sophisticated configuration.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wrote about my first pass at the Philips&#8217; Hue API to customise the motion sensor functionality back in December.\u00a0At the time, I tested out my approach to force a third time slot [use of a nightlight setting for part &hellip; <a href=\"https:\/\/the-plot.com\/blog\/?p=1436\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1436","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1436"}],"version-history":[{"count":1,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1436\/revisions"}],"predecessor-version":[{"id":1437,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1436\/revisions\/1437"}],"wp:attachment":[{"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}