{"id":191,"date":"2017-12-14T21:35:37","date_gmt":"2017-12-15T05:35:37","guid":{"rendered":"http:\/\/www.diyfuturism.com\/?p=191"},"modified":"2018-01-16T20:55:40","modified_gmt":"2018-01-17T04:55:40","slug":"basic-node-red-flows-for-automating-lighting-with-home-assistant","status":"publish","type":"post","link":"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/","title":{"rendered":"Basic Node-Red Flows for Automating Lighting with Home Assistant"},"content":{"rendered":"<p>Smart <a href=\"http:\/\/www.diyfuturism.com\/index.php\/2017\/11\/20\/my-smart-home-hardware-list\/\">light bulbs<\/a> are probably the first thing everyone getting into home automation buys. It is easy to see the applications for them &#8211; have the lights come on at night, turn off when you&#8217;re home, etc. It&#8217;s very satisfying to have the lights react to the day and your activities, and my goal with automating lighting has always been to not have to think about it, for it to work in the background.<\/p>\n<p>In my initial post about <a href=\"http:\/\/www.diyfuturism.com\/index.php\/2017\/11\/26\/the-open-source-smart-home-getting-started-with-home-assistant-node-red\/\">Home Assistant and Node-Red<\/a>, I explained the initial hoops you have to jump through to get both pieces of software up and running and talking to each other. Now we will start using them together in some very simple flows to control lighting, to get a better understanding of how Node-Red works, and to start to delve into this powerful tool.<\/p>\n<p><!--more--><\/p>\n<p><script type=\"text\/javascript\">\namzn_assoc_placement = \"adunit0\";\namzn_assoc_tracking_id = \"diyfuturism-20\";\namzn_assoc_ad_mode = \"search\";\namzn_assoc_ad_type = \"smart\";\namzn_assoc_marketplace = \"amazon\";\namzn_assoc_region = \"US\";\namzn_assoc_default_search_phrase = \"smart home light bulb\";\namzn_assoc_default_category = \"All\";\namzn_assoc_linkid = \"ccb23140abcd3ec5538569c7b1c23826\";\namzn_assoc_design = \"in_content\";\namzn_assoc_title = \"Smart Light Bulbs\";\n<\/script><br \/>\n<script src=\"\/\/z-na.amazon-adsystem.com\/widgets\/onejs?MarketPlace=US\"><\/script><\/p>\n<h2>SPLIT PERSONALITY<\/h2>\n<p>The way I approach making automations is to think of Home Assistant as a state machine. It&#8217;s job is to track all the states of the devices, and to call services to change those states. All the hardware interfacing &#8211; the communication between the hub and the device and interpreting that information &#8211; is all Home Assistant. Home Assistant is a giant catalog of data (states) and actions (services) that Node-Red can draw from.<\/p>\n<p>Node-Red, on the other hand, is our brain. Node-Red performs the logic. Node-Red doesn&#8217;t have to keep track of states or know how to talk to a <a href=\"http:\/\/amzn.to\/2kuuZog\" target=\"_blank\" rel=\"noopener\">Philips Hue bulb<\/a> and a <a href=\"http:\/\/amzn.to\/2yw5841\" target=\"_blank\" rel=\"noopener\">Wemo smart switch<\/a>, Node-Red just asks Home Assistant when it needs to know the state of something. When Node-Red makes a decision, it sends the command (service) back to Home Assistant to handle. Node-Red is all about the big picture.<\/p>\n<p>This simple separation of duties in our automations will make integrating much easier.<\/p>\n<p><script type=\"text\/javascript\">\namzn_assoc_placement = \"adunit0\";\namzn_assoc_tracking_id = \"diyfuturism-20\";\namzn_assoc_ad_mode = \"search\";\namzn_assoc_ad_type = \"smart\";\namzn_assoc_marketplace = \"amazon\";\namzn_assoc_region = \"US\";\namzn_assoc_default_search_phrase = \"smart home\";\namzn_assoc_default_category = \"Electronics\";\namzn_assoc_linkid = \"ccb23140abcd3ec5538569c7b1c23826\";\namzn_assoc_design = \"in_content\";\namzn_assoc_title = \"\";\namzn_assoc_default_browse_node = \"172282\";\n<\/script><br \/>\n<script src=\"\/\/z-na.amazon-adsystem.com\/widgets\/onejs?MarketPlace=US\"><\/script><\/p>\n<h2>LIGHTING ONE: SIMPLE BINARY<\/h2>\n<p>I have a light bulb in an awkward crawl space that is really hard to reach. Every once in a while I need to reach a breaker in there and can never find the switch. So I replaced the bulb with a <a href=\"http:\/\/amzn.to\/2Bp3yGL\" target=\"_blank\" rel=\"noopener\">cheap smart bulb<\/a> and added a <a href=\"http:\/\/amzn.to\/2BpJST3\" target=\"_blank\" rel=\"noopener\">door sensor<\/a>. When the door opens, the light comes on, when it&#8217;s closed, the light is off.<\/p>\n<p><img data-attachment-id=\"194\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/screen-shot-2017-12-14-at-8-08-21-pm\/\" data-orig-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.08.21-PM.png?fit=582%2C161&amp;ssl=1\" data-orig-size=\"582,161\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screen Shot 2017-12-14 at 8.08.21 PM\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.08.21-PM.png?fit=300%2C83&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.08.21-PM.png?fit=582%2C161&amp;ssl=1\" loading=\"lazy\" class=\"aligncenter size-full wp-image-194\" src=\"https:\/\/i2.wp.com\/www.diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.08.21-PM.png?resize=582%2C161\" alt=\"\" width=\"582\" height=\"161\" srcset=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.08.21-PM.png?w=582&amp;ssl=1 582w, https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.08.21-PM.png?resize=300%2C83&amp;ssl=1 300w\" sizes=\"(max-width: 582px) 100vw, 582px\" data-recalc-dims=\"1\" \/><\/p>\n<pre>[{\"id\":\"70a001ee.bfd2e\",\"type\":\"server-state-changed\",\"z\":\"18835ede.3f82d1\",\"name\":\"Crawl Space Door\",\"server\":\"8ac3cd7f.58d3e\",\"entityidfilter\":\"binary_sensor.crawl_space_door\",\"haltifstate\":\"\",\"x\":131.4206886291504,\"y\":544.5259022712708,\"wires\":[[\"d0ccbd28.cb728\"]]},{\"id\":\"d0ccbd28.cb728\",\"type\":\"switch\",\"z\":\"18835ede.3f82d1\",\"name\":\"\",\"property\":\"payload\",\"propertyType\":\"msg\",\"rules\":[{\"t\":\"eq\",\"v\":\"on\",\"vt\":\"str\"},{\"t\":\"eq\",\"v\":\"off\",\"vt\":\"str\"}],\"checkall\":\"true\",\"outputs\":2,\"x\":299.98705673217773,\"y\":544.2827610969543,\"wires\":[[\"5e9a8806.36d148\"],[\"6123b169.361c9\"]]},{\"id\":\"5e9a8806.36d148\",\"type\":\"api-call-service\",\"z\":\"18835ede.3f82d1\",\"name\":\"ON\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"light\",\"service\":\"turn_on\",\"data\":\"{\\\"entity_id\\\":\\\"light.crawl_space\\\"}\",\"x\":444.8025550842285,\"y\":516.2688345909119,\"wires\":[]},{\"id\":\"6123b169.361c9\",\"type\":\"api-call-service\",\"z\":\"18835ede.3f82d1\",\"name\":\"OFF\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"homeassistant\",\"service\":\"turn_off\",\"data\":\"{\\\"entity_id\\\":\\\"light.crawl_space\\\"}\",\"x\":445.87427139282227,\"y\":567.6973919868469,\"wires\":[]},{\"id\":\"8ac3cd7f.58d3e\",\"type\":\"server\",\"z\":\"\",\"name\":\"Home Assistant\",\"url\":\"http:\/\/localhost:8123\",\"pass\":\"XXXXX\"}]<\/pre>\n<p>Our input is a Home Assistant state node that monitors the <a href=\"http:\/\/amzn.to\/2BpJST3\" target=\"_blank\" rel=\"noopener\">door sensor<\/a>. When a state change is detected, it&#8217;s sent as a message to the next node, a switch.<\/p>\n<p><img data-attachment-id=\"195\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/screen-shot-2017-12-14-at-8-09-17-pm\/\" data-orig-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.09.17-PM.png?fit=503%2C268&amp;ssl=1\" data-orig-size=\"503,268\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screen Shot 2017-12-14 at 8.09.17 PM\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.09.17-PM.png?fit=300%2C160&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.09.17-PM.png?fit=503%2C268&amp;ssl=1\" loading=\"lazy\" class=\"aligncenter size-full wp-image-195\" src=\"https:\/\/i1.wp.com\/www.diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.09.17-PM.png?resize=503%2C268\" alt=\"\" width=\"503\" height=\"268\" srcset=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.09.17-PM.png?w=503&amp;ssl=1 503w, https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.09.17-PM.png?resize=300%2C160&amp;ssl=1 300w\" sizes=\"(max-width: 503px) 100vw, 503px\" data-recalc-dims=\"1\" \/><\/p>\n<p>If the message (<strong>msg.payload\u00a0<\/strong>in Node-Red terms) is on, route to output 1, if it&#8217;s off, route to output 2. These outputs end in Home Assistant service calls that turn the light on or off.<\/p>\n<p>&nbsp;<\/p>\n<p>You must hit the &#8220;DEPLOY&#8221; to save and activate your flow.<\/p>\n<p>Congrats, this is the entire process of creating an automation with Node-Red.<\/p>\n<p><script async src=\"\/\/z-na.amazon-adsystem.com\/widgets\/onejs?MarketPlace=US&#038;adInstanceId=8ba45d28-72f3-4d97-89af-ef96de2a7468\"><\/script><\/p>\n<h2>LIGHTING TWO: MOTION TIMER<\/h2>\n<p>Let&#8217;s do something more interesting. For this example we will need an extra node called <a href=\"https:\/\/flows.nodered.org\/node\/node-red-contrib-stoptimer\" target=\"_blank\" rel=\"noopener\">stoptimer<\/a>, which can be installed through &#8220;Manage palette&#8221; in the Node-Red menu. When stoptimer receives a message, the timer starts. If it receives another message the timer is reset. If it gets a message that says &#8220;<strong>STOP<\/strong>&#8221; then it cancels the timer. Pretty useful.<\/p>\n<p>I have a <a href=\"http:\/\/amzn.to\/2BoMMro\" target=\"_blank\" rel=\"noopener\">motion sensor<\/a> under my office desk, when I sit down the lights come on. If I walk away I want the lights to turn off &#8211; say after 20 minutes of no activity.<\/p>\n<p><img data-attachment-id=\"199\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/screen-shot-2017-12-14-at-8-34-05-pm\/\" data-orig-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.34.05-PM.png?fit=806%2C149&amp;ssl=1\" data-orig-size=\"806,149\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screen Shot 2017-12-14 at 8.34.05 PM\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.34.05-PM.png?fit=300%2C55&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.34.05-PM.png?fit=806%2C149&amp;ssl=1\" loading=\"lazy\" class=\"aligncenter size-full wp-image-199\" src=\"https:\/\/i0.wp.com\/www.diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.34.05-PM.png?resize=806%2C149\" alt=\"\" width=\"806\" height=\"149\" srcset=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.34.05-PM.png?w=806&amp;ssl=1 806w, https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.34.05-PM.png?resize=600%2C111&amp;ssl=1 600w, https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.34.05-PM.png?resize=300%2C55&amp;ssl=1 300w, https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.34.05-PM.png?resize=768%2C142&amp;ssl=1 768w\" sizes=\"(max-width: 806px) 100vw, 806px\" data-recalc-dims=\"1\" \/><\/p>\n<pre>[{\"id\":\"6b710453.81dbac\",\"type\":\"server-state-changed\",\"z\":\"4056fc4f.0baa64\",\"name\":\"Office Motion\",\"server\":\"8ac3cd7f.58d3e\",\"entityidfilter\":\"binary_sensor.office_motion\",\"haltifstate\":\"\",\"x\":190,\"y\":380,\"wires\":[[\"994dd149.e4555\"]]},{\"id\":\"19caec7f.e0b4d4\",\"type\":\"stoptimer\",\"z\":\"4056fc4f.0baa64\",\"duration\":\"20\",\"units\":\"Minute\",\"payloadtype\":\"num\",\"payloadval\":\"0\",\"name\":\"20min\",\"x\":550,\"y\":420,\"wires\":[[\"a9408fec.408e1\"],[]]},{\"id\":\"a9408fec.408e1\",\"type\":\"api-call-service\",\"z\":\"4056fc4f.0baa64\",\"name\":\"OFF\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"homeassistant\",\"service\":\"turn_off\",\"data\":\"{\\\"entity_id\\\":\\\"group.Office\\\"}\",\"x\":1010,\"y\":414,\"wires\":[]},{\"id\":\"fa446f4f.1df58\",\"type\":\"api-call-service\",\"z\":\"4056fc4f.0baa64\",\"name\":\"ON\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"homeassistant\",\"service\":\"turn_on\",\"data\":\"{\\\"entity_id\\\":\\\"group.Office\\\"}\",\"x\":1010.1666526794434,\"y\":373.95236015319824,\"wires\":[]},{\"id\":\"994dd149.e4555\",\"type\":\"switch\",\"z\":\"4056fc4f.0baa64\",\"name\":\"\",\"property\":\"payload\",\"propertyType\":\"msg\",\"rules\":[{\"t\":\"eq\",\"v\":\"on\",\"vt\":\"str\"},{\"t\":\"eq\",\"v\":\"off\",\"vt\":\"str\"}],\"checkall\":\"true\",\"outputs\":2,\"x\":350,\"y\":380,\"wires\":[[\"19caec7f.e0b4d4\",\"da14546c.577218\"],[\"19caec7f.e0b4d4\"]]},{\"id\":\"da14546c.577218\",\"type\":\"api-current-state\",\"z\":\"4056fc4f.0baa64\",\"name\":\"Already On?\",\"server\":\"8ac3cd7f.58d3e\",\"halt_if\":\"on\",\"entity_id\":\"switch.office\",\"x\":748,\"y\":373,\"wires\":[[\"fa446f4f.1df58\"]]},{\"id\":\"8ac3cd7f.58d3e\",\"type\":\"server\",\"z\":\"\",\"name\":\"Home Assistant\",\"url\":\"http:\/\/localhost:8123\",\"pass\":\"XXXXX\"}]<\/pre>\n<p>We&#8217;ve added a few nodes to our first example, let&#8217;s follow the flow.<\/p>\n<p>If Office Motion is\u00a0<strong>on<\/strong>, the switch sends it down two paths simultaneously:<\/p>\n<ul>\n<li>A state node that looks up the state of\u00a0<strong>group.office<\/strong>. If it&#8217;s already\u00a0<strong>on<\/strong>, the flow halts, otherwise the lights are turned on<\/li>\n<li>Starts or resets the 20 minute stoptimer if it&#8217;s already running. If no other state changes come from the Office Motion sensor, the\u00a0<strong>msg.payload<\/strong> terminates in an off service command.<\/li>\n<\/ul>\n<p>If Office Motion is\u00a0<strong>off<\/strong>, it starts or resets the timer.<\/p>\n<p>This keeps the lights on as long as something is happening with the <a href=\"http:\/\/amzn.to\/2BoMMro\" target=\"_blank\" rel=\"noopener\">motion sensor<\/a>. When there&#8217;s been no activity for 20 minutes, the timer reaches it&#8217;s conclusion and the\u00a0<strong>msg.payload<\/strong> is sent to the output to turn the light off.<\/p>\n<p>Note in the &#8220;Already On?&#8221; node we can halt the flow according to the state it returns:<\/p>\n<p><img data-attachment-id=\"200\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/screen-shot-2017-12-14-at-8-33-30-pm\/\" data-orig-file=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.33.30-PM.png?fit=504%2C259&amp;ssl=1\" data-orig-size=\"504,259\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screen Shot 2017-12-14 at 8.33.30 PM\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.33.30-PM.png?fit=300%2C154&amp;ssl=1\" data-large-file=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.33.30-PM.png?fit=504%2C259&amp;ssl=1\" loading=\"lazy\" class=\"aligncenter size-full wp-image-200\" src=\"https:\/\/i2.wp.com\/www.diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.33.30-PM.png?resize=504%2C259\" alt=\"\" width=\"504\" height=\"259\" srcset=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.33.30-PM.png?w=504&amp;ssl=1 504w, https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.33.30-PM.png?resize=300%2C154&amp;ssl=1 300w\" sizes=\"(max-width: 504px) 100vw, 504px\" data-recalc-dims=\"1\" \/><\/p>\n<p>The alternative would be to use a switch node, but this saves us the trouble. In Home Assistant terminology, this is equivalent to a condition.<\/p>\n<div id=\"amzn-assoc-ad-8ba45d28-72f3-4d97-89af-ef96de2a7468\"><\/div>\n<p><script async src=\"\/\/z-na.amazon-adsystem.com\/widgets\/onejs?MarketPlace=US&#038;adInstanceId=8ba45d28-72f3-4d97-89af-ef96de2a7468\"><\/script><\/p>\n<h2>LIGHTING THREE: MOTION, TIME RANGE, &amp; OCCUPANCY<\/h2>\n<p>Now that&#8217;s we&#8217;ve done two simple examples, let&#8217;s start to show off the real power of Node-Red. For this one we&#8217;re going to need another additional node, the\u00a0<a href=\"https:\/\/flows.nodered.org\/node\/node-red-contrib-time-range-switch\" target=\"_blank\" rel=\"noopener\">time range switch<\/a>. I&#8217;m also using a meta-motion sensor that shows where Home Assistant last saw motion.<\/p>\n<p><img data-attachment-id=\"202\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/screen-shot-2017-12-14-at-8-52-58-pm\/\" data-orig-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.52.58-PM.png?fit=774%2C161&amp;ssl=1\" data-orig-size=\"774,161\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screen Shot 2017-12-14 at 8.52.58 PM\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.52.58-PM.png?fit=300%2C62&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.52.58-PM.png?fit=774%2C161&amp;ssl=1\" loading=\"lazy\" class=\"aligncenter wp-image-202 size-full\" src=\"https:\/\/i1.wp.com\/www.diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.52.58-PM.png?resize=774%2C161\" alt=\"\" width=\"774\" height=\"161\" srcset=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.52.58-PM.png?w=774&amp;ssl=1 774w, https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.52.58-PM.png?resize=600%2C125&amp;ssl=1 600w, https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.52.58-PM.png?resize=300%2C62&amp;ssl=1 300w, https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-8.52.58-PM.png?resize=768%2C160&amp;ssl=1 768w\" sizes=\"(max-width: 774px) 100vw, 774px\" data-recalc-dims=\"1\" \/><\/p>\n<pre>[{\"id\":\"4876c05d.90497\",\"type\":\"server-state-changed\",\"z\":\"4056fc4f.0baa64\",\"name\":\"Bathroom Motion\",\"server\":\"8ac3cd7f.58d3e\",\"entityidfilter\":\"binary_sensor.bathroom_motion\",\"haltifstate\":\"off\",\"x\":220,\"y\":420,\"wires\":[[\"e25bff84.3451d\"]]},{\"id\":\"e25bff84.3451d\",\"type\":\"time-range-switch\",\"z\":\"4056fc4f.0baa64\",\"name\":\"After 6AM\",\"lat\":\"\",\"lon\":\"\",\"startTime\":\"06:00\",\"endTime\":\"23:59\",\"x\":403.333309173584,\"y\":419.9999780654907,\"wires\":[[\"e6559f89.5c606\",\"ec4009c3.5b4c48\"],[]]},{\"id\":\"e6559f89.5c606\",\"type\":\"api-current-state\",\"z\":\"4056fc4f.0baa64\",\"name\":\"Light Off?\",\"server\":\"8ac3cd7f.58d3e\",\"halt_if\":\"on\",\"entity_id\":\"switch.bathroom_light\",\"x\":573.3334007263184,\"y\":381.33339405059814,\"wires\":[[\"13aee75f.de9699\"]]},{\"id\":\"13aee75f.de9699\",\"type\":\"api-call-service\",\"z\":\"4056fc4f.0baa64\",\"name\":\"ON\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"switch\",\"service\":\"turn_on\",\"data\":\"{\\\"entity_id\\\":\\\"switch.bathroom_light\\\"}\",\"x\":1034.9999504089355,\"y\":382.99997901916504,\"wires\":[]},{\"id\":\"1c5dbbe7.4de5e4\",\"type\":\"api-render-template\",\"z\":\"4056fc4f.0baa64\",\"name\":\"Still in Bathroom?\",\"server\":\"8ac3cd7f.58d3e\",\"template\":\"{{ states.variable.last_motion.state != 'Bathroom Motion' }}\",\"x\":743.3333396911621,\"y\":440.0000238418579,\"wires\":[[\"67242a38.922154\"]]},{\"id\":\"ec4009c3.5b4c48\",\"type\":\"stoptimer\",\"z\":\"4056fc4f.0baa64\",\"duration\":\"12\",\"units\":\"Minute\",\"payloadtype\":\"num\",\"payloadval\":\"0\",\"name\":\"12min\",\"x\":560.0000190734863,\"y\":446.6667079925537,\"wires\":[[\"1c5dbbe7.4de5e4\"],[]]},{\"id\":\"67242a38.922154\",\"type\":\"switch\",\"z\":\"4056fc4f.0baa64\",\"name\":\"\",\"property\":\"payload\",\"propertyType\":\"msg\",\"rules\":[{\"t\":\"eq\",\"v\":\"True\",\"vt\":\"str\"}],\"checkall\":\"true\",\"outputs\":1,\"x\":908.3333015441895,\"y\":440.00000286102295,\"wires\":[[\"e1e6dad7.9a0dc8\"]]},{\"id\":\"e1e6dad7.9a0dc8\",\"type\":\"api-call-service\",\"z\":\"4056fc4f.0baa64\",\"name\":\"OFF\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"homeassistant\",\"service\":\"turn_off\",\"data\":\"{\\\"entity_id\\\":\\\"group.bathroom\\\"}\",\"x\":1037.5001754760742,\"y\":440.00003147125244,\"wires\":[]},{\"id\":\"ed231cde.fc99\",\"type\":\"server-state-changed\",\"z\":\"4056fc4f.0baa64\",\"name\":\"Bathroom Switch Flipped On\",\"server\":\"8ac3cd7f.58d3e\",\"entityidfilter\":\"switch.bathroom_light\",\"haltifstate\":\"off\",\"x\":353.33336639404297,\"y\":495.0001130104065,\"wires\":[[\"ec4009c3.5b4c48\"]]},{\"id\":\"8ac3cd7f.58d3e\",\"type\":\"server\",\"z\":\"\",\"name\":\"Home Assistant\",\"url\":\"http:\/\/localhost:8123\",\"pass\":\"XXXXX\"}]<\/pre>\n<p>In my bathroom I&#8217;ve got a <a href=\"http:\/\/amzn.to\/2BoMMro\" target=\"_blank\" rel=\"noopener\">motion sensor<\/a> and a <a href=\"http:\/\/amzn.to\/2yv494c\" target=\"_blank\" rel=\"noopener\">Z-Wave wall switch<\/a> that controls the light. I want the light to turn off after 12 minutes of no motion, but not if I&#8217;m still&#8230; taking care of business. The switch should trigger the same timer if someone uses it. And also &#8211; I don&#8217;t want to get blinded if I get up in the middle of the night.<\/p>\n<p>Following the flow, the state of the Bathroom Motion sensor is sent to the time-range switch, which will only continue if it&#8217;s after 6AM. After that we essentially do the same thing as the last example, checking to see if the light is already on before calling the light.turn_on service. The stop timer accepts another input from the wall switch if guests use it.<\/p>\n<p>After the timer concludes, it gets the state of the meta-motion sensor and the switch evaluates if I&#8217;m still in the Bathroom before turning the light off.<\/p>\n<div id=\"amzn-assoc-ad-8ba45d28-72f3-4d97-89af-ef96de2a7468\"><\/div>\n<p><script async src=\"\/\/z-na.amazon-adsystem.com\/widgets\/onejs?MarketPlace=US&#038;adInstanceId=8ba45d28-72f3-4d97-89af-ef96de2a7468\"><\/script><\/p>\n<h2>LIGHTING FOUR: SOLAR EVENT TRIGGER<\/h2>\n<p>What about having the lights turn on at sunset? There&#8217;s more than one node for that. Here I am using\u00a0<a href=\"https:\/\/www.npmjs.com\/package\/node-red-contrib-bigtimer\" target=\"_blank\" rel=\"noopener\" class=\"broken_link\">bigtimer<\/a>\u00a0because it allows offsetting solar events. You can read the documentation for bigtimer, it&#8217;s kind of more complicated than it needs to be IMO, but it&#8217;s useful here for turning my aquarium on at sunset and off at 10pm.<\/p>\n<p><img data-attachment-id=\"204\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/screen-shot-2017-12-14-at-9-09-26-pm\/\" data-orig-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-9.09.26-PM.png?fit=658%2C126&amp;ssl=1\" data-orig-size=\"658,126\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screen Shot 2017-12-14 at 9.09.26 PM\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-9.09.26-PM.png?fit=300%2C57&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-9.09.26-PM.png?fit=658%2C126&amp;ssl=1\" loading=\"lazy\" class=\"aligncenter size-full wp-image-204\" src=\"https:\/\/i1.wp.com\/www.diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-9.09.26-PM.png?resize=658%2C126\" alt=\"\" width=\"658\" height=\"126\" srcset=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-9.09.26-PM.png?w=658&amp;ssl=1 658w, https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-9.09.26-PM.png?resize=600%2C115&amp;ssl=1 600w, https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-9.09.26-PM.png?resize=300%2C57&amp;ssl=1 300w\" sizes=\"(max-width: 658px) 100vw, 658px\" data-recalc-dims=\"1\" \/><\/p>\n<pre>[{\"id\":\"c49b6101.4865\",\"type\":\"bigtimer\",\"z\":\"59230ccd.4625e4\",\"outtopic\":\"\",\"outpayload1\":\"\",\"outpayload2\":\"\",\"name\":\"Sunset\",\"lat\":\"37.799564008\",\"lon\":\"-122.268797\",\"starttime\":\"5004\",\"endtime\":\"5003\",\"startoff\":\"-60\",\"endoff\":\"240\",\"offs\":0,\"outtext1\":\"on\",\"outtext2\":\"off\",\"timeout\":1440,\"sun\":true,\"mon\":true,\"tue\":true,\"wed\":true,\"thu\":true,\"fri\":true,\"sat\":true,\"jan\":true,\"feb\":true,\"mar\":true,\"apr\":true,\"may\":true,\"jun\":true,\"jul\":true,\"aug\":true,\"sep\":true,\"oct\":true,\"nov\":true,\"dec\":true,\"day1\":0,\"month1\":0,\"day2\":0,\"month2\":0,\"day3\":0,\"month3\":0,\"day4\":0,\"month4\":0,\"day5\":0,\"month5\":0,\"d1\":0,\"w1\":0,\"d2\":0,\"w2\":0,\"d3\":0,\"w3\":0,\"d4\":0,\"w4\":0,\"d5\":0,\"w5\":0,\"suspend\":false,\"random\":false,\"repeat\":true,\"atstart\":true,\"odd\":false,\"even\":false,\"x\":353.75000381469727,\"y\":428.7500057220459,\"wires\":[[],[],[\"c6e50538.2732a8\"]]},{\"id\":\"c6e50538.2732a8\",\"type\":\"switch\",\"z\":\"59230ccd.4625e4\",\"name\":\"\",\"property\":\"payload\",\"propertyType\":\"msg\",\"rules\":[{\"t\":\"eq\",\"v\":\"on\",\"vt\":\"str\"},{\"t\":\"eq\",\"v\":\"off\",\"vt\":\"str\"}],\"checkall\":\"true\",\"outputs\":2,\"x\":593.1337394714355,\"y\":406.8185729980469,\"wires\":[[\"4c8b4d1b.32ece4\"],[\"db50b01e.eea8e\"]]},{\"id\":\"893ff0c6.accba\",\"type\":\"api-call-service\",\"z\":\"59230ccd.4625e4\",\"name\":\"Turn off Aquarium\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"switch\",\"service\":\"turn_off\",\"data\":\"{\\\"entity_id\\\":\\\"switch.aquarium\\\"}\",\"x\":990.0001640319824,\"y\":446.24994373321533,\"wires\":[]},{\"id\":\"4c8b4d1b.32ece4\",\"type\":\"api-call-service\",\"z\":\"59230ccd.4625e4\",\"name\":\"Turn on Aquarium\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"switch\",\"service\":\"turn_on\",\"data\":\"{\\\"entity_id\\\":\\\"switch.aquarium\\\"}\",\"x\":989.3838424682617,\"y\":382.6952495574951,\"wires\":[]},{\"id\":\"bc733e16.0eb51\",\"type\":\"inject\",\"z\":\"59230ccd.4625e4\",\"name\":\"10pm\",\"topic\":\"\",\"payload\":\"\",\"payloadType\":\"date\",\"repeat\":\"\",\"crontab\":\"00 22 * * *\",\"once\":false,\"x\":600.6250152587891,\"y\":444.9523983001709,\"wires\":[[\"893ff0c6.accba\"]]},{\"id\":\"db50b01e.eea8e\",\"type\":\"api-current-state\",\"z\":\"59230ccd.4625e4\",\"name\":\"Off Already?\",\"server\":\"8ac3cd7f.58d3e\",\"halt_if\":\"off\",\"entity_id\":\"switch.aquarium\",\"x\":762.4783706665039,\"y\":422.348180770874,\"wires\":[[\"893ff0c6.accba\"]]},{\"id\":\"8ac3cd7f.58d3e\",\"type\":\"server\",\"z\":\"\",\"name\":\"Home Assistant\",\"url\":\"http:\/\/localhost:8123\",\"pass\":\"XXXXXX\"}]<\/pre>\n<h2>MORE LINKS<\/h2>\n<p>Hopefully now you&#8217;ve got a better idea of some of the things that are possible using just a handful of nodes with Home Assistant. I&#8217;ve got a big list of nodes I&#8217;ve used in home automation linked below if you want to explore some more.<\/p>\n<p>One of the great things about Node-Red is how easy it is to share flows. Copy from the pastebin link below to get all the flows here and start automating your lights immediately!<\/p>\n<ul>\n<li><a href=\"https:\/\/pastebin.com\/3QbbKRf4\" target=\"_blank\" rel=\"noopener\"><strong>PasteBin of All Flows in this Post<\/strong><\/a><\/li>\n<li>My <a href=\"http:\/\/www.diyfuturism.com\/index.php\/2017\/11\/26\/big-list-of-home-automation-nodes-for-node-red\/\">Big List of Useful Home Automation Nodes<\/a><\/li>\n<li><a href=\"https:\/\/flows.nodered.org\/\" target=\"_blank\" rel=\"noopener\">Node-Red Flow Search<\/a><\/li>\n<\/ul>\n<div id=\"amzn-assoc-ad-8ba45d28-72f3-4d97-89af-ef96de2a7468\"><\/div>\n<p><script async src=\"\/\/z-na.amazon-adsystem.com\/widgets\/onejs?MarketPlace=US&#038;adInstanceId=8ba45d28-72f3-4d97-89af-ef96de2a7468\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"wpm_excerpt clearfix\"><p>Smart light bulbs are probably the first thing everyone getting into home automation buys. It is easy to see the applications for them &#8211; have the &hellip;<\/p>\n<\/div>","protected":false},"author":1,"featured_media":192,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[8,7,11,3],"tags":[47,57,99,43,56,55,96,98,97,36,31,54,42,48,52,25,100],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Basic Node-Red Flows for Automating Lighting with Home Assistant - DIY Futurism<\/title>\n<meta name=\"description\" content=\"How to automate smart light bulbs with Node-Red and Home Assistant based on motion sensors and presence.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Basic Node-Red Flows for Automating Lighting with Home Assistant - DIY Futurism\" \/>\n<meta property=\"og:description\" content=\"How to automate smart light bulbs with Node-Red and Home Assistant based on motion sensors and presence.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/\" \/>\n<meta property=\"og:site_name\" content=\"DIY Futurism\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-15T05:35:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-17T04:55:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-7.49.36-PM.png?fit=835%2C631&#038;ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"835\" \/>\n\t<meta property=\"og:image:height\" content=\"631\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@diyfuturism\" \/>\n<meta name=\"twitter:site\" content=\"@diyfuturism\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"brad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/diyfuturism.com\/#website\",\"url\":\"https:\/\/diyfuturism.com\/\",\"name\":\"DIY Futurism\",\"description\":\"Adventures in Open Source Smart Home Projects\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/diyfuturism.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-7.49.36-PM.png?fit=835%2C631&ssl=1\",\"contentUrl\":\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-7.49.36-PM.png?fit=835%2C631&ssl=1\",\"width\":835,\"height\":631},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/#webpage\",\"url\":\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/\",\"name\":\"Basic Node-Red Flows for Automating Lighting with Home Assistant - DIY Futurism\",\"isPartOf\":{\"@id\":\"https:\/\/diyfuturism.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/#primaryimage\"},\"datePublished\":\"2017-12-15T05:35:37+00:00\",\"dateModified\":\"2018-01-17T04:55:40+00:00\",\"author\":{\"@id\":\"https:\/\/diyfuturism.com\/#\/schema\/person\/b93619fac07567640bd87cc613a55b7c\"},\"description\":\"How to automate smart light bulbs with Node-Red and Home Assistant based on motion sensors and presence.\",\"breadcrumb\":{\"@id\":\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/diyfuturism.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Basic Node-Red Flows for Automating Lighting with Home Assistant\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/diyfuturism.com\/#\/schema\/person\/b93619fac07567640bd87cc613a55b7c\",\"name\":\"brad\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/diyfuturism.com\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7e2d60eb1f322b4ad6040a746946a361?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7e2d60eb1f322b4ad6040a746946a361?s=96&d=mm&r=g\",\"caption\":\"brad\"},\"description\":\"I'm a professional artist who likes to tinker with building things in my spare time.\",\"sameAs\":[\"https:\/\/twitter.com\/@diyfuturism\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Basic Node-Red Flows for Automating Lighting with Home Assistant - DIY Futurism","description":"How to automate smart light bulbs with Node-Red and Home Assistant based on motion sensors and presence.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/","og_locale":"en_US","og_type":"article","og_title":"Basic Node-Red Flows for Automating Lighting with Home Assistant - DIY Futurism","og_description":"How to automate smart light bulbs with Node-Red and Home Assistant based on motion sensors and presence.","og_url":"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/","og_site_name":"DIY Futurism","article_published_time":"2017-12-15T05:35:37+00:00","article_modified_time":"2018-01-17T04:55:40+00:00","og_image":[{"width":835,"height":631,"url":"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-7.49.36-PM.png?fit=835%2C631&ssl=1","path":"\/var\/www\/html\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-7.49.36-PM.png","size":"full","id":192,"alt":"","pixels":526885,"type":"image\/png"}],"twitter_card":"summary_large_image","twitter_creator":"@diyfuturism","twitter_site":"@diyfuturism","twitter_misc":{"Written by":"brad","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/diyfuturism.com\/#website","url":"https:\/\/diyfuturism.com\/","name":"DIY Futurism","description":"Adventures in Open Source Smart Home Projects","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/diyfuturism.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/#primaryimage","inLanguage":"en-US","url":"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-7.49.36-PM.png?fit=835%2C631&ssl=1","contentUrl":"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-7.49.36-PM.png?fit=835%2C631&ssl=1","width":835,"height":631},{"@type":"WebPage","@id":"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/#webpage","url":"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/","name":"Basic Node-Red Flows for Automating Lighting with Home Assistant - DIY Futurism","isPartOf":{"@id":"https:\/\/diyfuturism.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/#primaryimage"},"datePublished":"2017-12-15T05:35:37+00:00","dateModified":"2018-01-17T04:55:40+00:00","author":{"@id":"https:\/\/diyfuturism.com\/#\/schema\/person\/b93619fac07567640bd87cc613a55b7c"},"description":"How to automate smart light bulbs with Node-Red and Home Assistant based on motion sensors and presence.","breadcrumb":{"@id":"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/diyfuturism.com\/"},{"@type":"ListItem","position":2,"name":"Basic Node-Red Flows for Automating Lighting with Home Assistant"}]},{"@type":"Person","@id":"https:\/\/diyfuturism.com\/#\/schema\/person\/b93619fac07567640bd87cc613a55b7c","name":"brad","image":{"@type":"ImageObject","@id":"https:\/\/diyfuturism.com\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/7e2d60eb1f322b4ad6040a746946a361?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7e2d60eb1f322b4ad6040a746946a361?s=96&d=mm&r=g","caption":"brad"},"description":"I'm a professional artist who likes to tinker with building things in my spare time.","sameAs":["https:\/\/twitter.com\/@diyfuturism"]}]}},"jetpack_featured_media_url":"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/12\/Screen-Shot-2017-12-14-at-7.49.36-PM.png?fit=835%2C631&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9q0Cl-35","jetpack-related-posts":[{"id":22,"url":"https:\/\/diyfuturism.com\/index.php\/2017\/11\/26\/the-open-source-smart-home-getting-started-with-home-assistant-node-red\/","url_meta":{"origin":191,"position":0},"title":"The Open Source Smart Home: Getting Started with Home Assistant &#038; Node-Red","date":"November 26, 2017","format":false,"excerpt":"Home Assistant is one of the most interesting open source projects I've ever come across. It interfaces with any device, platform, or service you can think of. It can connect all of your devices to make a truly smart home. With a little creativity almost anything is possible with Home\u2026","rel":"","context":"In &quot;Config&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2017\/11\/Screen-Shot-2017-11-26-at-10.43.33-PM.png?fit=1200%2C562&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":16,"url":"https:\/\/diyfuturism.com\/index.php\/2017\/11\/26\/big-list-of-home-automation-nodes-for-node-red\/","url_meta":{"origin":191,"position":1},"title":"Big List of Useful Home Automation Nodes for Node-Red","date":"November 26, 2017","format":false,"excerpt":"An ongoing list of nodes I have found useful for constructing home automation flows. I have not included device platform nodes, as all state tracking and actions are performed in Home Assistant.","rel":"","context":"In &quot;Node-Red&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":764,"url":"https:\/\/diyfuturism.com\/index.php\/2018\/12\/16\/my-node-red-smart-alarm-clock-with-snooze\/","url_meta":{"origin":191,"position":2},"title":"My Node-Red Smart Alarm Clock with Snooze","date":"December 16, 2018","format":false,"excerpt":"Definitely one of my very favorite features of my smart house is my alarm clock. Which is funny because I am not a morning person\u00a0at all\u00a0and hate getting up. But the daily grind is made a little better by having my house gently wake me by fading in lights and\u2026","rel":"","context":"In &quot;Config&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/12\/david-von-diemar-291597-unsplash.jpg?fit=1200%2C734&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":469,"url":"https:\/\/diyfuturism.com\/index.php\/2018\/03\/13\/location-aware-notification-lights-node-red-ifttt\/","url_meta":{"origin":191,"position":3},"title":"Location Aware Notification Lights with Node-Red and IFTTT","date":"March 13, 2018","format":false,"excerpt":"I am in the habit of going on cooking sprees while listening to music... loudly. I only share one wall with a neighbor here in the loft, and that neighbor is very tolerant. On a Sunday afternoon, with multiple dishes going at a time, my most used smart home feature\u2026","rel":"","context":"In &quot;Home Assistant&quot;","img":{"alt_text":"Connecting Node Red and IFTTT","src":"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/03\/36159691101_b469c9a91f_k.jpg?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":410,"url":"https:\/\/diyfuturism.com\/index.php\/2018\/01\/23\/nodes-home-automation-state-machine-actionflows-dashboard-statistics\/","url_meta":{"origin":191,"position":4},"title":"More Nodes for Home Automation: state-machine, actionflows, dashboard, statistics","date":"January 23, 2018","format":false,"excerpt":"I'm keeping a running list of useful nodes I've found for home automation. Here's a couple of more I came across recently in the Node-Red library. dashboard\u00a0- Create an entirely custom, live dashboard. Amazing! statistics - Some useful statistical functions, based on\u00a0Simple Statistics state-machine\u00a0- Manage a state machine with your\u2026","rel":"","context":"In &quot;Node-Red&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":718,"url":"https:\/\/diyfuturism.com\/index.php\/2018\/07\/30\/automate-dumb-devices-ir-node-red-home-assistant\/","url_meta":{"origin":191,"position":5},"title":"Automating Dumb Devices with Node-Red and Home Assistant","date":"July 30, 2018","format":false,"excerpt":"Here in coastal California, air conditioning is extremely uncommon. So during a recent heat wave, I got desperate and went down to the big box store in search of some relief and came home with a regular old dumb fan. I'm sure this is the kind of gadget you could\u2026","rel":"","context":"In &quot;Hardware&quot;","img":{"alt_text":"Automating a Dumb Fan","src":"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/07\/Screenshot-from-2018-07-30-125551.png?fit=939%2C759&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/posts\/191"}],"collection":[{"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/comments?post=191"}],"version-history":[{"count":12,"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/posts\/191\/revisions"}],"predecessor-version":[{"id":770,"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/posts\/191\/revisions\/770"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/media\/192"}],"wp:attachment":[{"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/media?parent=191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/categories?post=191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/tags?post=191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}