{"id":374,"date":"2018-01-18T15:23:56","date_gmt":"2018-01-18T23:23:56","guid":{"rendered":"http:\/\/diyfuturism.com\/?p=374"},"modified":"2018-01-19T12:42:14","modified_gmt":"2018-01-19T20:42:14","slug":"going-further-with-home-automations-in-node-red","status":"publish","type":"post","link":"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/","title":{"rendered":"Going Further with Home Automations in Node-Red"},"content":{"rendered":"<p>In my <a href=\"http:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/\">last post<\/a>\u00a0about using Node-Red to make automations with Home Assistant, I showed some very simple flows for turning lights on and off. While it is important to get used to the Node-Red way of doing things and it&#8217;s interface, none of the examples in my post are very compelling. All of that can easily be accomplished in Home Assistant already, so what makes Node-Red so awesome?<\/p>\n<p>Let&#8217;s examine some of Node-Red&#8217;s features a little closer to get a better idea of what&#8217;s going on, how we can use that to create dynamic automations\u00a0with Home Assistant, and an example of an alarm clock radio flow that uses some advanced logic nodes.<\/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 = \"raspberry pi\";\namzn_assoc_default_category = \"Electronics\";\namzn_assoc_linkid = \"56be2f14439da0d27feb71eed1ee9093\";\namzn_assoc_default_browse_node = \"172282\";\namzn_assoc_design = \"in_content\";\n<\/script><br \/>\n<script src=\"\/\/z-na.amazon-adsystem.com\/widgets\/onejs?MarketPlace=US\"><\/script><\/p>\n<h2>GETTING THE MSG<\/h2>\n<p>The simplest explanation of Node-Red is that it a way to route messages. Input nodes create a\u00a0<strong>msg<\/strong>\u00a0that has several parts, the nodes in the flow examine this message to decide where to send it next, &amp; this ends in an output that acts on the message.<\/p>\n<p>Usually, we are most interested in the\u00a0<strong>msg.payload<\/strong>, but that&#8217;s not the only information the <strong>msg<\/strong> carries. By setting a\u00a0<strong>debug<\/strong> node to output the entire message, we can see all the information:<\/p>\n<div id=\"attachment_377\" style=\"width: 509px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-377\" data-attachment-id=\"377\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/screen-shot-2018-01-18-at-12-37-25-pm\/\" data-orig-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-12.37.25-PM.png?fit=499%2C283&amp;ssl=1\" data-orig-size=\"499,283\" 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=\"Debug Node&#8217;s Output Settings\" data-image-description=\"&lt;p&gt;Debug Node&#8217;s Output Settings&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Debug Node&#8217;s Output Settings&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-12.37.25-PM.png?fit=300%2C170&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-12.37.25-PM.png?fit=499%2C283&amp;ssl=1\" loading=\"lazy\" class=\"size-full wp-image-377\" src=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-12.37.25-PM.png?resize=499%2C283\" alt=\"Debug Node's Output Settings\" width=\"499\" height=\"283\" srcset=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-12.37.25-PM.png?w=499&amp;ssl=1 499w, https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-12.37.25-PM.png?resize=300%2C170&amp;ssl=1 300w\" sizes=\"(max-width: 499px) 100vw, 499px\" data-recalc-dims=\"1\" \/><p id=\"caption-attachment-377\" class=\"wp-caption-text\">Debug Node&#8217;s Output Settings<\/p><\/div>\n<p>If I hook this debug node up to my location device_tracker, I get this in the Debug panel:<\/p>\n<div id=\"attachment_378\" style=\"width: 438px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-378\" data-attachment-id=\"378\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/screen-shot-2018-01-18-at-12-48-21-pm\/\" data-orig-file=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-12.48.21-PM.png?fit=428%2C466&amp;ssl=1\" data-orig-size=\"428,466\" 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=\"Full debug msg output\" data-image-description=\"&lt;p&gt;Full debug msg output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Full debug msg output&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-12.48.21-PM.png?fit=276%2C300&amp;ssl=1\" data-large-file=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-12.48.21-PM.png?fit=428%2C466&amp;ssl=1\" loading=\"lazy\" class=\"size-full wp-image-378\" src=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-12.48.21-PM.png?resize=428%2C466\" alt=\"Full debug msg output\" width=\"428\" height=\"466\" srcset=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-12.48.21-PM.png?w=428&amp;ssl=1 428w, https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-12.48.21-PM.png?resize=276%2C300&amp;ssl=1 276w\" sizes=\"(max-width: 428px) 100vw, 428px\" data-recalc-dims=\"1\" \/><p id=\"caption-attachment-378\" class=\"wp-caption-text\">Full debug msg output<\/p><\/div>\n<p>That&#8217;s a lot more info than just the payload! Both the new and the old state are here, as well as the full range of attributes that Home Assistant tracks.<\/p>\n<p>But how to use this information? To get the latitude and longitude here we would refer to them as:<\/p>\n<pre>msg.data.new_state.attributes.latitude\r\nmsg.data.new_state.attributes.longitude<\/pre>\n<p>This can get slightly more complicated if the information is contained in a different data type, such as an array or object. If, like me, you are not a programmer you may want to keep this\u00a0<a href=\"https:\/\/www.w3schools.com\/js\/js_datatypes.asp\">basic overview of data types in javascript<\/a>\u00a0handy if you are having trouble figuring out the syntax.<\/p>\n<p>&nbsp;<\/p>\n<h2>DYNAMIC SERVICE CALLS<\/h2>\n<p>Now that we can see there&#8217;s more to the msg than the payload, let&#8217;s use it to make our automations more useful. It&#8217;s great to be able to turn a light on or off, but what if we want our automation to set the brightness dynamically?<\/p>\n<h3>MSG.PAYLOAD.DATA<\/h3>\n<p>The\u00a0<strong>call service<\/strong>\u00a0Home Assistant node will look for a <strong>data<\/strong> object in the <strong>msg.payload<\/strong>. Anything it finds in the data object will be used to override the settings you entered in the call service node. The syntax for this looks like:<\/p>\n<pre>msg.payload = { \"data\": {\"entity_id\":\"light.bedroom\",\"brightness\": 255 } }<\/pre>\n<p>Using an inject node, set the msg.payload to JSON and enter the above value. Since we are sending all the information necessary to make the service call, we can just leave the &#8220;Data&#8221; field blank in the output with a pair of brackets { }.<\/p>\n<p><img data-attachment-id=\"381\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/screen-shot-2018-01-18-at-1-28-01-pm\/\" data-orig-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.01-PM.png?fit=551%2C91&amp;ssl=1\" data-orig-size=\"551,91\" 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 2018-01-18 at 1.28.01 PM\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.01-PM.png?fit=300%2C50&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.01-PM.png?fit=551%2C91&amp;ssl=1\" loading=\"lazy\" class=\"aligncenter size-full wp-image-381\" src=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.01-PM.png?resize=551%2C91\" alt=\"\" width=\"551\" height=\"91\" srcset=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.01-PM.png?w=551&amp;ssl=1 551w, https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.01-PM.png?resize=300%2C50&amp;ssl=1 300w\" sizes=\"(max-width: 551px) 100vw, 551px\" data-recalc-dims=\"1\" \/><\/p>\n<p>Settings:<\/p>\n<div id=\"attachment_380\" style=\"width: 542px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-380\" data-attachment-id=\"380\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/screen-shot-2018-01-18-at-1-28-16-pm\/\" data-orig-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.16-PM.png?fit=532%2C356&amp;ssl=1\" data-orig-size=\"532,356\" 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=\"\" data-image-description=\"&lt;p&gt;Inject Node&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Inject Node&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.16-PM.png?fit=300%2C201&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.16-PM.png?fit=532%2C356&amp;ssl=1\" loading=\"lazy\" class=\"size-full wp-image-380\" src=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.16-PM.png?resize=532%2C356\" alt=\"Inject Node\" width=\"532\" height=\"356\" srcset=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.16-PM.png?w=532&amp;ssl=1 532w, https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.16-PM.png?resize=300%2C201&amp;ssl=1 300w\" sizes=\"(max-width: 532px) 100vw, 532px\" data-recalc-dims=\"1\" \/><p id=\"caption-attachment-380\" class=\"wp-caption-text\">Inject Node<\/p><\/div>\n<div id=\"attachment_379\" style=\"width: 499px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-379\" data-attachment-id=\"379\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/screen-shot-2018-01-18-at-1-28-30-pm\/\" data-orig-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.30-PM.png?fit=489%2C389&amp;ssl=1\" data-orig-size=\"489,389\" 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=\"\" data-image-description=\"&lt;p&gt;Service Call Node&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Service Call Node&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.30-PM.png?fit=300%2C239&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.30-PM.png?fit=489%2C389&amp;ssl=1\" loading=\"lazy\" class=\"size-full wp-image-379\" src=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.30-PM.png?resize=489%2C389\" alt=\"Service Call Node\" width=\"489\" height=\"389\" srcset=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.30-PM.png?w=489&amp;ssl=1 489w, https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-1.28.30-PM.png?resize=300%2C239&amp;ssl=1 300w\" sizes=\"(max-width: 489px) 100vw, 489px\" data-recalc-dims=\"1\" \/><p id=\"caption-attachment-379\" class=\"wp-caption-text\">Service Call Node<\/p><\/div>\n<p>Flow JSON:<\/p>\n<pre>[{\"id\":\"aa2c6a07.d910d8\",\"type\":\"inject\",\"z\":\"86cf38de.45d048\",\"name\":\"\",\"topic\":\"\",\"payload\":\"{ \\\"data\\\": {\\\"entity_id\\\":\\\"light.bedroom\\\",\\\"brightness\\\": 255 } }\",\"payloadType\":\"json\",\"repeat\":\"\",\"crontab\":\"\",\"once\":false,\"x\":170,\"y\":260,\"wires\":[[\"992a58f4.573ad8\"]]},{\"id\":\"992a58f4.573ad8\",\"type\":\"api-call-service\",\"z\":\"86cf38de.45d048\",\"name\":\"Service Call\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"light\",\"service\":\"turn_on\",\"data\":\"{ }\",\"x\":430,\"y\":260,\"wires\":[]},{\"id\":\"8ac3cd7f.58d3e\",\"type\":\"server\",\"z\":\"\",\"name\":\"Home Assistant\",\"url\":\"http:\/\/localhost:8123\",\"pass\":\"YOURPASS\"}]<\/pre>\n<p>Deploy the flow and press the button on the inject node: boom! Now our service call outputs can accept a range of commands from upstream in the flow, determined programmatically instead of hardcoded into the automation.<\/p>\n<h3>TIPS<\/h3>\n<p>You can easily set values for msg.payload.data in your flows using function, change, and set nodes (among others). Another way, pointed out by <a href=\"https:\/\/community.home-assistant.io\/t\/node-red-experiences\/36923\/19?u=oakbrad\" target=\"_blank\" rel=\"noopener\">a very helpful poster<\/a> on the Hass forums, is to use a\u00a0template node set to output JSON.<\/p>\n<div id=\"attachment_401\" style=\"width: 511px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-401\" data-attachment-id=\"401\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/screen-shot-2018-01-19-at-12-39-49-pm\/\" data-orig-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-19-at-12.39.49-PM.png?fit=501%2C580&amp;ssl=1\" data-orig-size=\"501,580\" 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=\"Using a Template Node\" data-image-description=\"&lt;p&gt;Using a Template Node&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Using a Template Node&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-19-at-12.39.49-PM.png?fit=259%2C300&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-19-at-12.39.49-PM.png?fit=501%2C580&amp;ssl=1\" loading=\"lazy\" class=\"size-full wp-image-401\" src=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-19-at-12.39.49-PM.png?resize=501%2C580\" alt=\"Using a Template Node\" width=\"501\" height=\"580\" srcset=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-19-at-12.39.49-PM.png?w=501&amp;ssl=1 501w, https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-19-at-12.39.49-PM.png?resize=259%2C300&amp;ssl=1 259w\" sizes=\"(max-width: 501px) 100vw, 501px\" data-recalc-dims=\"1\" \/><p id=\"caption-attachment-401\" class=\"wp-caption-text\">Using a Template Node<\/p><\/div>\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 = \"onkyo tx\";\namzn_assoc_default_category = \"Electronics\";\namzn_assoc_linkid = \"56be2f14439da0d27feb71eed1ee9093\";\namzn_assoc_default_browse_node = \"172282\";\namzn_assoc_design = \"in_content\";\n<\/script><br \/>\n<script src=\"\/\/z-na.amazon-adsystem.com\/widgets\/onejs?MarketPlace=US\"><\/script><\/p>\n<h2>EXAMPLE: MORNING RADIO FADE IN<\/h2>\n<div id=\"attachment_383\" style=\"width: 1013px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-383\" data-attachment-id=\"383\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/screen-shot-2018-01-18-at-2-04-27-pm\/\" data-orig-file=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?fit=1003%2C410&amp;ssl=1\" data-orig-size=\"1003,410\" 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=\"Morning Radio\" data-image-description=\"&lt;p&gt;Morning Radio&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Morning Radio&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?fit=300%2C123&amp;ssl=1\" data-large-file=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?fit=854%2C349&amp;ssl=1\" loading=\"lazy\" class=\"size-full wp-image-383\" src=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?resize=854%2C349\" alt=\"Morning Radio\" width=\"854\" height=\"349\" srcset=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?w=1003&amp;ssl=1 1003w, https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?resize=600%2C245&amp;ssl=1 600w, https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?resize=300%2C123&amp;ssl=1 300w, https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?resize=768%2C314&amp;ssl=1 768w\" sizes=\"(max-width: 854px) 100vw, 854px\" data-recalc-dims=\"1\" \/><p id=\"caption-attachment-383\" class=\"wp-caption-text\">Morning Radio<\/p><\/div>\n<p>As part of my alarm clock sequence, I want to gradually fade in the volume of the local public radio station so I can wake up to the morning news and traffic. I have an inexpensive <a href=\"http:\/\/amzn.to\/2B76a9n\">Onkyo TX<\/a>\u00a0stereo receiver that integrates really well with Home Assistant.<\/p>\n<p>This flow turns on the receiver, which requires some delays for it to power up and connect to the network before it will accept commands. Once it&#8217;s online, it begins a simple loop using the <a href=\"https:\/\/flows.nodered.org\/node\/node-red-contrib-looptimer\" target=\"_blank\" rel=\"noopener\">looptimer<\/a>\u00a0node.<\/p>\n<h3>THE LOOP<\/h3>\n<div id=\"attachment_390\" style=\"width: 731px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-390\" data-attachment-id=\"390\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/screen-shot-2018-01-18-at-2-53-59-pm\/\" data-orig-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.53.59-PM.png?fit=721%2C200&amp;ssl=1\" data-orig-size=\"721,200\" 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=\"Simple Node-Red Loop\" data-image-description=\"&lt;p&gt;Simple Node-Red Loop&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Simple Node-Red Loop&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.53.59-PM.png?fit=300%2C83&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.53.59-PM.png?fit=721%2C200&amp;ssl=1\" loading=\"lazy\" class=\"size-full wp-image-390\" src=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.53.59-PM.png?resize=721%2C200\" alt=\"Simple Node-Red Loop\" width=\"721\" height=\"200\" srcset=\"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.53.59-PM.png?w=721&amp;ssl=1 721w, https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.53.59-PM.png?resize=600%2C166&amp;ssl=1 600w, https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.53.59-PM.png?resize=300%2C83&amp;ssl=1 300w\" sizes=\"(max-width: 721px) 100vw, 721px\" data-recalc-dims=\"1\" \/><p id=\"caption-attachment-390\" class=\"wp-caption-text\">Simple Node-Red Loop<\/p><\/div>\n<p>Once started, the loop runs every 25 seconds. It gets the current stereo volume, adds 5 points to that value with a <strong>function<\/strong> node, and sends that new volume as a data override to the service call output.<\/p>\n<p>Function nodes use javascript (if you prefer Python, there&#8217;s <a href=\"https:\/\/flows.nodered.org\/node\/node-red-contrib-python3-function\" target=\"_blank\" rel=\"noopener\">a node for that<\/a>). Again, take careful note of the data types. The <strong>msg.payload\u00a0<\/strong>in this case comes in as a <em>string<\/em>, in order to perform math on it I had to convert it to a <em>float<\/em>. I then returned the new volume as a data object in the payload.<\/p>\n<pre>newmsg = Object();\r\n\r\nold_vol = parseFloat(msg.payload);\r\nnew_vol = old_vol + 0.05;\r\n\r\nnewmsg.payload = { data: { 'entity_id': 'media_player.stereo','volume_level': new_vol } };\r\nreturn newmsg;<\/pre>\n<p>Now, I could just set the upper maximums on the looptimer node to quit when it&#8217;s reached the level I want. I&#8217;m going to make this more complicated than necessary though because I can.<\/p>\n<h3>STOP THE LOOP WITH A THRESHOLD<\/h3>\n<p>Another useful logic node is the <a href=\"https:\/\/flows.nodered.org\/node\/node-red-contrib-traffic\" target=\"_blank\" rel=\"noopener\">traffic light<\/a>. It can be turned red or green, and accordingly will either drop or forward the messages through based on it&#8217;s state. In order for this to make sense, read the documentation on both the traffic light and the looptimer to see how these nodes are controlled via messages.<\/p>\n<div id=\"attachment_389\" style=\"width: 718px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-389\" data-attachment-id=\"389\" data-permalink=\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/screen-shot-2018-01-18-at-2-52-19-pm\/\" data-orig-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.52.19-PM.png?fit=708%2C257&amp;ssl=1\" data-orig-size=\"708,257\" 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=\"Loop Threshold\" data-image-description=\"&lt;p&gt;Loop Threshold&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Loop Threshold&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.52.19-PM.png?fit=300%2C109&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.52.19-PM.png?fit=708%2C257&amp;ssl=1\" loading=\"lazy\" class=\"size-full wp-image-389\" src=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.52.19-PM.png?resize=708%2C257\" alt=\"Loop Threshold\" width=\"708\" height=\"257\" srcset=\"https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.52.19-PM.png?w=708&amp;ssl=1 708w, https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.52.19-PM.png?resize=600%2C218&amp;ssl=1 600w, https:\/\/i0.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.52.19-PM.png?resize=300%2C109&amp;ssl=1 300w\" sizes=\"(max-width: 708px) 100vw, 708px\" data-recalc-dims=\"1\" \/><p id=\"caption-attachment-389\" class=\"wp-caption-text\">Loop Threshold<\/p><\/div>\n<p>In my example, the traffic light is turned to\u00a0<strong>GREEN<\/strong> (messages allowed through) when the loop starts. The volume of the stereo is monitored with a state change node through another function &#8211; if above 45, send a <strong>STOP\u00a0<\/strong>message to the traffic light. Because the light is <strong>GREEN<\/strong>, the <strong>STOP<\/strong> message is forwarded to the looptimer node, which is the signal to turn itself off. On completion of the loop, the looptimer outputs a <strong>stopped\u00a0<\/strong>message through it&#8217;s second output, which goes back to the traffic light and switches the traffic light to\u00a0<strong>RED<\/strong>, blocking future volume changes from activating the loop again.<\/p>\n<p>I thought it was kind of interesting that these two nodes, which effectively cancel each other out, visually form an &#8220;X&#8221; with their wires.<\/p>\n<h3>THE JSON<\/h3>\n<p>Copy this to import the whole flow into Node-Red:<\/p>\n<pre>[{\"id\":\"ec1c1cc0.89f0a\",\"type\":\"link in\",\"z\":\"20e65bf6.292fb4\",\"name\":\"\",\"links\":[\"829f9430.fc3088\",\"b73a76c2.703498\"],\"x\":60.00002670288086,\"y\":1669.9999589920044,\"wires\":[[\"fee08205.45787\"]]},{\"id\":\"41b5a4e4.9cae8c\",\"type\":\"comment\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Fade in NPR with Alarm\",\"info\":\"\",\"x\":143.33335494995117,\"y\":1623.3333101272583,\"wires\":[]},{\"id\":\"d844d3fa.5a26d\",\"type\":\"switch\",\"z\":\"20e65bf6.292fb4\",\"name\":\"\",\"property\":\"payload\",\"propertyType\":\"msg\",\"rules\":[{\"t\":\"eq\",\"v\":\"on\",\"vt\":\"str\"}],\"checkall\":\"true\",\"outputs\":1,\"x\":335.66672134399414,\"y\":1923.3331894874573,\"wires\":[[\"99146127.9daf4\",\"6b99dd1f.172194\"]]},{\"id\":\"1b9b043f.e39a8c\",\"type\":\"server-state-changed\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Stereo Volume\",\"server\":\"8ac3cd7f.58d3e\",\"entityidfilter\":\"sensor.stereo_volume\",\"haltifstate\":\"\",\"x\":194.66672134399414,\"y\":2010.3331894874573,\"wires\":[[\"350a9df1.760542\"]]},{\"id\":\"350a9df1.760542\",\"type\":\"function\",\"z\":\"20e65bf6.292fb4\",\"name\":\"&gt; 45?\",\"func\":\"newmsg = Object();\\nif (msg.payload &gt; 0.44) {\\n newmsg.payload = \\\"STOP\\\";\\n} else {\\n newmsg.payload = \\\"Not Yet\\\";\\n}\\nreturn newmsg;\",\"outputs\":1,\"noerr\":0,\"x\":195.66672134399414,\"y\":2063.3331894874573,\"wires\":[[\"49e87859.3c9e68\"]]},{\"id\":\"49e87859.3c9e68\",\"type\":\"switch\",\"z\":\"20e65bf6.292fb4\",\"name\":\"\",\"property\":\"payload\",\"propertyType\":\"msg\",\"rules\":[{\"t\":\"eq\",\"v\":\"STOP\",\"vt\":\"str\"}],\"checkall\":\"true\",\"outputs\":1,\"x\":335.66672134399414,\"y\":2063.3331894874573,\"wires\":[[\"6b99dd1f.172194\"]]},{\"id\":\"7d6b19a8.1c3058\",\"type\":\"switch\",\"z\":\"20e65bf6.292fb4\",\"name\":\"\",\"property\":\"payload\",\"propertyType\":\"msg\",\"rules\":[{\"t\":\"eq\",\"v\":\"STOP\",\"vt\":\"str\"}],\"checkall\":\"true\",\"outputs\":1,\"x\":546.6667404174805,\"y\":1984.6664643287659,\"wires\":[[\"99146127.9daf4\"]]},{\"id\":\"99146127.9daf4\",\"type\":\"looptimer\",\"z\":\"20e65bf6.292fb4\",\"duration\":\"25\",\"units\":\"Second\",\"maxloops\":\"15\",\"maxtimeout\":\"10\",\"maxtimeoutunits\":\"Minute\",\"name\":\"Turn Up Volume\",\"x\":732.3333702087402,\"y\":1922.3331718444824,\"wires\":[[\"3632c93f.a0b866\"],[\"6b99dd1f.172194\"]]},{\"id\":\"6b99dd1f.172194\",\"type\":\"traffic\",\"z\":\"20e65bf6.292fb4\",\"name\":\"\",\"property_allow\":\"payload\",\"filter_allow\":\"on\",\"ignore_case_allow\":false,\"negate_allow\":false,\"send_allow\":false,\"property_stop\":\"payload\",\"filter_stop\":\"stopped\",\"ignore_case_stop\":false,\"negate_stop\":false,\"send_stop\":false,\"default_start\":false,\"differ\":false,\"x\":555.6667442321777,\"y\":2062.3332085609436,\"wires\":[[\"7d6b19a8.1c3058\"]]},{\"id\":\"325e1bca.fc58d4\",\"type\":\"comment\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Loop\",\"info\":\"\",\"x\":960.0000610351562,\"y\":1931.3332405090332,\"wires\":[]},{\"id\":\"3632c93f.a0b866\",\"type\":\"api-current-state\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Stereo Volume\",\"server\":\"8ac3cd7f.58d3e\",\"halt_if\":\"\",\"entity_id\":\"sensor.stereo_volume\",\"x\":990.5000495910645,\"y\":1973.3332934379578,\"wires\":[[\"1aeb6c59.1a9474\"]]},{\"id\":\"1aeb6c59.1a9474\",\"type\":\"function\",\"z\":\"20e65bf6.292fb4\",\"name\":\"+5 Volume\",\"func\":\"newmsg = Object();\\n\\nold_vol = parseFloat(msg.payload);\\nnew_vol = old_vol + 0.05;\\n\\nnewmsg.payload = { data: { 'entity_id': 'media_player.stereo','volume_level': new_vol } }\\n\\nreturn newmsg;\",\"outputs\":1,\"noerr\":0,\"x\":998.0000076293945,\"y\":2019.9999270439148,\"wires\":[[\"d001ed10.c8e12\"]]},{\"id\":\"d001ed10.c8e12\",\"type\":\"api-call-service\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Turn Up Volume\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"media_player\",\"service\":\"volume_set\",\"data\":\"{\\\"entity_id\\\":\\\"media_player.stereo\\\"}\",\"x\":1199.1666679382324,\"y\":2020.3333044052124,\"wires\":[]},{\"id\":\"99e3766f.1769d8\",\"type\":\"api-current-state\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Receiver On?\",\"server\":\"8ac3cd7f.58d3e\",\"halt_if\":\"\",\"entity_id\":\"switch.dualplug_right\",\"x\":181.3333854675293,\"y\":1729.9999380111694,\"wires\":[[\"ee90183e.999a08\"]]},{\"id\":\"ee90183e.999a08\",\"type\":\"switch\",\"z\":\"20e65bf6.292fb4\",\"name\":\"\",\"property\":\"payload\",\"propertyType\":\"msg\",\"rules\":[{\"t\":\"eq\",\"v\":\"on\",\"vt\":\"str\"},{\"t\":\"eq\",\"v\":\"off\",\"vt\":\"str\"}],\"checkall\":\"true\",\"outputs\":2,\"x\":344.3333854675293,\"y\":1729.9999380111694,\"wires\":[[\"84655780.58a0f8\"],[\"4caef560.20d36c\",\"84655780.58a0f8\"]]},{\"id\":\"4caef560.20d36c\",\"type\":\"api-call-service\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Turn On Receiver\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"switch\",\"service\":\"turn_on\",\"data\":\"{\\\"entity_id\\\":\\\"switch.dualplug_right\\\"}\",\"x\":760.3333854675293,\"y\":1733.9999380111694,\"wires\":[]},{\"id\":\"84655780.58a0f8\",\"type\":\"delay\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Let it Turn On - 50s\",\"pauseType\":\"delay\",\"timeout\":\"50\",\"timeoutUnits\":\"seconds\",\"rate\":\"1\",\"nbRateUnits\":\"1\",\"rateUnits\":\"second\",\"randomFirst\":\"1\",\"randomLast\":\"5\",\"randomUnits\":\"seconds\",\"drop\":false,\"x\":286.8333854675293,\"y\":1783.9999589920044,\"wires\":[[\"813154b7.868cc8\",\"6d45ef3c.29bba\"]]},{\"id\":\"813154b7.868cc8\",\"type\":\"api-call-service\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Set Volume to 0\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"media_player\",\"service\":\"volume_set\",\"data\":\"{\\\"entity_id\\\":\\\"media_player.stereo\\\",\\\"volume_level\\\":\\\"0.10\\\"}\",\"x\":750.3333854675293,\"y\":1783.9999380111694,\"wires\":[]},{\"id\":\"e42b6f68.f7683\",\"type\":\"api-call-service\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Switch Receiver to FM\",\"server\":\"8ac3cd7f.58d3e\",\"service_domain\":\"media_player\",\"service\":\"select_source\",\"data\":\"{\\\"entity_id\\\":\\\"media_player.stereo\\\",\\\"source\\\":\\\"fm\\\"}\",\"x\":771.3333854675293,\"y\":1832.9999380111694,\"wires\":[]},{\"id\":\"585bee5f.37de9\",\"type\":\"change\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Turn On Loop\",\"rules\":[{\"t\":\"set\",\"p\":\"payload\",\"pt\":\"msg\",\"to\":\"on\",\"tot\":\"str\"}],\"action\":\"\",\"property\":\"\",\"from\":\"\",\"to\":\"\",\"reg\":false,\"x\":304.58337783813477,\"y\":1875.8332796096802,\"wires\":[[\"d844d3fa.5a26d\"]]},{\"id\":\"6d45ef3c.29bba\",\"type\":\"delay\",\"z\":\"20e65bf6.292fb4\",\"name\":\"\",\"pauseType\":\"delay\",\"timeout\":\"50\",\"timeoutUnits\":\"seconds\",\"rate\":\"1\",\"nbRateUnits\":\"1\",\"rateUnits\":\"second\",\"randomFirst\":\"1\",\"randomLast\":\"5\",\"randomUnits\":\"seconds\",\"drop\":false,\"x\":515.8333854675292,\"y\":1824.9999380111692,\"wires\":[[\"e42b6f68.f7683\",\"585bee5f.37de9\"]]},{\"id\":\"fee08205.45787\",\"type\":\"api-current-state\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Want Music?\",\"server\":\"8ac3cd7f.58d3e\",\"halt_if\":\"off\",\"entity_id\":\"input_boolean.alarmradio\",\"x\":168.1667137145996,\"y\":1670.6666860580444,\"wires\":[[\"99e3766f.1769d8\"]]},{\"id\":\"21f780ba.d339d\",\"type\":\"comment\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Turn On Receiver &amp; Prep it\",\"info\":\"\",\"x\":776.6666679382324,\"y\":1679.999924659729,\"wires\":[]},{\"id\":\"b0732620.9a2ae8\",\"type\":\"comment\",\"z\":\"20e65bf6.292fb4\",\"name\":\"Volume Threshold\",\"info\":\"\",\"x\":201.66669845581055,\"y\":1968.333176612854,\"wires\":[]},{\"id\":\"8ac3cd7f.58d3e\",\"type\":\"server\",\"z\":\"\",\"name\":\"Home Assistant\",\"url\":\"http:\/\/localhost:8123\",\"pass\":\"YOURPASS\"}]<\/pre>\n<h2>CONCLUSION<\/h2>\n<p>Hopefully by now, you can start to see the power of using Node-Red for your Home Assistant automations. With an understanding of how the message is handled and how to dynamically interact with Home Assistant almost anything is possible.<\/p>\n<p>I have only used a few nodes here, there are many, many more &#8211; each of which can be added to your flows to greatly expand the possibilities. Take a look through <a href=\"https:\/\/flows.nodered.org\/\" target=\"_blank\" rel=\"noopener\">Node Red&#8217;s library<\/a>\u00a0to see a list of community contributed nodes.<\/p>\n<p>If you&#8217;ve found any novel nodes or made cool things with them, please post in the comments below!<\/p>\n<h3>RESOURCES<\/h3>\n<ul>\n<li><a href=\"https:\/\/flows.nodered.org\/\">Node-Red Library<\/a><\/li>\n<li><a href=\"https:\/\/www.w3schools.com\/js\/js_datatypes.asp\" target=\"_blank\" rel=\"noopener\">Javascript Data Types<\/a><\/li>\n<li>My list of <a href=\"http:\/\/diyfuturism.com\/index.php\/2017\/11\/26\/big-list-of-home-automation-nodes-for-node-red\/\">Useful Home Automation Nodes<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/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 = \"56be2f14439da0d27feb71eed1ee9093\";\namzn_assoc_default_browse_node = \"172282\";\namzn_assoc_design = \"in_content\";\n<\/script><br \/>\n<script src=\"\/\/z-na.amazon-adsystem.com\/widgets\/onejs?MarketPlace=US\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"wpm_excerpt clearfix\"><p>In my last post\u00a0about using Node-Red to make automations with Home Assistant, I showed some very simple flows for turning lights on and off. While it &hellip;<\/p>\n<\/div>","protected":false},"author":1,"featured_media":383,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"#HowTo Make Advanced Home Automations in @NodeRed w\/ @Home_Assistant Dynamic service calls & an Alarm Clock Radio #smarthome #nodered #hass","jetpack_is_tweetstorm":false},"categories":[7,11,3],"tags":[47,43,55,36,31,54,32,30,126,42,48,25,127],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Going Further with Home Automations in Node-Red - DIY Futurism<\/title>\n<meta name=\"description\" content=\"Making dynamic home automations with Home Assistant, Node-Red, and some advanced logic nodes. Example of using a loop to gradually increase alarm clock stereo volume until a threshold is reached.\" \/>\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\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Going Further with Home Automations in Node-Red - DIY Futurism\" \/>\n<meta property=\"og:description\" content=\"Making dynamic home automations with Home Assistant, Node-Red, and some advanced logic nodes. Example of using a loop to gradually increase alarm clock stereo volume until a threshold is reached.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/\" \/>\n<meta property=\"og:site_name\" content=\"DIY Futurism\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-18T23:23:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-19T20:42:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?fit=1003%2C410&#038;ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1003\" \/>\n\t<meta property=\"og:image:height\" content=\"410\" \/>\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=\"11 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\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?fit=1003%2C410&ssl=1\",\"contentUrl\":\"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?fit=1003%2C410&ssl=1\",\"width\":1003,\"height\":410,\"caption\":\"Morning Radio\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/#webpage\",\"url\":\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/\",\"name\":\"Going Further with Home Automations in Node-Red - DIY Futurism\",\"isPartOf\":{\"@id\":\"https:\/\/diyfuturism.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/#primaryimage\"},\"datePublished\":\"2018-01-18T23:23:56+00:00\",\"dateModified\":\"2018-01-19T20:42:14+00:00\",\"author\":{\"@id\":\"https:\/\/diyfuturism.com\/#\/schema\/person\/b93619fac07567640bd87cc613a55b7c\"},\"description\":\"Making dynamic home automations with Home Assistant, Node-Red, and some advanced logic nodes. Example of using a loop to gradually increase alarm clock stereo volume until a threshold is reached.\",\"breadcrumb\":{\"@id\":\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/diyfuturism.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Going Further with Home Automations in Node-Red\"}]},{\"@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":"Going Further with Home Automations in Node-Red - DIY Futurism","description":"Making dynamic home automations with Home Assistant, Node-Red, and some advanced logic nodes. Example of using a loop to gradually increase alarm clock stereo volume until a threshold is reached.","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\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/","og_locale":"en_US","og_type":"article","og_title":"Going Further with Home Automations in Node-Red - DIY Futurism","og_description":"Making dynamic home automations with Home Assistant, Node-Red, and some advanced logic nodes. Example of using a loop to gradually increase alarm clock stereo volume until a threshold is reached.","og_url":"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/","og_site_name":"DIY Futurism","article_published_time":"2018-01-18T23:23:56+00:00","article_modified_time":"2018-01-19T20:42:14+00:00","og_image":[{"width":1003,"height":410,"url":"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?fit=1003%2C410&ssl=1","path":"\/var\/www\/html\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png","size":"full","id":383,"alt":"Morning Radio","pixels":411230,"type":"image\/png"}],"twitter_card":"summary_large_image","twitter_creator":"@diyfuturism","twitter_site":"@diyfuturism","twitter_misc":{"Written by":"brad","Est. reading time":"11 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\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/#primaryimage","inLanguage":"en-US","url":"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?fit=1003%2C410&ssl=1","contentUrl":"https:\/\/i1.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?fit=1003%2C410&ssl=1","width":1003,"height":410,"caption":"Morning Radio"},{"@type":"WebPage","@id":"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/#webpage","url":"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/","name":"Going Further with Home Automations in Node-Red - DIY Futurism","isPartOf":{"@id":"https:\/\/diyfuturism.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/#primaryimage"},"datePublished":"2018-01-18T23:23:56+00:00","dateModified":"2018-01-19T20:42:14+00:00","author":{"@id":"https:\/\/diyfuturism.com\/#\/schema\/person\/b93619fac07567640bd87cc613a55b7c"},"description":"Making dynamic home automations with Home Assistant, Node-Red, and some advanced logic nodes. Example of using a loop to gradually increase alarm clock stereo volume until a threshold is reached.","breadcrumb":{"@id":"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/diyfuturism.com\/index.php\/2018\/01\/18\/going-further-with-home-automations-in-node-red\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/diyfuturism.com\/"},{"@type":"ListItem","position":2,"name":"Going Further with Home Automations in Node-Red"}]},{"@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\/2018\/01\/Screen-Shot-2018-01-18-at-2.04.27-PM.png?fit=1003%2C410&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9q0Cl-62","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":374,"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":374,"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":410,"url":"https:\/\/diyfuturism.com\/index.php\/2018\/01\/23\/nodes-home-automation-state-machine-actionflows-dashboard-statistics\/","url_meta":{"origin":374,"position":2},"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":191,"url":"https:\/\/diyfuturism.com\/index.php\/2017\/12\/14\/basic-node-red-flows-for-automating-lighting-with-home-assistant\/","url_meta":{"origin":374,"position":3},"title":"Basic Node-Red Flows for Automating Lighting with Home Assistant","date":"December 14, 2017","format":false,"excerpt":"Smart light bulbs are probably the first thing everyone getting into home automation buys. It is easy to see the applications for them - have the lights come on at night, turn off when you're home, etc. It's very satisfying to have the lights react to the day and your\u2026","rel":"","context":"In &quot;Config&quot;","img":{"alt_text":"","src":"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&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":374,"position":4},"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":417,"url":"https:\/\/diyfuturism.com\/index.php\/2018\/01\/31\/setting-up-lets-encrypt-with-node-red-home-assistant\/","url_meta":{"origin":374,"position":5},"title":"Setting Up Let&#8217;s Encrypt with Node-Red &#038; Home Assistant","date":"January 31, 2018","format":false,"excerpt":"Privacy is important in the smart home, and one of the primary reasons to use Home Assistant is because it is totally under control of the user, on your own network. Since writing these posts, setting up encryption with Hass & Node-Red has been the number one question I've been\u2026","rel":"","context":"In &quot;Config&quot;","img":{"alt_text":"Let's Encrypt","src":"https:\/\/i2.wp.com\/diyfuturism.com\/wp-content\/uploads\/2018\/01\/images.duckduckgo.png?fit=800%2C400&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/posts\/374"}],"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=374"}],"version-history":[{"count":13,"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/posts\/374\/revisions"}],"predecessor-version":[{"id":402,"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/posts\/374\/revisions\/402"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/media\/383"}],"wp:attachment":[{"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/media?parent=374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/categories?post=374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diyfuturism.com\/index.php\/wp-json\/wp\/v2\/tags?post=374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}