{"id":166,"date":"2016-01-09T13:03:57","date_gmt":"2016-01-09T13:03:57","guid":{"rendered":"http:\/\/davidjohntaylor.co.uk\/?p=166"},"modified":"2016-01-10T09:53:21","modified_gmt":"2016-01-10T09:53:21","slug":"how-arriving-home-is-a-now-welcome-sight","status":"publish","type":"post","link":"https:\/\/davidjohntaylor.co.uk\/index.php\/2016\/01\/09\/how-arriving-home-is-a-now-welcome-sight\/","title":{"rendered":"How arriving home is a welcome sight"},"content":{"rendered":"<p>I&#8217;m continuing to try out different combinations of sensors and devices at home with the aim of automating different aspects of my daily life. \u00a0Whilst its unlikely to reach the level that <a href=\"http:\/\/www.theverge.com\/2016\/1\/3\/10705652\/zuckerberg-building-ai-to-run-home-like-in-iron-man\">Mark Zuckerberg announced<\/a> in the past week, I&#8217;m finding that with a bit of thought you really can combine different bits of tech quite easily to provide a benefit.<\/p>\n<p>A few nights ago, I had one of those &#8220;what if?&#8221; moments, in this case it was, &#8220;What if, when I could come and go from home in the dark (early mornings &amp; late night returns from work!), the lights on the porch and hallway light automatically?&#8221;. \u00a0Within an hour or so I&#8217;d put together a simple system!<\/p>\n<div style=\"width: 910px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/brightup.azurewebsites.net\/wp-content\/uploads\/2014\/07\/welcomehome.jpg\" alt=\"\" width=\"900\" height=\"600\" \/><p class=\"wp-caption-text\">Not my house!<\/p><\/div>\n<p>The main components needed were:<\/p>\n<ul>\n<li>Milight wireless <a href=\"http:\/\/www.banggood.com\/E27-6W-RGBW-14-LED-450LM-LED-Spotlight-Dimmable-Bulb-lamp-85-265V-p-971552.html\">lightbulbs<\/a><\/li>\n<li>Milight <a href=\"http:\/\/www.ebay.co.uk\/itm\/MiLight-4-Zone-RF-2-4ghz-Transmission-LED-Strip-Light-Controller-Dimmer-\/321894244989?hash=item4af264627d:g:D8wAAOSwAYtWH5~7\">gateway<\/a>\u00a0controller<\/li>\n<li><a href=\"http:\/\/nodered.org\/\">node-red<\/a> instance running on a local PC<\/li>\n<li><a href=\"http:\/\/www.sky.com\/shop\/broadband-talk\/sky-hub\/\">Sky router<\/a> with LAN address reservation functionality<\/li>\n<li><a href=\"http:\/\/www.wampserver.com\/en\/\">WampServer <\/a>running on a local PC<\/li>\n<li>Milight\/LimitlessLED\/EasyBulb Complete <a href=\"https:\/\/github.com\/yasharrashedi\/LimitlessLED\">PHP API<\/a><\/li>\n<\/ul>\n<p>So how does this all plug together? \u00a0I&#8217;ve broken it down into a couple of sections which means you can pick and choose from these if you want to do bits of this yourself! \u00a0Note that this is more of a summary of how to get this system running &#8211; more detailed posts are coming on how to implement the actual components. \u00a0If you&#8217;re techy enough, you&#8217;ll get the gist from the notes below.<\/p>\n<h2>Spotting when I come home (or leave the house)<\/h2>\n<p>I wanted to use whatever technology I already had available, and so buying Bluetooth gateways etc. was out of the question. \u00a0The key thing I always have with me is my phone, and this connects\/disconnects to my wireless when I arrive\/leave home. \u00a0This was what I used to recognise when I was in or out.<\/p>\n<p>First of all, it was necessary to configure the address reservation of my Sky router to always give my phone the same IP address. \u00a0This meant, the monitoring software would be able to see that IP address appear on my home network as soon as I got home. \u00a0A quick test showed that on pulling up outside the house, I was on the network within a few seconds &#8211; perfect!<\/p>\n<p>Secondly, to monitor for the phone arriving, I built a node-red workspace which pinged the IP address of my phone every 5 seconds, and then reacted when the phone connected\/disconnected to the network (more on this later).<\/p>\n<h2>Managing the house lights automatically<\/h2>\n<p>I already had some Milight bulbs in the house &#8211; these look pretty much like normal light bulbs, but via a controller (and <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.lierda.wifi&amp;hl=en_GB\">free mobile app<\/a>) you can manage their brightness and colour. \u00a0The bulbs were moved to the hallway and porch, and I checked that the Sky router also had a designated IP address for the controller. \u00a0At this point its also worth using one of the free apps to assign each bulb to a separate group so you have finely grained control. \u00a0My hall light was assigned to group 1, and the porch to group 2.<\/p>\n<div style=\"width: 1241px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/HT1Gmkv8LcBBVNOcQ_66fs8JqLB1lH8SyhPy_1idCuBx-e5yKxvMx4HEvOn0qYU4x7IC6YS-nXahMSoQQPwP5pzafrKtFHMXA8OODBlOdm17W_UpKFndAXg4o_JU5ZAyJW_dG_lAMoW7kGqDvTbw5NRpTFDPRHVGgKm3gzcuU7Y7xMMkYu5WVyly7ASa-CchDDXtTPTXmvlu_5Y_ArSOtciAnf5ZoK4htn9-Y_viRoxtdPlqTCtP2i7iFxWwJ03D3kce_veFDoh1HVuThzEQRJQdYX5BmMeJSJekDbau-XGQ5OMNrLB_az2UrT-TGLz3fhMpyn-DdvQMw96cNLa5gEi_VhYQ6ad7YGETaynUjsw-Cih8-sm3in6-trYl8SIVDjEVQtq9rVnPgg40Wqdh7DXLNSFUVvcdVR30P3OPBtO8OohzfQqYK7SQ_KL_vQublpQBwhx_KsLtPXQOkxs8Hkan8ZRQLz0kh5Gda45ZziXExt2bnkfhjlI5X77Z8Z0EUpZnHcLTAWD6OnHC1sFTSU8zSHbtnh9g2hQ7vFdNcx138LgXCG-2Gg-0xZ-e9JLfYvTj-g=w1231-h923-no\" alt=\"\" width=\"1231\" height=\"923\" \/><p class=\"wp-caption-text\">Testing\u00a0the light colours out<\/p><\/div>\n<p>I knew it was possible to control the lights via a PHP library I&#8217;d seen the past, so after a quick Google later, I found the code on <a href=\"https:\/\/github.com\/yasharrashedi\/LimitlessLED\">GitHub<\/a>.<\/p>\n<p>As this was PHP, and because i&#8217;m lazy, I always find its easiest to kick bits of code off via a web server, so I installed WampServer on my home PC which provides you with a really quick way to get\u00a0Apache2, PHP and a MySQL database installed.<\/p>\n<p>To try out the PHP code, I dropped the LimitlessLED library into the webserver root, reconfigured the example to point at the IP address of the controller, and then flash a bulb group on and off. \u00a0Then it was a case of calling it via a the web browser. \u00a0It worked straight away.<\/p>\n<p>To keep it really simple, I just copied the example a few times, and saved a number of additional PHP files for:<\/p>\n<ul>\n<li>HallLightOff.php<\/li>\n<li>HallLightOn.php<\/li>\n<li>FrontDoorLightOff.php<\/li>\n<li>FrontDoorLightOn.php<\/li>\n<\/ul>\n<p>Quick and dirty code, but it would work.<\/p>\n<h2>The glue in the middle to automate the process<\/h2>\n<p>Now I just needed the &#8220;glue&#8221; in the middle act on my arrival\/departure &#8211; this is where a node-red workspace came into its own!<\/p>\n<p><a href=\"http:\/\/davidjohntaylor.co.uk\/wp\/wp-content\/uploads\/2016\/01\/node-red-auto-lights.png\" rel=\"attachment wp-att-168\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-168 size-full\" src=\"http:\/\/davidjohntaylor.co.uk\/wp\/wp-content\/uploads\/2016\/01\/node-red-auto-lights.png\" alt=\"node-red-auto-lights\" width=\"777\" height=\"362\" srcset=\"https:\/\/davidjohntaylor.co.uk\/wp\/wp-content\/uploads\/2016\/01\/node-red-auto-lights.png 777w, https:\/\/davidjohntaylor.co.uk\/wp\/wp-content\/uploads\/2016\/01\/node-red-auto-lights-300x140.png 300w, https:\/\/davidjohntaylor.co.uk\/wp\/wp-content\/uploads\/2016\/01\/node-red-auto-lights-768x358.png 768w\" sizes=\"auto, (max-width: 777px) 100vw, 777px\" \/><\/a><\/p>\n<p>I&#8217;ve included a view of the workspace, as it makes it easier to explain, but it works like this:<\/p>\n<ul>\n<li>Ping the IP address every 5 seconds &#8211; the node responds with either false or a response time<\/li>\n<li>If response is false, pass straight through to RBE (Report by Exception node) &#8211; i.e. we only need to know once if I&#8217;ve arrived or left, otherwise the lights are going to turn into a disco!<\/li>\n<li>If response is a number, then convert that to true and pass to RBE<\/li>\n<li>If the response if different to the last one, i.e. I&#8217;ve left or arrived pass through to the switch<\/li>\n<li>At the switch, if the response is true then flow moves to &#8220;David Home&#8221;, if false, &#8220;David Away&#8221;<\/li>\n<li>The relevant http request from node-red then calls the web server with the appropriate PHP code, i.e. if I arrive home, then\u00a0HallLightOn.php and\u00a0FrontDoorLightOn.php is called.<\/li>\n<li>The &#8220;Auto-Home&#8221; node you can see is a &#8220;Notify My Android&#8221; node which sends a notification to my phone confirming the activity &#8211; this is just for debug at the moment.<\/li>\n<\/ul>\n<p>That&#8217;s all there is to it!<\/p>\n<h2>What next?<\/h2>\n<p>Obviously this is just fairly basic so next steps are:<\/p>\n<ul>\n<li>Only manage the lights if its actually dark, so I&#8217;m going to integrate with a web service which indicates if, where I live, its past dusk (and before dawn has broke)<\/li>\n<li>Account for the fact other people may still be at home, and so if I leave the house for example, I may not want certain lights to switch off<\/li>\n<li>Add other lights into the mix (on order!)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m continuing to try out different combinations of sensors and devices at home with the aim of automating different aspects of my daily life. \u00a0Whilst its unlikely to reach the level that Mark Zuckerberg announced in the past week, I&#8217;m&hellip; <a href=\"https:\/\/davidjohntaylor.co.uk\/index.php\/2016\/01\/09\/how-arriving-home-is-a-now-welcome-sight\/\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":172,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-166","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-internet-of-things-iot"],"_links":{"self":[{"href":"https:\/\/davidjohntaylor.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davidjohntaylor.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davidjohntaylor.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davidjohntaylor.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/davidjohntaylor.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=166"}],"version-history":[{"count":4,"href":"https:\/\/davidjohntaylor.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/166\/revisions"}],"predecessor-version":[{"id":173,"href":"https:\/\/davidjohntaylor.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/166\/revisions\/173"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davidjohntaylor.co.uk\/index.php\/wp-json\/wp\/v2\/media\/172"}],"wp:attachment":[{"href":"https:\/\/davidjohntaylor.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davidjohntaylor.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davidjohntaylor.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}