<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>node-red &#8211; Squix &#8211; TechBlog</title>
	<atom:link href="https://blog.squix.org/tag/node-red/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.squix.org</link>
	<description></description>
	<lastBuildDate>Wed, 14 Jul 2021 20:30:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.8</generator>
<site xmlns="com-wordpress:feed-additions:1">121913304</site>	<item>
		<title>Alexa-Home, Node-Red and Docker</title>
		<link>https://blog.squix.org/2021/07/alexa-home-node-red-and-docker.html</link>
					<comments>https://blog.squix.org/2021/07/alexa-home-node-red-and-docker.html#respond</comments>
		
		<dc:creator><![CDATA[Daniel Eichhorn]]></dc:creator>
		<pubDate>Wed, 14 Jul 2021 20:29:58 +0000</pubDate>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[IoT Products]]></category>
		<category><![CDATA[alexa]]></category>
		<category><![CDATA[home-automation]]></category>
		<category><![CDATA[node-red]]></category>
		<guid isPermaLink="false">https://blog.squix.org/?p=6841</guid>

					<description><![CDATA[How do you add new virtual devices/commands in Node-Red so that Alexa can control them? There are great Node-Red extensions but things get more complicated if Node-Red is running in a docker container. In this blog post I share my take-aways from setting this up. ... <p><a class="read-more btn btn-secondary" href="https://blog.squix.org/2021/07/alexa-home-node-red-and-docker.html">Read More</a></p>]]></description>
										<content:encoded><![CDATA[
<p>How do you add new virtual devices/commands in Node-Red so that Alexa can control them? There are great Node-Red extensions but things get more complicated if Node-Red is running in a docker container. In this blog post I share my take-aways from setting this up.</p>



<span id="more-6841"></span>



<p>Voice assistants and smart home applications go together really well. For several years now we have an Echo Dot with Alexa running at home and I have connected more and more devices to it. Another important factor in my smart home setup is a Node-Red instance running in a docker container on a RaspberryPi 4. </p>



<h2 class="wp-block-heading">Why Running Node-Red in Docker?</h2>



<p>I probably could save myself some trouble if I would just install Node-Red as regular service on the base system on my Raspberry Pi. Especially where Node-Red needs direct access to RPi hardware resources. It took me quite some time to figure out how I can use the RPi Bluetooth device from within the docker container. In a nutshell: you have to use <em>network_mode: host</em> to share the BLE hardware between host and container.</p>



<p>But I believe that the benefits of running such applications like Node-Red in a docker container outweigh the trouble. Updating or trying out different configurations is super easy. And all the resources are cleanly separated from other containers running on the same machine.</p>



<h2 class="wp-block-heading">The Alexa-Home Node</h2>



<p>I have a couple of Tasmota powered Shelly devices, allowing me to control lights either with a regular light switch over WiFi. You can set up Tasmota devices to be discoverable by Alexa. Then with a simple &#8220;Alexa, turn on the corridor&#8221; you can control the lights in your corridor. But what if you want to make a new command accessible to Alexa that is not represented by a physical device?</p>



<p>This is where the Alexa-Home node comes in. The official name is <a href="https://flows.nodered.org/node/node-red-contrib-alexa-home">node-red-contrib-alexa-home</a> and this extension comes with two nodes: a controller and a device node. The controller lets you do some basic settings like the network port used for discovery while the device node lets you setup a virtual device.</p>



<p>So for instance I created a node called &#8220;Everything&#8221; and now I can turn off all lights by calling &#8220;Alexa, turn off Everything&#8221;. Nice, eh? But sadly this didn&#8217;t work right away. Once more I suspected the docker setup and I was correct.</p>



<h2 class="wp-block-heading">The Solution</h2>



<p>No matter what I tried, the virtual devices from Node-Red did not show up in Alexa&#8217;s device list. So I assumed some kind of networking issue. According to this <a href="https://github.com/vintlabs/fauxmoESP">github project</a> the device needs to listen on a certain port, for generation 3 devices this has to be port 80. Alexa must be able to download the file /alexa-home/setup.xml from the RPi. This file contains the device description.</p>



<p>That means we have to make sure that a request to the RPi is forwarded to our Node-Red container. Now the next steps depends on your setup. I&#8217;m running Node-Red together with MQTT from a docker-compose command. And as mentioned earlier this setup is using &#8220;network_mode: host&#8221;:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Setting <strong>network_mode</strong> to <strong>host</strong> allows the container to share the same network namespace as the <strong>host</strong> OS. When this is set, any ports exposed on the container will be exposed locally on the device. This is necessary for features such as bluetooth.</p><cite>Source: <a href="https://www.balena.io/docs/learn/develop/multicontainer/" target="_blank" rel="noreferrer noopener">https://www.balena.io/docs/learn/develop/multicontainer/</a></cite></blockquote>



<p>This means that I cannot do port mapping in the docker-compose file because host-mode together with port-mapping is not allowed. That means that the port which uses Alexa-Home to publish it&#8217;s setup.xml must be exposed from the Dockerfile. </p>



<p>I set my Alexa-Home controller node to port 80:</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="480" height="212" data-attachment-id="6849" data-permalink="https://blog.squix.org/2021/07/alexa-home-node-red-and-docker.html/image-7-4" data-orig-file="https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-7.png?fit=480%2C212&amp;ssl=1" data-orig-size="480,212" 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="image-7" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-7.png?fit=300%2C133&amp;ssl=1" data-large-file="https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-7.png?fit=480%2C212&amp;ssl=1" src="https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-7.png?resize=480%2C212&#038;ssl=1" alt="" class="wp-image-6849" srcset="https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-7.png?w=480&amp;ssl=1 480w, https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-7.png?resize=300%2C133&amp;ssl=1 300w" sizes="(max-width: 480px) 100vw, 480px" /><figcaption>Alexa Home Controller Node, set to port 80</figcaption></figure>



<p>And in the Dockerfile I added</p>



<pre class="wp-block-code"><code>EXPOSE 80</code></pre>



<p>And that&#8217;s it! Rebuild the docker container and restart both containers with docker-compose. Now add an Alexa-Home node in your Node-Red web interface and set the device name in the node configuration. This is the name you will use to give commands for that virtual device. Then tell Alexa to &#8220;Discover devices&#8221;. After about 20 seconds she will tell you that she discovered your new device.</p>



<p>Now you can create nodes just like this one:</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" decoding="async" width="730" height="443" data-attachment-id="6852" data-permalink="https://blog.squix.org/2021/07/alexa-home-node-red-and-docker.html/image-8-4" data-orig-file="https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-8.png?fit=1802%2C1094&amp;ssl=1" data-orig-size="1802,1094" 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="image-8" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-8.png?fit=300%2C182&amp;ssl=1" data-large-file="https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-8.png?fit=730%2C443&amp;ssl=1" src="https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-8.png?resize=730%2C443&#038;ssl=1" alt="" class="wp-image-6852" srcset="https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-8.png?resize=1024%2C622&amp;ssl=1 1024w, https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-8.png?resize=300%2C182&amp;ssl=1 300w, https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-8.png?resize=768%2C466&amp;ssl=1 768w, https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-8.png?resize=1536%2C933&amp;ssl=1 1536w, https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-8.png?w=1802&amp;ssl=1 1802w, https://i0.wp.com/blog.squix.org/wp-content/uploads/2021/07/image-8.png?w=1460&amp;ssl=1 1460w" sizes="(max-width: 730px) 100vw, 730px" /><figcaption>The &#8220;Everything&#8221; node allows you to tell &#8220;Alexa, turn off everything&#8221;</figcaption></figure>



<h2 class="wp-block-heading">Summary</h2>



<p>Alexa and Node-Red can be a powerful team. You can create powerful commands in Node-Red which Alexa can understand. While you are limited to simple commands like &#8220;Turn On XXX&#8221; or &#8220;Dim XXX to 50%&#8221; you can get a long way with this. </p>



<p>Running Node-Red in a container is a powerful thing and has many benefits. But it also complicates things every once in a while. And connecting Alexa and Node-Red over the device discovery is such a thing. But if you are in this situation you&#8217;ll hopefully find this blog post and have it up and running in no time!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.squix.org/2021/07/alexa-home-node-red-and-docker.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">6841</post-id>	</item>
	</channel>
</rss>
