<?xml version="1.0" encoding="utf-8" standalone="yes"?><?xml-stylesheet href="/rss.xsl" type="text/xsl" ?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Domoticz | Bacardi55&#39;s Web Cave</title>
    <link>https://bacardi55.io/tags/domoticz/</link>
    <description>Recent content in Domoticz on Bacardi55&#39;s Web Cave</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <managingEditor>bac@rdi55.pl (bacardi55)</managingEditor>
    <webMaster>bac@rdi55.pl (bacardi55)</webMaster>
    <copyright>2010-2025 bacardi55</copyright>
    <lastBuildDate>Tue, 23 Mar 2021 00:00:00 +0100</lastBuildDate>
    <atom:link href="https://bacardi55.io/tags/domoticz/index.xml" rel="self" type="application/rss+xml" />
    <item>
      
      <title>Home Automation, part 8: Entry door detection with Motion and NodeRed</title><link>https://bacardi55.io/2021/03/23/home-automation-part-8-entry-door-detection-with-motion-and-nodered/</link><pubDate>Tue, 23 Mar 2021 00:00:00 +0100</pubDate><author>bac@rdi55.pl (bacardi55)</author><guid>https://bacardi55.io/2021/03/23/home-automation-part-8-entry-door-detection-with-motion-and-nodered/</guid><description>&lt;h2 id=&#34;context&#34;&gt;Context&lt;/h2&gt;&#xA;&lt;p&gt;In this post, I&amp;rsquo;ll describe how I use motion, NodeRed, MQTT and Telegram&#xA;to manage everything related to my entry door camera.&lt;/p&gt;&#xA;&lt;p&gt;The TL;DR is: when the camera pointing at the entry door sees some&#xA;movement, it will: - sent a MQTT message right away (that triggers an&#xA;alert on my phone via Telegram); - Start recording video; - Take&#xA;pictures in the meantime. Pictures are scp to another server in the&#xA;house and outside; - Once the video is done (no more movement), it will&#xA;save it on drive and send it to my phone via Telegram - Option: Ability&#xA;to request a snapshot (picture of the entry as of right now) via&#xA;Telegram.&lt;/p&gt;&#xA;&lt;h3 id=&#34;used-devices-software&#34;&gt;Used devices / software&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;A &lt;a href=&#34;https://www.raspberrypi.org/products/raspberry-pi-zero-w/&#34;&gt;raspberry pi 0W&lt;/a&gt; with a&#xA;&lt;a href=&#34;https://www.pishop.us/product/rpi-camera-h-fisheye-lens-supports-night-vision/&#34;&gt;fisheyes picamera&lt;/a&gt;, running &lt;a href=&#34;https://motion-project.github.io/&#34;&gt;motion&lt;/a&gt;,&#xA;named in this blog &amp;ldquo;PiCam&amp;rdquo; for simplicity (named in reality&#xA;&lt;code&gt;nickylarson&lt;/code&gt;);&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://nodered.org/&#34;&gt;NodeRed&lt;/a&gt; and&#xA;&lt;a href=&#34;https://github.com/eclipse/mosquitto&#34;&gt;Mosquitto&lt;/a&gt; installed on my&#xA;&lt;a href=&#34;https://bacardi55.io/pages/home-lab/&#34;&gt;homelab cluster&lt;/a&gt;;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://telegram.org/&#34;&gt;Telegram&lt;/a&gt; on my phone&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;picam-installation&#34;&gt;PiCam Installation&lt;/h2&gt;&#xA;&lt;p&gt;The following are installed not on the homeautomation cluster but on the&#xA;PiCam (aka &lt;code&gt;NickyLarson&lt;/code&gt;).&lt;/p&gt;&#xA;&lt;h3 id=&#34;motion&#34;&gt;Motion&lt;/h3&gt;&#xA;&lt;h4 id=&#34;installation&#34;&gt;Installation&lt;/h4&gt;&#xA;&lt;p&gt;On raspbian/RaspberrypiOS or debian, you can install it as usual:&#xA;&lt;code&gt;sudo apt install motion&lt;/code&gt;&lt;/p&gt;&#xA;&lt;!--list-separator--&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Configuration&lt;/p&gt;&#xA;&lt;p&gt;I let you read the&#xA;&lt;a href=&#34;https://motion-project.github.io/motion_download.html&#34;&gt;motion&#xA;documentation&lt;/a&gt; and you can find my full&#xA;&lt;a href=&#34;https://github.com/bacardi55/scripts55-cleaned/blob/main/nickylarson/motion.conf&#34;&gt;motion.conf&#xA;here&lt;/a&gt;, but the important pieces are:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    daemon on&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Run motion as deamon.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    videodevice /dev/video0&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    v4l2_palette 17&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This works for the pi camera,&#xA;&lt;a href=&#34;https://motion-project.github.io/motion_config.html#basic_setup_picam&#34;&gt;see&#xA;here&lt;/a&gt;, adapt if you are using something else.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    webcontrol_localhost on&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To enable control of motion via http requests from localhost. This is&#xA;needed for the MQTT handler script to request a snapshot (picture of&#xA;&amp;ldquo;right now&amp;rdquo;).&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    target_dir /var/motion/pictures/&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    snapshot_filename %v-%Y%m%d%H%M%S-snapshot&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    picture_filename %v-%Y%m%d%H%M%S-%q&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    movie_filename %v-%Y%m%d%H%M%S&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    timelapse_filename %Y%m%d-timelapse&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To indicates where files are stored and how they are named.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    on_event_start /home/pi/scripts/alert_motion_start.sh&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    on_event_end /home/pi/scripts/alert_motion.sh&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And where the magic happens, indicates the script to run when an event&#xA;starts or ends.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h4 id=&#34;motion-events-scripts&#34;&gt;Motion Events Scripts&lt;/h4&gt;&#xA;&lt;p&gt;As configured above, we need 2 scripts, one for when an event starts and&#xA;one when an event stops.&lt;/p&gt;&#xA;&lt;!--list-separator--&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Alert Starts&lt;/p&gt;&#xA;&lt;p&gt;The &lt;code&gt;alert_motion_start.sh&lt;/code&gt; script looks like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;#!/bin/bash&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;# This script is run after the event starts.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    logfile&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;/tmp/alert.log&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    date&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;date&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$date&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Motion event started&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;# Get home mode.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Starting alert&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mode&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;curl -s -X GET http://&amp;lt;IPOfNodeRed&amp;gt;:&amp;lt;PortOfNodeRed&amp;gt;/api/home/mode | jq -r &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;.house_mode&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;current house mode: &lt;/span&gt;$mode&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; -z &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$mode&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        mode&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;empty&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;# If mode is not manual or full, raise an alert&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$mode&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; !&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;full&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$mode&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; !&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Manual&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        mosquitto_pub -h &amp;lt;MosquittoServerIP&amp;gt; -p &amp;lt;MosquittoPort&amp;gt; -t home/entry/motion -m &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt; -q &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or the latest version always&#xA;&lt;a href=&#34;https://github.com/bacardi55/scripts55-cleaned/blob/main/nickylarson/alert_motion_start.sh&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The 2 main parts are:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mode&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;curl -s -X GET http://&amp;lt;IPOfNodeRed&amp;gt;:&amp;lt;PortOfNodeRed&amp;gt;/api/home/mode | jq -r &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;.house_mode&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This asks NoredRed via http GET request the current house mode. It means&#xA;that NodeRed shoud respond the home mode on this URI. We&amp;rsquo;ll see below&#xA;how this works.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;# If mode is not manual or full, raise an alert&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$mode&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; !&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;full&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$mode&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; !&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Manual&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        mosquitto_pub -h &amp;lt;MosquittoServerIP&amp;gt; -p &amp;lt;MosquittoPort&amp;gt; -t home/entry/motion -m &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt; -q &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will send an alert via MQTT if the house mode is not full or manual&#xA;(this mode disable everything). It should never be the case anyway as I&#xA;disable the camera and motion when I&amp;rsquo;m home (more below) but before I&#xA;used to have the camera enabled at night.&lt;/p&gt;&#xA;&lt;p&gt;As you have guessed, you will need to install &lt;code&gt;mosquitto-clients&lt;/code&gt; to get&#xA;the &lt;code&gt;mosquitto_pub&lt;/code&gt; command.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;!--list-separator--&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Alert Ends&lt;/p&gt;&#xA;&lt;p&gt;The end script looks like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;#!/bin/bash&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;# This script is run after the event end.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    logfile&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;/tmp/alert.log&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    date&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;date&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$date&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;# Get home mode.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Event end alert&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mode&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;curl -s -X GET http://&amp;lt;IPOfNodeRed&amp;gt;:&amp;lt;PortOfNodeRed&amp;gt;/api/home/mode | jq -r &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;.house_mode&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;current house mode: &lt;/span&gt;$mode&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; -z &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$mode&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        mode&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;empty&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;# If mode is not manual or full, raise an alert&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$mode&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Away&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# Retrieve latest video:&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        file&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;ls -t /var/motion/pictures/*.mp4 | head -1&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        curl -X POST  http://&amp;lt;IPOfNodeRed&amp;gt;:&amp;lt;PortOfNodeRed&amp;gt;/api/home/entry/camera/event/end -F &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;file=@&lt;/span&gt;$file&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &amp;gt; /dev/null 2&amp;gt;&amp;amp;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Latest version on git&#xA;&lt;a href=&#34;https://github.com/bacardi55/scripts55-cleaned/blob/main/nickylarson/alert_motion.sh&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;As for the starts script, the 2 important parts are:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mode&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;curl -s -X GET http://&amp;lt;IPOfNodeRed&amp;gt;:&amp;lt;PortOfNodeRed&amp;gt;/api/home/mode | jq -r &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;.house_mode&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To request current house mode, and:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$mode&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Away&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# Retrieve latest video:&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        file&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;ls -t /var/motion/pictures/*.mp4 | head -1&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        curl -X POST  http://&amp;lt;IPOfNodeRed&amp;gt;:&amp;lt;PortOfNodeRed&amp;gt;/api/home/entry/camera/event/end -F &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;file=@&lt;/span&gt;$file&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &amp;gt; /dev/null 2&amp;gt;&amp;amp;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In this case, I retrieve the latest mp4 file (video captured by motion),&#xA;and send it via HTTP request to NoredRed. I didn&amp;rsquo;t find a better&#xA;solution than an HTTP request to send a file but it works well. We&amp;rsquo;ll&#xA;see below how to configure NodeRed to react accordingly.&lt;/p&gt;&#xA;&lt;p&gt;Make sure that the path, video format and naming match the values in the&#xA;script!&lt;/p&gt;&#xA;&lt;p&gt;You should now be able to start / stop motion with:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;# systemctl {start,stop} motion.service&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now that motion is configured and working, let&amp;rsquo;s see how NodeRed can&#xA;control it via MQTT.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;mqtt-handler&#34;&gt;MQTT handler&lt;/h3&gt;&#xA;&lt;p&gt;In order for NodeRed to controll the PiCam via MQTT, PiCam needs to be&#xA;be able to listen and interact with MQTT. For this, I created a python&#xA;script for all the MQTT interaction. The script is too long to be fully&#xA;copied within a blog post, but you can find it&#xA;&lt;a href=&#34;https://github.com/bacardi55/scripts55-cleaned/blob/main/nickylarson/mqtt-gateway.py&#34;&gt;here&lt;/a&gt;.&#xA;The script will basically:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Subscribe to the right topic (&lt;code&gt;client.subscribe(&amp;quot;home/entry/#&amp;quot;)&lt;/code&gt;) on&#xA;start;&lt;/li&gt;&#xA;&lt;li&gt;listen to message for 2 topics:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;home/entry/snapshot&lt;/code&gt;: In case I request via telegram a picture of&#xA;&amp;ldquo;right now&amp;rdquo; Use requests to send the file once available;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;home/entry/camera&lt;/code&gt;: to enable / disable motion:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Depending on the value, motion is {enabled,disabled} via&#xA;&lt;code&gt;subprocess.Popen(&amp;quot;sudo systemctl {start,stop} motion.service&amp;quot;, shell=True, stdout=subprocess.PIPE).stdout.read()&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The paho.mqtt.client python library is used by the script so you need to&#xA;install it:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    pip3 install paho-mqtt&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Also, the &lt;code&gt;requests&lt;/code&gt; library is used to send the snapshot via http.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    pip3 install -U requests&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Have a look to the&#xA;&lt;a href=&#34;https://github.com/bacardi55/scripts55-cleaned/blob/main/nickylarson/mqtt-gateway.py&#34;&gt;full&#xA;script&lt;/a&gt; it will help :).&lt;/p&gt;&#xA;&lt;p&gt;To start the script at launch, I added this cron job:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    @reboot sleep 30 &amp;amp;&amp;amp; /usr/bin/python3 /home/pi/scripts/mqtt-gateway.py &amp;gt; /tmp/mqtt-gateway.log 2&amp;gt;&amp;amp;1&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;via &lt;code&gt;crontab -e&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Ok, now that PiCam is ready, we need to configure NodeRed.&lt;/p&gt;&#xA;&lt;h2 id=&#34;on-nodered&#34;&gt;On NodeRed&lt;/h2&gt;&#xA;&lt;p&gt;On the NodeRed side, we need to configure: - The HTTP requests&#xA;endpoints: - &lt;code&gt;/api/home/mode&lt;/code&gt;: A GET request to retrieve the home&#xA;status; - &lt;code&gt;/api/home/entry/camera/event/end&lt;/code&gt;: Receive the &amp;ldquo;end event&amp;rdquo;&#xA;generated video file; - &lt;code&gt;/api/home/entry/camera/snapshot&lt;/code&gt;: When a&#xA;snapshot is received. - MQTT messages to be sent to: - Enable/Disable&#xA;Motion; - Request a snapshot.&lt;/p&gt;&#xA;&lt;h3 id=&#34;nodered-flows&#34;&gt;NodeRed flows&lt;/h3&gt;&#xA;&lt;h4 id=&#34;house-mode--get&#34;&gt;House Mode (GET)&lt;/h4&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/03/nodered-api-gethome.png&#34;&#xA;    alt=&#34;Figure 1: NodeRed API Get Home&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 1: &lt;/span&gt;NodeRed API Get Home&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;prep response&lt;/code&gt; function only set the house mode (global variable)&#xA;in the payload that is then converted to JSON and send as the response&#xA;of the API call with the 200 status code.&lt;/p&gt;&#xA;&lt;h4 id=&#34;event-end--post-with-attachment&#34;&gt;Event End (POST with attachment)&lt;/h4&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/03/nodered-api-eventends.png&#34;&#xA;    alt=&#34;Figure 2: NodeRed API Events&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 2: &lt;/span&gt;NodeRed API Events&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;This one is a bit more complex. Basically, when receiving the API&#xA;request with the file in the received payload (in my case&#xA;&lt;code&gt;msg.req.files[0].buffer&lt;/code&gt;), the buffer is copied it to a specific file&#xA;(&lt;code&gt;/data/camera/entry.mp4&lt;/code&gt; in my case). Then, a 200 response is sent back&#xA;and the video is then sent to me via telegram. To send a video, all I&#xA;need is to indicate that the type is video and content is the path to&#xA;the file, with a caption saying «Home Intrusion!».&lt;/p&gt;&#xA;&lt;h4 id=&#34;snapshot--post-with-attachment&#34;&gt;Snapshot (POST with attachment)&lt;/h4&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/03/nodered-api-snapshot.png&#34;&#xA;    alt=&#34;Figure 3: NodeRed Snapshot&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 3: &lt;/span&gt;NodeRed Snapshot&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;The snapshot works the same way as above.&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/03/nodered-mqtt-entrycam.png&#34;&#xA;    alt=&#34;Figure 4: NodeRed MQTT message for entry cam&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 4: &lt;/span&gt;NodeRed MQTT message for entry cam&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;When, via telegram, I request a snapshot, (bottom part of the&#xA;screenshot), an MQTT message is sent to start motion (see above with the&#xA;MQTT handler). There is a 1 minute delay just to make sure motion is&#xA;correctly started. Then a request is actually sent for the snapshot over&#xA;MQTT.&lt;/p&gt;&#xA;&lt;p&gt;The MQTT handler described above is then taking care to request the&#xA;snapshot and then send it back to nodered.&lt;/p&gt;&#xA;&lt;h4 id=&#34;enable-disable-motion&#34;&gt;Enable/Disable Motion&lt;/h4&gt;&#xA;&lt;p&gt;See the previous screenshot. In there, we see the simple camera on/off&#xA;settings that is then sent over MQTT so that the MQTT handler listen to&#xA;when start/stop motion.&lt;/p&gt;&#xA;&lt;h2 id=&#34;bonus&#34;&gt;Bonus&lt;/h2&gt;&#xA;&lt;h3 id=&#34;backup-pictures-as-arrive&#34;&gt;Backup pictures as arrive&lt;/h3&gt;&#xA;&lt;p&gt;I have a script that runs to check if there are new files (pictures)&#xA;created by motion. I do this because pictures are created on the fly&#xA;from motion. It means that on top of the video I will have pictures too.&#xA;Because a potential attacker can see the PiCam when entering and&#xA;potentially destroy it before the video has been fully taken, at least&#xA;the picture are saved to another machine quickly.&lt;/p&gt;&#xA;&lt;p&gt;To do this, I use &lt;code&gt;inotifywait&lt;/code&gt; to react on new files. First, install it&#xA;via:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    sudo apt-get install inotify-tools&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is my shell script that scp files as they appear in the motion&#xA;directory (look at the configuration to see where they go):&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;#!/bin/sh&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    logfile&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;/tmp/watcher.log&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    date&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;date&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    which inotifywait &amp;gt;/dev/null &lt;span style=&#34;color:#f92672&#34;&gt;||&lt;/span&gt; err &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;you need &amp;#39;inotifywait&amp;#39; command (sudo apt-get install inotify-tools)&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    pkill -f &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;inotifywait -m /var/motion/pictures -e create -e moved_to&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#75715e&#34;&gt;# kill old watcher&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    inotifywait -m /var/motion/pictures -e create -e moved_to |&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;while&lt;/span&gt; read path action file; &lt;span style=&#34;color:#66d9ef&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#75715e&#34;&gt;#echo &amp;#34;The file &amp;#39;$file&amp;#39; appeared in directory &amp;#39;$path&amp;#39; via &amp;#39;$action&amp;#39;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$date&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            scp &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$path$file&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &amp;lt;user&amp;gt;@&amp;lt;server&amp;gt;:/path/to/directory &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;logfile&amp;#34;&lt;/span&gt; 2&amp;gt;&amp;amp;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Copying new files &lt;/span&gt;$file&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, I start this script at boot with a cron job as well:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    @reboot sleep 50 &amp;amp;&amp;amp; sh /home/pi/scripts/motionfiles_watcher.sh&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In reality, pictures uploaded to this other local server will then be&#xA;exported to an external one too, but that&amp;rsquo;s not part of this blog post.&lt;/p&gt;&#xA;&lt;h3 id=&#34;clean-old-files&#34;&gt;Clean old files&lt;/h3&gt;&#xA;&lt;p&gt;As the picture directory can grow quickly, I have a cleaning script that&#xA;runs daily:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;#!/bin/sh&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    logfile&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;/tmp/cleaning.log&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    date&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;date&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$date&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Cleaning old images&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    sudo find /var/motion/pictures/ -mindepth &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt; -mtime +4 -delete &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; 2&amp;gt;&amp;amp;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Cleaning done&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$logfile&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Started via cron job as usual:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    0 7 * * * sh /home/pi/scripts/motionfiles_dailyclean.sh&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This post is wayyyyy longer than expected, so I&amp;rsquo;ll stop here, but feel&#xA;free to reach out for additional info (:.&lt;/p&gt;&#xA;</description></item>
    <item>
      
      <title>Home Automation, part 7: Alarms and alerts flows with Nodered</title><link>https://bacardi55.io/2021/03/09/home-automation-part-7-alarms-and-alerts-flows-with-nodered/</link><pubDate>Tue, 09 Mar 2021 00:00:00 +0100</pubDate><author>bac@rdi55.pl (bacardi55)</author><guid>https://bacardi55.io/2021/03/09/home-automation-part-7-alarms-and-alerts-flows-with-nodered/</guid><description>&lt;h2 id=&#34;context&#34;&gt;Context&lt;/h2&gt;&#xA;&lt;p&gt;Following my previous posts about&#xA;&lt;a href=&#34;https://bacardi55.io/2021/02/06/home-automation-part-4-list-of-my-nodered-automation-flows/&#34;&gt;my&#xA;automation flows&lt;/a&gt;,&#xA;&lt;a href=&#34;https://bacardi55.io/2021/02/22/home-automation-part-5-night-and-morning-routines-with-nodered/&#34;&gt;my&#xA;night and morning routines&lt;/a&gt; and&#xA;&lt;a href=&#34;https://bacardi55.io/2021/02/28/home-automation-part-6-leaving-and-arriving-home-routine-via-nodered/&#34;&gt;my&#xA;leaving and arriving home routines&lt;/a&gt;, in this post, I want to describe&#xA;the different alerts mechanism I have in place.&lt;/p&gt;&#xA;&lt;p&gt;The involved devices are: - A raspberry pi 0W with a fisheye camera&#xA;pointing at the door entry running&#xA;&lt;a href=&#34;https://motion-project.github.io/&#34;&gt;motion&lt;/a&gt; (but more on this in my&#xA;next post); - Zwave devices: Door sensor, Water leak dectector, Smoke&#xA;detectors; - My &lt;a href=&#34;https://bacardi55.io/pages/home-lab/&#34;&gt;homelab&lt;/a&gt; cluster with&#xA;&lt;a href=&#34;https://nodered.org/&#34;&gt;NodeRed&lt;/a&gt;,&#xA;&lt;a href=&#34;https://www.domoticz.com/&#34;&gt;Domoticz&lt;/a&gt; and&#xA;&lt;a href=&#34;https://github.com/eclipse/mosquitto&#34;&gt;Mosquitto&lt;/a&gt;;&lt;/p&gt;&#xA;&lt;h2 id=&#34;alarms&#34;&gt;Alarms&lt;/h2&gt;&#xA;&lt;h3 id=&#34;always-on-detectors&#34;&gt;Always on detectors&lt;/h3&gt;&#xA;&lt;h4 id=&#34;smoke-and-water-leaks&#34;&gt;Smoke and Water leaks&lt;/h4&gt;&#xA;&lt;p&gt;I have a few &amp;ldquo;always on&amp;rdquo; detectors. I use a water leak and a smoke&#xA;detectors. They do ring very loud in case of water or smoke detected but&#xA;also connect over zwave so that domoticz can receive information when an&#xA;alert is raised by one of the devices. I&amp;rsquo;ve explained how&#xA;&lt;a href=&#34;https://bacardi55.io/2021/02/06/home-automation-part-4-list-of-my-nodered-automation-flows/#mqtt&#34;&gt;NodeRed&#xA;listen to Domoticz MQTT message for all devices and republish this in a&#xA;proper way&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;This is the smoke detector flow:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/03/nodered-smoke-flow.png&#34;&#xA;    alt=&#34;Figure 1: NodeRed Smoke Flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 1: &lt;/span&gt;NodeRed Smoke Flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;As you can see, based on the message receive, I send a notification via&#xA;telegram.&lt;/p&gt;&#xA;&lt;p&gt;The Start Alert subflow looks like this:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/03/nodered-startalert-flow.png&#34;&#xA;    alt=&#34;Figure 2: NodeRed Startalert Subflow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 2: &lt;/span&gt;NodeRed Startalert Subflow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;The message indicates the alert, eg: &amp;ldquo;Alert: Water leak detected&amp;rdquo; or&#xA;&amp;ldquo;Alert: Smoke detected&amp;rdquo;. Then, like for&#xA;&lt;a href=&#34;https://bacardi55.io/2021/02/28/home-automation-part-6-leaving-and-arriving-home-routine-via-nodered/&#34;&gt;night / morning routines&lt;/a&gt;, it asks me if this is a real alert or not. If I&#xA;don&amp;rsquo;t respond, it will tell me every 10min that the home is still under&#xA;alerts.&lt;/p&gt;&#xA;&lt;p&gt;If I say it is a real alert, then for now it does nothing except wishing&#xA;me luck&amp;hellip; Not very useful yet but I have some ideas to implement here.&lt;/p&gt;&#xA;&lt;p&gt;This is the nodered flow that checks for unresolved alerts:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/03/nodered-alarm-check.png&#34;&#xA;    alt=&#34;Figure 3: NodeRed checks for alert every 10min&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 3: &lt;/span&gt;NodeRed checks for alert every 10min&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;The rules here are just passing parameters to the alert to indicate it&#xA;is a repeat and not a new alert. It means that the message will be&#xA;different (eg: &amp;ldquo;Home is still under alert (&lt;code&gt;&amp;lt;reason of the alert&amp;gt;&lt;/code&gt;), do&#xA;something!&amp;rdquo;).&lt;/p&gt;&#xA;&lt;p&gt;The &amp;ldquo;show notification&amp;rdquo; subflow will just display the alert on NodeRed&#xA;dashboard (so at least on my touch screen in the living room and any&#xA;other place where the dashboard is loaded).&lt;/p&gt;&#xA;&lt;p&gt;This is the water leak flow:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/03/nodered-water-flow.png&#34;&#xA;    alt=&#34;Figure 4: NodeRed Water flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 4: &lt;/span&gt;NodeRed Water flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;Same kind of alert/questions is sent for this one. You can notice in&#xA;this case that the alert can stopped itself if the water leak indicates&#xA;that everything is fine again.&lt;/p&gt;&#xA;&lt;p&gt;The stop alert subflow looks like this:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/03/nodered-stopalert-flow.png&#34;&#xA;    alt=&#34;Figure 5: NodeRed Stop alert flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 5: &lt;/span&gt;NodeRed Stop alert flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;Very simple, remove the alert and send back a message.&lt;/p&gt;&#xA;&lt;h4 id=&#34;entry-door&#34;&gt;Entry Door&lt;/h4&gt;&#xA;&lt;p&gt;I also have an &amp;ldquo;always on&amp;rdquo; check on the entry door where I have a small&#xA;z-wave device that checks if the door is closed or opened. When home, I&#xA;will get an alert if a door has been opened for more than 2 minutes.&lt;/p&gt;&#xA;&lt;p&gt;The flow looks like this:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/03/nodered-alarm-entry-door.png&#34;&#xA;    alt=&#34;Figure 6: NodeRed Alarm Entry Door opened for 2min&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 6: &lt;/span&gt;NodeRed Alarm Entry Door opened for 2min&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;Basically start a counter that will wait for 2min. If nothing happened&#xA;during this 2 minutes, then an message will be sent to my phone on&#xA;telegram. If that&amp;rsquo;s the case while in away mode, it will raise an alert&#xA;too (see below).&lt;/p&gt;&#xA;&lt;p&gt;If the door is closed faster than 2 minutes, the counter is stopped and&#xA;nothing is sent.&lt;/p&gt;&#xA;&lt;h3 id=&#34;away-mode-alerts&#34;&gt;Away mode alerts&lt;/h3&gt;&#xA;&lt;p&gt;When in &amp;ldquo;Away&amp;rdquo; mode, I have the following running: - Check if entry door&#xA;is close; - Check for movement in living room; - Check for movement in&#xA;office. - Camera with motion detection pointing at the entry door;&lt;/p&gt;&#xA;&lt;p&gt;The nodered flow for the first 3 ones looks like this (still based on&#xA;the mqtt messages received&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;):&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/03/nodered-alarm-door-and-mvt.png&#34;&#xA;    alt=&#34;Figure 7: NodeRed Stop alert flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 7: &lt;/span&gt;NodeRed Stop alert flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;You can notice that the entry door alert here is fired by motion and the&#xA;camera, not the entry door (not the same MQTT topic). That is because&#xA;the entry door is managed elsewhere, as shown in the picture above in&#xA;the &lt;a href=&#34;https://bacardi55.io/#entry-door&#34;&gt;entry door&lt;/a&gt; flow.&lt;/p&gt;&#xA;&lt;p&gt;Basically, when receiving a mqtt message indicating some movement in the&#xA;office, the living room or at the entry door, if the mode is &amp;ldquo;away&amp;rdquo; then&#xA;it will start an alert as well as send me a notification via telegram.&lt;/p&gt;&#xA;&lt;p&gt;Same for the entry door, if it is open while in &amp;ldquo;Away&amp;rdquo; mode, I&amp;rsquo;ll get a&#xA;message on telegram and an alert will be raised.&lt;/p&gt;&#xA;&lt;p&gt;I haven&amp;rsquo;t program anything yet in case of emergency, but I&amp;rsquo;m thinking&#xA;potentially of a message indicating their faces have been recorded and&#xA;sent to a remote server as well as playing an alarm sound at maximum&#xA;level in every room. But I didn&amp;rsquo;t set it up yet.&lt;/p&gt;&#xA;&lt;p&gt;A detailed post on managing the motion (on/off, captures, backups&#xA;etc&amp;hellip;) will follow soon as it would make this post way too long :).&lt;/p&gt;&#xA;&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;&#xA;&lt;hr&gt;&#xA;&lt;ol&gt;&#xA;&lt;li id=&#34;fn:1&#34;&gt;&#xA;&lt;p&gt;See&#xA;&lt;a href=&#34;https://bacardi55.io/2021/02/06/home-automation-part-4-list-of-my-nodered-automation-flows/#mqtt&#34;&gt;this&#xA;post&lt;/a&gt; for more details on mqtt management.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/div&gt;&#xA;</description></item>
    <item>
      
      <title>Home Automation, part 6: Leaving and Arriving home routine via NodeRed</title><link>https://bacardi55.io/2021/02/28/home-automation-part-6-leaving-and-arriving-home-routine-via-nodered/</link><pubDate>Sun, 28 Feb 2021 00:00:00 +0100</pubDate><author>bac@rdi55.pl (bacardi55)</author><guid>https://bacardi55.io/2021/02/28/home-automation-part-6-leaving-and-arriving-home-routine-via-nodered/</guid><description>&lt;h2 id=&#34;context&#34;&gt;Context&lt;/h2&gt;&#xA;&lt;p&gt;Following my previous posts about&#xA;&lt;a href=&#34;https://bacardi55.io/2021/02/06/home-automation-part-4-list-of-my-nodered-automation-flows/&#34;&gt;my&#xA;automation flows&lt;/a&gt; and&#xA;&lt;a href=&#34;https://bacardi55.io/2021/02/22/home-automation-part-5-night-and-morning-routines-with-nodered/&#34;&gt;my&#xA;night and morning routines&lt;/a&gt;, in this post, I want to describe the two&#xA;simple routines I have in place for when I leave my place or when I come&#xA;back.&lt;/p&gt;&#xA;&lt;p&gt;It is basically about managing devices and alarms when I leave or come&#xA;back home.&lt;/p&gt;&#xA;&lt;p&gt;The involved devices are:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;A raspberry pi 0W with a fisheye camera pointing at the door entry running&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://motion-project.github.io/&#34;&gt;motion&lt;/a&gt;;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Telegram on my phone;&lt;/li&gt;&#xA;&lt;li&gt;A z-wave door sensor;&lt;/li&gt;&#xA;&lt;li&gt;My &lt;a href=&#34;https://bacardi55.io/pages/home-lab/&#34;&gt;homelab&lt;/a&gt; cluster with &lt;a href=&#34;https://nodered.org/&#34;&gt;NodeRed&lt;/a&gt;, &lt;a href=&#34;https://www.domoticz.com/&#34;&gt;Domoticz&lt;/a&gt; and &lt;a href=&#34;https://github.com/eclipse/mosquitto&#34;&gt;Mosquitto&lt;/a&gt;;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;em&gt;Nota&lt;/em&gt;: More devices will be used for the next post explaining all&#xA;alarms in place.&lt;/p&gt;&#xA;&lt;h2 id=&#34;routine-description&#34;&gt;Routine description:&lt;/h2&gt;&#xA;&lt;h3 id=&#34;leaving-routine&#34;&gt;Leaving Routine&lt;/h3&gt;&#xA;&lt;p&gt;When leaving my apartment, the following scenario runs: - Wait 30s&#xA;and: - Switch off lights and TV (if on); - Stop kodi media server and&#xA;the multi room music system if playing; - Switch off the piscreen&#xA;display. - Wait 5min and: - Start entry door camera (motion); - Set&#xA;&amp;ldquo;Away&amp;rdquo; mode (for alarms); - Send &amp;ldquo;good by&amp;rdquo; notification.&lt;/p&gt;&#xA;&lt;p&gt;The NodeRed flow looks like this:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-leaving-flow.png&#34;&#xA;    alt=&#34;Figure 1: NodeRed leaving flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 1: &lt;/span&gt;NodeRed leaving flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;I will describe in the next post the alarms themselves in place and how&#xA;they work so I won&amp;rsquo;t say much here except that NodeRed will send via&#xA;MQTT a message. A custom python script run on the raspberry pi 0W with&#xA;motion listen to this specific topic. Depending on the message, the&#xA;script will start/stop motion and the camera. Stay tuned for more&#xA;details.&lt;/p&gt;&#xA;&lt;p&gt;You can read the &lt;a href=&#34;https://bacardi55.io/2021/02/06/home-automation-part-4-list-of-my-nodered-automation-flows/#device-mgt&#34;&gt;part 4&lt;/a&gt; for details on managing the devices.&lt;/p&gt;&#xA;&lt;p&gt;5min later, I will receive a message on Telegram if everything went well&#xA;saying «Away mode activated! See you soon :)».&lt;/p&gt;&#xA;&lt;h4 id=&#34;starting-the-leaving-routine&#34;&gt;Starting the &amp;ldquo;leaving routine&amp;rdquo;&lt;/h4&gt;&#xA;&lt;p&gt;I used to have a Bluetooth beacon to detect if I was home or not but it&#xA;died. Since then, I have a more manual process. When leaving the house,&#xA;I have multiple options to start the &amp;ldquo;leaving home&amp;rdquo; scenario: - On the&#xA;touch piscreen, I can start the &amp;ldquo;leaving home&amp;rdquo; scenario (see&#xA;&lt;a href=&#34;https://bacardi55.io/2021/02/06/home-automation-part-4-list-of-my-nodered-automation-flows/#dashboard&#34;&gt;this&#xA;post&lt;/a&gt; for a screenshot of the dashboard); - By clicking on my &amp;ldquo;exit&#xA;button&amp;rdquo; near the entry door. Unfortunately, this is the only unreliable&#xA;z-wave device I have so I don&amp;rsquo;t really use it as it doesn&amp;rsquo;t work most of&#xA;the time&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;; - By clicking on the right button that my&#xA;&lt;a href=&#34;https://www.remotec.com.hk/zrc90&#34;&gt;multi button remote control&lt;/a&gt;; - By&#xA;sending a Telegram command (Allow me to enable it whenever I want).&lt;/p&gt;&#xA;&lt;h3 id=&#34;arriving-routine&#34;&gt;Arriving Routine&lt;/h3&gt;&#xA;&lt;p&gt;When arriving home, the following is done: - Switching off the entry&#xA;camera (stopping motion); - Switch on piscreen display; - Send me a&#xA;welcome message on telegram (just to make sure that if anyone else know&#xA;how to stop the alerts by saying I&amp;rsquo;m home, I still receive something on&#xA;telegram); - Change house mode from &amp;ldquo;away&amp;rdquo; to &amp;ldquo;home&amp;rdquo;;&lt;/p&gt;&#xA;&lt;p&gt;The NodeRed flow looks like this:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-arriving-flow.png&#34;&#xA;    alt=&#34;Figure 2: NodeRed home flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 2: &lt;/span&gt;NodeRed home flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;Again, on the next post I&amp;rsquo;ll talk about the different alerts mechanism&#xA;in more details. But same as above, a message is sent via MQTT so that&#xA;the motion service is stopped.&lt;/p&gt;&#xA;&lt;h4 id=&#34;starting-the-arrived-home-routine&#34;&gt;Starting the &amp;ldquo;arrived home routine&amp;rdquo;&lt;/h4&gt;&#xA;&lt;p&gt;As said above, I do not have Bluetooth detection anymore to see if I&amp;rsquo;m&#xA;home or not. To start this scenario, I can: - Click on a specific button&#xA;of the remote control; - Send a telegram message (eg: when in the&#xA;elevator); - Wait for the alert and indicate I&amp;rsquo;m home (read below).&lt;/p&gt;&#xA;&lt;p&gt;The 3rd option is the one I&amp;rsquo;m using the most because when I get back&#xA;home without starting the home routine ahead (which I never do since I&#xA;don&amp;rsquo;t do Bluetooth detection), it will starts an alert (because door has&#xA;been opened while &amp;ldquo;away mode&amp;rdquo; activated, and because the entry door&#xA;camera will detect motions).&lt;/p&gt;&#xA;&lt;p&gt;Again, I will explain in details the alarm/alerts in place, but what you&#xA;need to know here is that when the entry door is opened while in &amp;ldquo;away&amp;rdquo;&#xA;mode, I will receive a message via telegram asking « Stop Alert »,&#xA;« Real Alert », « I am Home ».&lt;/p&gt;&#xA;&lt;p&gt;More details later, but clicking on « I am Home » will simply start the&#xA;&amp;ldquo;arriving home&amp;rdquo; scenario.&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/telegram-entrydoor-alert.png&#34;&#xA;    alt=&#34;Figure 3: Telegram Door Alert&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 3: &lt;/span&gt;Telegram Door Alert&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;So when I arrive home, I usually use this.&lt;/p&gt;&#xA;&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;&#xA;&lt;hr&gt;&#xA;&lt;ol&gt;&#xA;&lt;li id=&#34;fn:1&#34;&gt;&#xA;&lt;p&gt;I use &lt;a href=&#34;https://www.fibaro.com/fr/products/the-button/&#34;&gt;this&#xA;Fiboro button&lt;/a&gt;. Unlike all other&#xA;&lt;a href=&#34;https://www.fibaro.com/&#34;&gt;Fibaro&lt;/a&gt; devices that works&#xA;flawlessly, this one just doesn&amp;rsquo;t work properly. And seeing other&#xA;comments online, I&amp;rsquo;m not the only one. Too bad for a device that&#xA;is supposed to by used as an emergency button&amp;hellip;&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/div&gt;&#xA;</description></item>
    <item>
      
      <title>Home Automation, part 5: Night and Morning routines with Nodered</title><link>https://bacardi55.io/2021/02/22/home-automation-part-5-night-and-morning-routines-with-nodered/</link><pubDate>Mon, 22 Feb 2021 00:00:00 +0100</pubDate><author>bac@rdi55.pl (bacardi55)</author><guid>https://bacardi55.io/2021/02/22/home-automation-part-5-night-and-morning-routines-with-nodered/</guid><description>&lt;h2 id=&#34;context&#34;&gt;Context&lt;/h2&gt;&#xA;&lt;p&gt;In this post, I want to highlight some of the things I talked about in&#xA;my&#xA;&lt;a href=&#34;https://bacardi55.io/2021/02/06/home-automation-part-4-list-of-my-nodered-automation-flows/&#34;&gt;previous&#xA;post listing all my home automation flows&lt;/a&gt;. And more specifically some&#xA;of the routines and automation in place at night and morning (the 2 are&#xA;linked).&lt;/p&gt;&#xA;&lt;h2 id=&#34;night-routine&#34;&gt;Night Routine&lt;/h2&gt;&#xA;&lt;h3 id=&#34;telegram-chat&#34;&gt;Telegram chat&lt;/h3&gt;&#xA;&lt;p&gt;It all starts at 8pm at night with a simple question I receive via&#xA;telegram from nodered asking me if I want to see what is schedule on TV&#xA;tonight (I usually respond no, but in case I say yes, it will leverage&#xA;the http crawler nodered flow I have to parse a site and bring me back&#xA;results):&lt;/p&gt;&#xA;&lt;p&gt;A couple of hours later, at 10pm, I receive another question on telegram&#xA;asking me at what time I want to wake up tomorrow. I only receive this&#xA;if the house is not in &amp;ldquo;vacation&amp;rdquo; mode.&lt;/p&gt;&#xA;&lt;p&gt;I have some pre-programmed time to select (eg: 7am, 7:30am, 8am or&#xA;8:30am) that I can clicked easily to select the right time, or click on&#xA;&amp;ldquo;other&amp;rdquo; to indicate manually a time to wake up.&lt;/p&gt;&#xA;&lt;p&gt;Once the time is set, I&amp;rsquo;ll be asked what type of music I want to listen&#xA;in the morning. I have 2 very different playlists (one with only my&#xA;favorite hiphop songs, the other one with classical music). The UI asks&#xA;me also if I want to select manually an artist or a radio, but I haven&amp;rsquo;t&#xA;configure the flows in these cases as I normally will want just one of&#xA;the 2 choices.&lt;/p&gt;&#xA;&lt;p&gt;After deciding what music will be played, I&amp;rsquo;m asked if I&amp;rsquo;m going to bed.&#xA;At that point, I usually wait to click yes only when I go to sleep. This&#xA;will trigger the «Going to bed» scenario&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/telegram-night.png&#34;&#xA;    alt=&#34;Figure 1: Incoming telegram chat at 8pm&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 1: &lt;/span&gt;Incoming telegram chat at 8pm&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;The alarm setup flow is a bit messy and looks like this:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-alarm-setup.png&#34;&#xA;    alt=&#34;Figure 2: Nodered Alarm flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 2: &lt;/span&gt;Nodered Alarm flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;All &amp;ldquo;link in&amp;rdquo; nodes mainly come from the bot flow that handle telegram&#xA;inputs and outputs.&lt;/p&gt;&#xA;&lt;h3 id=&#34;going-to-bed-scenario&#34;&gt;«Going to bed» scenario&lt;/h3&gt;&#xA;&lt;p&gt;When clicking «Yes», the different switch will go off (lights, TV, &amp;hellip;),&#xA;music, if playing will stopped, same for any video running on kodi. The&#xA;house switch to the «night mode» where only the frontdoor alerts stays&#xA;on (as well as the usual smoke &amp;amp; water leak detection).&lt;/p&gt;&#xA;&lt;p&gt;I also have a pi with a touch screen in the living room with the nodered&#xA;dashboard that switch off (just the screen, not the pi) at night. The&#xA;screen is turned back on when motion are detected at night in the living&#xA;room (and no guest is in the living room, but more on the guest mode&#xA;later :)).&lt;/p&gt;&#xA;&lt;p&gt;That&amp;rsquo;s it for the night routine, I then go to sleep and wait for the&#xA;morning one :).&lt;/p&gt;&#xA;&lt;p&gt;At a glance, the scenario looks like this in nodered:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-gotobed.png&#34;&#xA;    alt=&#34;Figure 3: Nodered Go to bed flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 3: &lt;/span&gt;Nodered Go to bed flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h2 id=&#34;morning-routine&#34;&gt;Morning routine&lt;/h2&gt;&#xA;&lt;p&gt;In the morning, at the time I asked at night, NodeRed will start playing&#xA;the music only in my bedroom&#xA;(&lt;a href=&#34;https://bacardi55.io/2020/04/18/home-automation-part-3-multi-room-music-and-sound-system-with-mopidy-and-snapcast/&#34;&gt;Remember&#xA;I have a multiroom sound system&lt;/a&gt;) with the playlist I wanted.&lt;/p&gt;&#xA;&lt;p&gt;I will also at the same time receive a chat on telegram telling me to&#xA;wake up and give me 2 options: either saying I&amp;rsquo;m up and stop the music,&#xA;or snooze it for 10 minutes (I love too much using snooze in the&#xA;morning&amp;hellip;). If I snooze, then the next time (10min later), the sound&#xA;will be louder and I will have the same options. If I don&amp;rsquo;t respond to&#xA;this, music continues.&lt;/p&gt;&#xA;&lt;p&gt;Once I click on &amp;ldquo;I&amp;rsquo;m up&amp;rdquo;, then I will get a quote of the day, the&#xA;weather for the day and be asked if I want to read the news:&lt;/p&gt;&#xA;&lt;p&gt;If I click on &amp;ldquo;yes&amp;rdquo;, I will receive titles and links from newspaper&#xA;websites&amp;rsquo; RSS feeds. On this example, we see feeds from the french&#xA;newspaper &amp;ldquo;Le Monde&amp;rdquo;.&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/telegram-morning.png&#34;&#xA;    alt=&#34;Figure 4: telegram morning&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 4: &lt;/span&gt;telegram morning&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;This is how it is managed by Nodered:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-alarm-wakeup.png&#34;&#xA;    alt=&#34;Figure 5: Nodered Alarm Wake Up&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 5: &lt;/span&gt;Nodered Alarm Wake Up&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;↑ This is the wake up process at the time decided.&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-alarm-snooze.png&#34;&#xA;    alt=&#34;Figure 6: Nodered Alarm Snooze&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 6: &lt;/span&gt;Nodered Alarm Snooze&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;↑ This is how I manage the snooze part of the routine.&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-alarm-snapcast.png&#34;&#xA;    alt=&#34;Figure 7: Nodered Alarm Wake Up&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 7: &lt;/span&gt;Nodered Alarm Wake Up&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;↑ This is the snapcast piece to manage sound in the right room and right&#xA;sound level.&lt;/p&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;I hope I managed to explain these routines clearly :)&lt;/p&gt;&#xA;&lt;p&gt;Obviously, as I don&amp;rsquo;t share the Nodered flows themselves, let me know if&#xA;you have any questions.&lt;/p&gt;&#xA;</description></item>
    <item>
      
      <title>Home Automation, part 4: List of my NodeRed automation flows</title><link>https://bacardi55.io/2021/02/06/home-automation-part-4-list-of-my-nodered-automation-flows/</link><pubDate>Sat, 06 Feb 2021 00:00:00 +0100</pubDate><author>bac@rdi55.pl (bacardi55)</author><guid>https://bacardi55.io/2021/02/06/home-automation-part-4-list-of-my-nodered-automation-flows/</guid><description>&lt;p&gt;I&amp;rsquo;ve discussed previously on this blog the &lt;a href=&#34;https://bacardi55.io/2020/04/12/home-automation-part-1-context-and-architecture/&#34;&gt;architecture&lt;/a&gt; and &lt;a href=&#34;https://bacardi55.io/2020/04/14/home-automation-part-2-nodered-mosquitto-and-domoticz-on-my-docker-swarm-cluster/&#34;&gt;setup&lt;/a&gt; to play with home automation, with tools like &lt;a href=&#34;https://nodered.org/&#34;&gt;NodeRed&lt;/a&gt;, &lt;a href=&#34;https://www.domoticz.com/&#34;&gt;Domoticz&lt;/a&gt; and &lt;a href=&#34;https://mosquitto.org/&#34;&gt;Mosquitto&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Today, before going into details of implementation, I thought it would be a good start to introduce the different NodeRed flows I have to give you an idea of the different automation in place. I&amp;rsquo;ll then cover the most interesting ones in dedicated posts later :).&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;&lt;/strong&gt;: I&amp;rsquo;m using a lot of `link in` and `link out` node to share info between flows and also subflows. They have clear names but sometimes it might not be easy to follow. If you have any questions or remarks, let me know by email :)&lt;/p&gt;&#xA;&lt;p&gt;### Dashboard&#xA;I&amp;rsquo;ve discussed previously on this blog the &lt;a href=&#34;https://bacardi55.io/2020/04/12/home-automation-part-1-context-and-architecture/&#34;&gt;architecture&lt;/a&gt; and &lt;a href=&#34;https://bacardi55.io/2020/04/14/home-automation-part-2-nodered-mosquitto-and-domoticz-on-my-docker-swarm-cluster/&#34;&gt;setup&lt;/a&gt;&#xA;to play with home automation, with tools like &lt;a href=&#34;https://nodered.org/&#34;&gt;NodeRed&lt;/a&gt;, &lt;a href=&#34;https://www.domoticz.com/&#34;&gt;Domoticz&lt;/a&gt; and&#xA;&lt;a href=&#34;https://mosquitto.org/&#34;&gt;Mosquitto&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Today, before going into details of implementation, I thought it would&#xA;be a good start to introduce the different NodeRed flows I have to give&#xA;you an idea of the different automation in place. I&amp;rsquo;ll then cover the&#xA;most interesting ones in dedicated posts later :).&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: I&amp;rsquo;m using a lot of &lt;code&gt;link in&lt;/code&gt; and &lt;code&gt;link out&lt;/code&gt; node to share&#xA;info between flows and also subflows. They have clear names but&#xA;sometimes it might not be easy to follow. If you have any questions or&#xA;remarks, let me know by email :)&lt;/p&gt;&#xA;&lt;h2 id=&#34;dashboard&#34;&gt;Dashboard&lt;/h2&gt;&#xA;&lt;p&gt;The nodered flow to manage my nodered dashboard. The flow is quite big&#xA;to provide multiple screen tabs, so I&amp;rsquo;ll write a post about this later.&#xA;In the meantime, I can show the main screen of my dashboard as of today:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-dashboard.png&#34;&#xA;    alt=&#34;Figure 1: Nodered Dashboard&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 1: &lt;/span&gt;Nodered Dashboard&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h2 id=&#34;scenarii&#34;&gt;Scenarii&lt;/h2&gt;&#xA;&lt;p&gt;I&amp;rsquo;ll write a dedicated post for these are they are the most interesting&#xA;thing setup, but an overview of the scenarii is below:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;em&gt;Go To Bed&lt;/em&gt;: What needs to happen when going to bed: switching off&#xA;everything, setting up the morning alarm Clock&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Leaving&lt;/em&gt;: Switching everything off, setup the &amp;ldquo;empty house&amp;rdquo; mode and&#xA;enable camera at entry and the alert system&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Getting Home&lt;/em&gt;: Switching off the camera and alerts, setup &amp;ldquo;full&#xA;house&amp;rdquo; for automation to work&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Wake Up&lt;/em&gt;: My morning routine, including music to wake up and getting&#xA;the news&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Work mode&lt;/em&gt;: A special mode when working for lights or other stuff&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;alerts&#34;&gt;Alerts&lt;/h2&gt;&#xA;&lt;p&gt;Managing all alerts: Always on alert: - Water leak sensor - Smoke&#xA;detector (I use the fibaro zwave smoke detector) - Front door open for&#xA;too long&lt;/p&gt;&#xA;&lt;p&gt;When &amp;ldquo;empty house&amp;rdquo; mode is on: - Frontend open detection - Motion sensor&#xA;in entry, living room or office&lt;/p&gt;&#xA;&lt;h2 id=&#34;modes&#34;&gt;Modes&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Manage house mode: empty, full, night&lt;/li&gt;&#xA;&lt;li&gt;Manage guest mode (If guests are staying in certain rooms, I want to&#xA;stop some automation :)).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;alarm-clock&#34;&gt;Alarm Clock&lt;/h2&gt;&#xA;&lt;p&gt;Specific workspace for managing my morning alarm clock. I&amp;rsquo;ll write an&#xA;article about this specifically.&lt;/p&gt;&#xA;&lt;h2 id=&#34;music&#34;&gt;Music&lt;/h2&gt;&#xA;&lt;p&gt;Integration with MPD server from my [[][mopidy server]], eg:&#xA;play/pause/next/prev/&amp;hellip;&lt;/p&gt;&#xA;&lt;p&gt;Example of the toggle play/pause flow:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-music-example.png&#34;&#xA;    alt=&#34;Figure 2: Nodered Music Flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 2: &lt;/span&gt;Nodered Music Flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h2 id=&#34;snapcast&#34;&gt;Snapcast&lt;/h2&gt;&#xA;&lt;p&gt;Integration with Snapcast: (un)mute or change volume on the different&#xA;snapcast client, eg:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-snapcast-example.png&#34;&#xA;    alt=&#34;Figure 3: Nodered Snapcast Flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 3: &lt;/span&gt;Nodered Snapcast Flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h2 id=&#34;device-mgt&#34;&gt;Device Mgt&lt;/h2&gt;&#xA;&lt;p&gt;This is where I manage the different devices: lights, kodi, tv, zwave&#xA;remote, &amp;hellip;&lt;/p&gt;&#xA;&lt;p&gt;It looks like this (partial view):&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-devices-example.png&#34;&#xA;    alt=&#34;Figure 4: Nodered devices flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 4: &lt;/span&gt;Nodered devices flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;But the main idea of this flow is just to receive a command and then&#xA;send it like it should (eg: via mqtt for domoticz device or api calls&#xA;for to kodi for example), nothing fancy :).&lt;/p&gt;&#xA;&lt;h2 id=&#34;mqtt&#34;&gt;MQTT&lt;/h2&gt;&#xA;&lt;p&gt;It looks like this:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-mqtt-flow.png&#34;&#xA;    alt=&#34;Figure 5: MQTT nodered flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 5: &lt;/span&gt;MQTT nodered flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;Integration with MQTT. Transform MQTT output from Domoticz into&#xA;something more useful, eg:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-mqtt-domoticz-in.png&#34;&#xA;    alt=&#34;Figure 6: MQTT Domoticz In&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 6: &lt;/span&gt;MQTT Domoticz In&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;becomes&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-mqtt-domoticz-out.png&#34;&#xA;    alt=&#34;Figure 7: MQTT Domoticz In&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 7: &lt;/span&gt;MQTT Domoticz In&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;This is better for me as the output is cleaner and the topic more&#xA;explicit following a naming convention like &lt;code&gt;home/&amp;lt;Room&amp;gt;/&amp;lt;Device&amp;gt;&lt;/code&gt;. Plus&#xA;I filter also what goes out so I dont&amp;rsquo; resend everything received by&#xA;Domoticz, but only the info I want to act on.&lt;/p&gt;&#xA;&lt;p&gt;I also check in there the battery level of the different devices and&#xA;send an alert via telegram in case a device has a low battery (&amp;lt;15%).&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;Don&amp;rsquo;t mind the last &amp;ldquo;line&amp;rdquo; as it is to send debug information via&#xA;telegram in some specific cases&lt;/em&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;bot&#34;&gt;Bot&lt;/h2&gt;&#xA;&lt;p&gt;A flow that allows me to interact with nodered via telegram chat. I&amp;rsquo;ll&#xA;talk about this in a dedicated posts as it would be too long in this&#xA;&amp;ldquo;high level view&amp;rdquo; for this post.&lt;/p&gt;&#xA;&lt;p&gt;To see the things I can do through the telegram chat, see the result&#xA;from the &lt;code&gt;/help&lt;/code&gt; command:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Available commands:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /alarm: Triger question for morning alarm clock;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /alert off: Stop alert mode;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /analysis or /status : Return setup information;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /analysis-mqtt or /status-mqtt : Return MQTT values;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /bedroom {on,off}: switch {on,off} the bedroom light;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /camera {on, off}: Start/Stop camera in entry;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /guest {office, bedroom, livingroom} {on, off}: (De-)Activate guest mode in {room};&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /kanboard {Task}: Add {task} to Kanboard backlog in Triage project - Alias: /kb;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /kodi {play,pause,toggle}: Toggle play/pause;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /mode {night, away, full, night, dumb}: switch house mode;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /music {play, pause, toggle}: Play / Pause music;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /news: Retrieve the news from &amp;#39;Le Monde&amp;#39;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /office {on,off}: switch {on,off} the office light;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /piscreen {on, off, reboot, halt}: Switch off screen on PisScreen, or reboot it or shut it down;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /scenario {bed, leaving, home, wakeup}: Start scenario - Alias: /s;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /snapshot: Take a picture of the entry and send it;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /tv {on,off}: switch {on,off} the tv;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /tvprogram: Get the tv program;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    /work {on,off}: Work mode {on,off};&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;apis&#34;&gt;APIs&lt;/h2&gt;&#xA;&lt;p&gt;Just managing a few API endpoints: - 1 for receiving picture for my&#xA;frontdoor camera (more on this later) - 1 for receiving a call from&#xA;&lt;a href=&#34;https://github.com/crazy-max/diun&#34;&gt;diun&lt;/a&gt; to alert me of new images for my docker containers (as&#xA;explained earlier &lt;a href=&#34;https://bacardi55.io/2020/05/05/receive-alerts-when-new-images-are-available-for-your-docker-swarm-cluster-with-diun/&#34;&gt;here&lt;/a&gt;)&lt;/p&gt;&#xA;&lt;p&gt;The flow for the diun API looks like this:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2021/02/nodered-api-example.png&#34;&#xA;    alt=&#34;Figure 8: Nodered API flow&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 8: &lt;/span&gt;Nodered API flow&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h2 id=&#34;kanboard&#34;&gt;Kanboard&lt;/h2&gt;&#xA;&lt;p&gt;API integration with Kanboard. Mainly to send tasks to my triage&#xA;project. I use it with the release detector (add task for each new&#xA;release for me to remember to update the software) or to add task via my&#xA;telegram bot integration.&lt;/p&gt;&#xA;&lt;h2 id=&#34;html-crawler&#34;&gt;HTML Crawler&lt;/h2&gt;&#xA;&lt;p&gt;Crawl pages without RSS feed to extract content and send the response&#xA;via telegram. I use this for example for getting the TV program at night&#xA;during my evening scenario.&lt;/p&gt;&#xA;&lt;h2 id=&#34;release-detector&#34;&gt;Release Detector&lt;/h2&gt;&#xA;&lt;p&gt;Check new release on github for specific software. New release are&#xA;pushed to the triage project on my kanboard for me to remember.&lt;/p&gt;&#xA;&lt;h2 id=&#34;cron&#34;&gt;Cron&lt;/h2&gt;&#xA;&lt;p&gt;Planned tasks at a specific time. Nothing interesting there because they&#xA;are in reality part of the other flows.&lt;/p&gt;&#xA;&lt;p&gt;This post is already long enough, I&amp;rsquo;ll write about the more interesting&#xA;flow in more details (scenario, alerts, &amp;hellip;) in later posts, but in the&#xA;meantime feel free to ping me with some questions :).&lt;/p&gt;&#xA;</description></item>
    <item>
      
      <title>Home Automation, part 2 - NodeRed, Mosquitto and Domoticz on my docker swarm cluster</title><link>https://bacardi55.io/2020/04/14/home-automation-part-2-nodered-mosquitto-and-domoticz-on-my-docker-swarm-cluster/</link><pubDate>Tue, 14 Apr 2020 00:00:00 +0200</pubDate><author>bac@rdi55.pl (bacardi55)</author><guid>https://bacardi55.io/2020/04/14/home-automation-part-2-nodered-mosquitto-and-domoticz-on-my-docker-swarm-cluster/</guid><description>&lt;h2 id=&#34;context&#34;&gt;Context&lt;/h2&gt;&#xA;&lt;p&gt;Following up with &lt;a href=&#34;https://bacardi55.io/posts/2020/04/12/my-home-automation-system-part-1-context-and-architecture/&#34;&gt;my home automation concepts and architecture post&lt;/a&gt;, today I&amp;rsquo;ll talk about&#xA;the installation and configuration of the most important parts:&#xA;&lt;a href=&#34;https://nodered.org/&#34;&gt;NodeRed&lt;/a&gt; (Brain and Orchestrator, as well as web dashboard), &lt;a href=&#34;https://mosquitto.org/&#34;&gt;Mosquitto&lt;/a&gt;&#xA;(&lt;a href=&#34;https://fr.wikipedia.org/wiki/MQTT&#34;&gt;MQTT&lt;/a&gt; message broker) and &lt;a href=&#34;https://www.domoticz.com&#34;&gt;domoticz&lt;/a&gt; (Z-wave devices controller).&lt;/p&gt;&#xA;&lt;p&gt;This post assumes that your setup is at least similar to&#xA;&lt;a href=&#34;https://bacardi55.io/pages/home-lab/&#34;&gt;my homelab setup&lt;/a&gt;, the TLDR; is: &amp;gt; A docker swarm&#xA;cluster with GlusterFS shared volume running on top of Raspberry Pis :)&lt;/p&gt;&#xA;&lt;p&gt;This post assume you have also a similar setup or that you understand&#xA;enough docker and the swarm engine to adapt it to your different needs&#xA;(Kubernetes, docker standalone, etc&amp;hellip;) :-).&lt;/p&gt;&#xA;&lt;p&gt;Also, this post is not a detailed explanation of what are NodeRed,&#xA;Domoticz and Mosquitto. If you have no idea what they are or do, I&#xA;suggest reading a bit more about it.&lt;/p&gt;&#xA;&lt;p&gt;Ok? Let&amp;rsquo;s go then!&lt;/p&gt;&#xA;&lt;h2 id=&#34;installation&#34;&gt;Installation&lt;/h2&gt;&#xA;&lt;p&gt;I want to install all three (NodeRed, Mosquitto and Domoticz) on my&#xA;existing cluster, so this is what we will do, but Domoticz will be a bit&#xA;different due to the need to use a Z-wave controller USB stick.&lt;/p&gt;&#xA;&lt;h3 id=&#34;domoticz-standalone-with-docker-compose&#34;&gt;Domoticz &amp;ldquo;standalone&amp;rdquo; with docker-compose&lt;/h3&gt;&#xA;&lt;p&gt;Because I use domoticz to manage my z-wave devices, it means it needs to&#xA;access the z-wave USB stick controller. For this with docker, it means&#xA;you need to run a container with the &lt;code&gt;--device&lt;/code&gt; option. Unfortunately,&#xA;at the time of setting it up, this wasn&amp;rsquo;t possible yet with docker swarm&#xA;(It seems it will be at some point though :)). So my quick and dirty&#xA;workaround was to simply launch the Domoticz container on one node of&#xA;the cluster (the one with the USB stick, in my case, I took my manager&#xA;but that may not be the idea to be honest^^ But that&amp;rsquo;s quick to change&#xA;if I want to someday :)).&lt;/p&gt;&#xA;&lt;p&gt;So to do this, all I had to do was to plug the z-wave controller USB&#xA;stick on my selected raspberry pi (cell&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; in my case) and create the&#xA;data directories. If you follow the &lt;a href=&#34;https://bacardi55.io/posts/2020/03/24/my-home-lab-2020-part-2-glusterfs-setup/&#34;&gt;same setup as me&lt;/a&gt;&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mkdir /mnt/cluster-data/&lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;containers-data,services-config&lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;/home-automation/&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mkdir -p /mnt/cluster-data/containers-data/home-automation/domoticz/config&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And the configuration file&#xA;&lt;code&gt;/mnt/cluster-data/services-config/home-automation/docker-compose-domoticz.yml&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    version: &amp;#34;3&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    services:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      domoticz:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        image: joshuacox/mkdomoticz:arm&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        devices:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - &amp;#34;/dev/ttyUSB0:/dev/ttyUSB0&amp;#34; #adapt if needed&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        restart: always&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        ports:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - 8080:8080 #changeme&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        volumes:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - /mnt/cluster-data/containers-data/home-automation/domoticz/config:/config&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;em&gt;Nota: As said previously on this blog, I don&amp;rsquo;t publish (yet) my&#xA;building files and private registry so I use public docker images on my&#xA;blog post example. When using containers, you should either build your&#xA;own (more on this and self hosted registry later) or at least have a&#xA;very strong understanding of how the public image you use is built and&#xA;what it does before using it. Using unknown containers on your platform&#xA;is a security risk!&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;Start Domoticz service with &lt;code&gt;docker-compose&lt;/code&gt; directly:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    docker-compose -p domoticz -f /mnt/cluster-data/services-config/home-automation/docker-compose-domoticz.yml up -d&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;-p domoticz&lt;/code&gt; is to set the name of the service because I didn&amp;rsquo;t want to&#xA;use the folder name, as it will be used for the swarm services. I could&#xA;have used homeautomation_domoticz for consistency I guess, but I wanted&#xA;to highlight that this service is not run like the other (yet T_T).&lt;/p&gt;&#xA;&lt;p&gt;And voilà, Domoticz should run on &lt;code&gt;http://&amp;lt;IPAddress&amp;gt;:8080&lt;/code&gt; (or other&#xA;port if you change it - and you should).&lt;/p&gt;&#xA;&lt;p&gt;Ok, now we have Domoticz running, let&amp;rsquo;s continue!&lt;/p&gt;&#xA;&lt;h3 id=&#34;creating-our-swarm-stack-with-nodered-and-mosquitto&#34;&gt;Creating our Swarm Stack with NodeRed and Mosquitto&lt;/h3&gt;&#xA;&lt;p&gt;For NodeRed and Mosquitto, I will simply make them run like any&#xA;&lt;a href=&#34;https://bacardi55.io/posts/2020/03/30/my-home-lab-2020-part-4-running-services-over-https-with-traefik/&#34;&gt;other services on my docker swarm setup&lt;/a&gt;, by creating a homeautomation stack&#xA;containing these 2 services. I don&amp;rsquo;t want these services to be available&#xA;outside my network so I don&amp;rsquo;t configure Traefik with labels on them and&#xA;use custom port that are blocked at my router level.&lt;/p&gt;&#xA;&lt;p&gt;Create the right structure, if you follow the same as my filesystem&#xA;structure (or adapt it :)):&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mkdir -p /mnt/cluster-data/containers-data/home-automation/nodered/data&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mkdir -p /mnt/cluster-data/containers-data/home-automation/mosquitto/&lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;config,data,log&lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, create the&#xA;&lt;code&gt;/mnt/cluster-data/services-config/home-automation/docker-compose.yml&lt;/code&gt;&#xA;as usual:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    version: &amp;#34;3.7&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    services:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      node-red:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        image: nodered/node-red:latest&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        environment:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - TZ=Europe/Paris #changeme&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        ports:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - &amp;#34;1880:1880&amp;#34; #changeme&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        volumes:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - /mnt/cluster-data/containers-data/home-automation/nodered/data:/data&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        networks:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - homeautomation-net&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        deploy:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          placement:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            constraints:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              - node.role == worker&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      mosquitto:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        image: eclipse-mosquitto&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        ports:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - &amp;#34;1883:1883&amp;#34; #changeme&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - &amp;#34;9001:9001&amp;#34; #changeme&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        volumes:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - /mnt/cluster-data/containers-data/home-automation/mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - /mnt/cluster-data/containers-data/home-automation/mosquitto/data:/mosquitto/data&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - /mnt/cluster-data/containers-data/home-automation/mosquitto/log:/mosquitto/log&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        networks:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          - homeautomation-net&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        deploy:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          placement:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            constraints:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              - node.role == worker&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    networks:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      homeautomation-net:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then create the configuration file for Mosquitto. My own is&#xA;&lt;code&gt;/mnt/cluster-data/containers-data/home-automation/mosquitto/config/mosquitto.conf&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    persistence true&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    persistence_location /mosquitto/data/&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    log_dest file /mosquitto/log/mosquitto.log&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Because I want to have persistent data. See the &lt;a href=&#34;https://mosquitto.org/man/mosquitto-conf-5.htmls://mosquitto.org/man/mosquitto-conf-5.html&#34;&gt;official documentation&lt;/a&gt; for more options.&lt;/p&gt;&#xA;&lt;p&gt;If you change &lt;code&gt;/mosquitto/data/&lt;/code&gt; or &lt;code&gt;/mosquitto/log/mosquitto.log&lt;/code&gt;, make&#xA;sure to also update the &lt;code&gt;docker-compose.yml&lt;/code&gt; file with the right paths.&lt;/p&gt;&#xA;&lt;p&gt;As usual, I force containers to run on worker nodes and not on the&#xA;manager (where there are already specific services running like Treafik,&#xA;Domoticz, &amp;hellip;).&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;Nota: As said previously on this blog, I don&amp;rsquo;t publish (yet) my&#xA;building files and private registry so I use public docker images on my&#xA;blog post example. When using containers, you should either build your&#xA;own (more on this and self hosted registry later) or at least have a&#xA;very strong understanding of how the public image you use is built and&#xA;what it does before using it. Using unknown containers on your platform&#xA;is a security risk!&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;Deploy the stack:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    docker stack deploy homeautomation -c /mnt/cluster-data/services-config/home-automation/docker-compose.yml&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can go to &lt;code&gt;http://&amp;lt;clusterIP&amp;gt;:1880&lt;/code&gt; to see if NodeRed is working&#xA;correctly.&lt;/p&gt;&#xA;&lt;p&gt;To test if Mosquitto is working correctly, I&amp;rsquo;m using the following&#xA;command from my laptop:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mosquitto_sub -h &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;10.0.0.101&amp;#34;&lt;/span&gt; -p &lt;span style=&#34;color:#ae81ff&#34;&gt;5883&lt;/span&gt;  -t &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;#&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;(You need to install &lt;code&gt;mosquitto-clients&lt;/code&gt; to do so)&lt;/p&gt;&#xA;&lt;p&gt;Delete the stack:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    docker stack rm homeautomation&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And voilà for the installation!&lt;/p&gt;&#xA;&lt;h2 id=&#34;configuration&#34;&gt;Configuration&lt;/h2&gt;&#xA;&lt;p&gt;And now we have all our 3 software running, it&amp;rsquo;s time to configure them!&#xA;Obviously, configuring home automation tools like Domoticz or&#xA;orchestrator like NodeRed is highly dependant of your use cases so I&#xA;keep this part very thin just to highlight some of the things I had to&#xA;do. NodeRed and Mosquitto are normally running, all you need is&#xA;&lt;a href=&#34;https://nodered.org/docs/tutorials/first-flows&#34;&gt;create flows with NodeRed&lt;/a&gt; (we&amp;rsquo;ll see this later on).&lt;/p&gt;&#xA;&lt;p&gt;Domoticz needs some additional configuration though to connect the&#xA;z-wave controller and enable the MQTT relay.&lt;/p&gt;&#xA;&lt;p&gt;First, go to Domoticz Web UI. If you didn&amp;rsquo;t change the port, it is&#xA;available at &lt;code&gt;http://&amp;lt;ClusterIpAddress&amp;gt;:8080&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;z-wave-usb-stick&#34;&gt;Z-wave USB stick&lt;/h3&gt;&#xA;&lt;p&gt;To be able to manage z-wave devices, we need to setup the z-wave&#xA;controller USB stick. For this, go to &lt;code&gt;Setup → Hardware&lt;/code&gt; and add a new&#xA;«OpenZWave USB» type of hardware:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2020/04/14/homeautomationp2/openzwaveusb.png&#34;&#xA;    alt=&#34;Figure 1: OpenZwave USB in domoticz&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 1: &lt;/span&gt;OpenZwave USB in domoticz&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;Of course, adapt it for your device (may be &lt;code&gt;/dev/ttyUSB1&lt;/code&gt; or other).&lt;/p&gt;&#xA;&lt;p&gt;Then, you need to configure the devices that you wish to connect to your&#xA;z-wave controller and thus to Domoticz. There are other documentation&#xA;about this online, I suggest you read this page to start including all&#xA;your devices:&#xA;&lt;a href=&#34;https://www.vesternet.com/pages/apnt-85-using-domoticz-with-the-razberry-z-wave-controller#.U_4xlxYU58E&#34;&gt;https://www.vesternet.com/pages/apnt-85-using-domoticz-with-the-razberry-z-wave-controller#.U_4xlxYU58E&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is where every setup might end up being different depending on&#xA;devices you want to include (eg: remotes or buttons don&amp;rsquo;t work the same&#xA;as detector for example). If you feel lost about these and don&amp;rsquo;t find&#xA;resources online, you can also &lt;a href=&#34;https://bacardi55.io/pages/about-me/&#34;&gt;contact me&lt;/a&gt; :).&lt;/p&gt;&#xA;&lt;h3 id=&#34;mqtt-relay&#34;&gt;MQTT relay&lt;/h3&gt;&#xA;&lt;p&gt;Ok, we have our z-wave controller installed and configured (you should&#xA;have devices shown when clicking on the &lt;code&gt;setup&lt;/code&gt; button next to your&#xA;z-wave USB stick) and see devices on the &lt;code&gt;setup → devices&lt;/code&gt; menu link.&lt;/p&gt;&#xA;&lt;p&gt;What we want now, is for Domoticz to send and receive messages (device&#xA;status update or command to send to devices) via MQTT to our Mosquitto&#xA;broker. For this, go to &lt;code&gt;setup → hardware&lt;/code&gt; again and create a new&#xA;hardware «MQTT Client Gateway with LAN interface»:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2020/04/14/homeautomationp2/mqtt.png&#34;&#xA;    alt=&#34;Figure 2: MQTT client in domoticz&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 2: &lt;/span&gt;MQTT client in domoticz&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;Obviously, you need to put your Cluster IP address and the port declared&#xA;in your &lt;code&gt;docker-compose.yml&lt;/code&gt; file (&lt;code&gt;1883&lt;/code&gt; by default).&lt;/p&gt;&#xA;&lt;p&gt;Don&amp;rsquo;t forget to set the &amp;ldquo;Publish Topic&amp;rdquo; to &lt;code&gt;out + /&lt;/code&gt;. The login password&#xA;fields are optional and needed only if you enabled Mosquitto&#xA;authentication.&lt;/p&gt;&#xA;&lt;p&gt;The official documentation should help you if you have difficulties:&#xA;&lt;a href=&#34;https://www.domoticz.com/wiki/MQTT#Add_hardware_.22MQTT_Client_Gateway.22&#34;&gt;https://www.domoticz.com/wiki/MQTT#Add_hardware_.22MQTT_Client_Gateway.22&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Your Domoticz is ready to send and receive MQTT messages and manage&#xA;Z-wave devices connected to your controller USB stick. If you already&#xA;setup a sensor device, you should see updates from it via MQTT. For&#xA;this, if you have installed &lt;code&gt;mosquitto-clients&lt;/code&gt;, you can launch:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mosquitto_sub -h &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;lt;ClusterIP&amp;gt;&amp;#34;&lt;/span&gt; -p &lt;span style=&#34;color:#ae81ff&#34;&gt;1883&lt;/span&gt;  -t &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;#&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Update the and optionally the port and wait a bit, you should see a&#xA;Domoticz message like this&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Battery&amp;#34;&lt;/span&gt; : 100,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;RSSI&amp;#34;&lt;/span&gt; : XX,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;description&amp;#34;&lt;/span&gt; : &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;dtype&amp;#34;&lt;/span&gt; : &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Temp + Humidity&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;id&amp;#34;&lt;/span&gt; : &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;XXX&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;idx&amp;#34;&lt;/span&gt; : XX&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;name&amp;#34;&lt;/span&gt; : &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;TempOffice&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;nvalue&amp;#34;&lt;/span&gt; : 0,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;stype&amp;#34;&lt;/span&gt; : &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;XXXXXX&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;svalue1&amp;#34;&lt;/span&gt; : &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;24.6&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;svalue2&amp;#34;&lt;/span&gt; : &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;23&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;svalue3&amp;#34;&lt;/span&gt; : &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;2&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;unit&amp;#34;&lt;/span&gt; : &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Of course this is an example but you should have something similar.&#xA;Later in this series, we&amp;rsquo;ll see how I handle these messages with NodeRed&#xA;and resend information in a more useful format for the other automation&#xA;flows.&lt;/p&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;This posts is already longer than expected so I&amp;rsquo;m stopping it here, but&#xA;there are a lot of other things to say :-). I don&amp;rsquo;t intend to replace&#xA;official documentation as well on how to use any of this tools. I&amp;rsquo;ll&#xA;focus in the next posts about the different flows I have setup at home&#xA;(eg: automation flows, routine, multi room music system, CEC bridge,&#xA;&amp;hellip;), that should be funnier that basic setup stuff :).&lt;/p&gt;&#xA;&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;&#xA;&lt;hr&gt;&#xA;&lt;ol&gt;&#xA;&lt;li id=&#34;fn:1&#34;&gt;&#xA;&lt;p&gt;As explained on &lt;a href=&#34;https://bacardi55.io/posts/2020/03/24/my-home-lab-2020-part-2-glusterfs-setup/#fnref:6&#34;&gt;this post&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li id=&#34;fn:2&#34;&gt;&#xA;&lt;p&gt;I follow the same setup rules as for my swarm services, it makes&#xA;more sense for backups, but more on that later.&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li id=&#34;fn:3&#34;&gt;&#xA;&lt;p&gt;Obviously, this highly depends on the devices setup.&amp;#160;&lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/div&gt;&#xA;</description></item>
    <item>
      
      <title>Home Automation, part 1 - Context and Architecture</title><link>https://bacardi55.io/2020/04/12/home-automation-part-1-context-and-architecture/</link><pubDate>Sun, 12 Apr 2020 00:00:00 +0200</pubDate><author>bac@rdi55.pl (bacardi55)</author><guid>https://bacardi55.io/2020/04/12/home-automation-part-1-context-and-architecture/</guid><description>&lt;h2 id=&#34;context&#34;&gt;Context&lt;/h2&gt;&#xA;&lt;p&gt;As previously said in my [[][homelab posts]], I&amp;rsquo;ve redone completely my&#xA;home automation system as it became old and not necessary aligned with&#xA;my usage&amp;hellip; To avoid repeating myself (because I&amp;rsquo;m also very lazy^^),&#xA;let me quote myself (that seems very narcissist of me&amp;hellip;):&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;On the home automation part, it became way too complicated, mostly&#xA;because I was learning at the time and was building it little by&#xA;little. I had a old rpi2 B with &lt;a href=&#34;https://github.com/domoticz/domoticz&#34;&gt;domoticz&lt;/a&gt;, a rpi3 with&#xA;&lt;a href=&#34;https://kalliope-project.github.io/&#34;&gt;kalliope&lt;/a&gt; and &lt;a href=&#34;https://nodered.org/&#34;&gt;nodered&lt;/a&gt;, &amp;hellip; For those reading my blog back&#xA;then, you are familiar with the voice assistant&#xA;&lt;a href=&#34;https://kalliope-project.github.io/&#34;&gt;Kalliope&lt;/a&gt; that was the brain&#xA;of my home and I was actively participating. One thing though&amp;hellip; I&#xA;noticed that I don&amp;rsquo;t like to talk to a software, that I prefer an easy&#xA;to access interface (web, app, cli, &amp;hellip;) to do the action I wanted&amp;hellip;&#xA;And that I was more into automation than voice control.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;The goal of this post is to describe the constraints and the&#xA;architecture choices for my home automation system. There will be follow&#xA;up posts on the setup and then a series of posts related to the actual&#xA;automation I put in place over time :).&lt;/p&gt;&#xA;&lt;h2 id=&#34;automation-ok-dot-dot-dot-but-for-what&#34;&gt;Automation ok&amp;hellip; But for what?&lt;/h2&gt;&#xA;&lt;p&gt;I have multiple type of things running that I will describe in more&#xA;details in future posts, like:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Home Alerts&lt;/strong&gt;: I have captors to alert me on things like water flood,&#xA;smoke detection, open front door for too long, temperature too low,&#xA;etc&amp;hellip;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Intrusion alerts&lt;/strong&gt;: When not in the house, camera is running filming&#xA;the front door as well as motion detector in rooms and I get an alert&#xA;directly via chatbot that something is up. I also receive a video of&#xA;the motion detected at the entry door (if any).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Recurring tasks&lt;/strong&gt;: Basic routines like wake up, go to sleep, leaving&#xA;the house, etc&amp;hellip;- &lt;strong&gt;Scenario&lt;/strong&gt;: Set of tasks that happen on specific occasion (leaving or&#xA;arriving at home, going to sleep, etc&amp;hellip;)&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Devices control&lt;/strong&gt;: Lights via motion detection in specific rooms and&#xA;other devices (Includes Sound system, media center, tv hdmi, etc&amp;hellip;).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Control&lt;/strong&gt;: Global house control from a single web dashboard,&#xA;accessible from a touchscreen in the living room or via any browser&#xA;(mobile friendly)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;constraints&#34;&gt;Constraints&lt;/h2&gt;&#xA;&lt;p&gt;I had more or less the following rules in mind when I started thinking&#xA;about the new architecture:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Most important one: Needs to pass the WAF tests :) (for Wife&#xA;Acceptance Factor&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;)&lt;/li&gt;&#xA;&lt;li&gt;A powerful &amp;ldquo;brain&amp;rdquo; (= orchestrator) easy to configure but powerful&#xA;enough to react and connect to anything&lt;/li&gt;&#xA;&lt;li&gt;Works with [[][z-wave]] devices (As I had already a few of them:&#xA;electric plugs, smoke and flood alarms, door sensor, buttons)&lt;/li&gt;&#xA;&lt;li&gt;Lightweight communication (I was using http APIs calls before, but&#xA;this was too heavy for IoT&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;)&lt;/li&gt;&#xA;&lt;li&gt;Dashboard to control it via a touchscreen device in the living room&#xA;(I already had the hardware)&lt;/li&gt;&#xA;&lt;li&gt;Communication from outside only via chatbot&lt;/li&gt;&#xA;&lt;li&gt;A multi room sound system&lt;/li&gt;&#xA;&lt;li&gt;A music server, connected to the multi room system above.&lt;/li&gt;&#xA;&lt;li&gt;A media center system for the TV in the living room.&lt;/li&gt;&#xA;&lt;li&gt;A camera pointed to my front door for an alarm system&lt;/li&gt;&#xA;&lt;li&gt;Reuse as much as possible my &lt;a href=&#34;https://bacardi55.io/categories/homelab/&#34;&gt;home lab raspberrypi cluster&lt;/a&gt; and thus docker swarm.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;That maybe a lot, but wait until you see the list of automation in place&#xA;:D&lt;/p&gt;&#xA;&lt;h2 id=&#34;my-architecture-choices&#34;&gt;My Architecture choices&lt;/h2&gt;&#xA;&lt;p&gt;The TLDR; can be summarized in a simple visual:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/pages/home-lab/architecture.jpg&#34;&#xA;    alt=&#34;Figure 1: My Home Automation architecture&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 1: &lt;/span&gt;My Home Automation architecture&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;Ok, it may seems complicated for a home setup but it is not :). Let&amp;rsquo;s&#xA;take them piece by piece.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Brain / Orchestrator&lt;/strong&gt;: I choose &lt;a href=&#34;https://nodered.org/&#34;&gt;nodered&lt;/a&gt;&#xA;for this for multiple reasons. But I really like how simple it is to&#xA;start creating the first flow (= automation recipe) just via drag &amp;amp;&#xA;drop and some configuration :). But it is also very powerful and&#xA;almost anything can be achieved (may require Javascript coding for&#xA;some use cases though!). The community is quite active and software&#xA;is evolving quite nicely! It also didn&amp;rsquo;t hurt that there is a great&#xA;node (= nodered module) to create nice dashboards (and thus manage&#xA;nodered - the brain - with it)&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Zwave controller&lt;/strong&gt;: I was already using&#xA;&lt;a href=&#34;https://www.domoticz.com/wiki/Main_Page&#34;&gt;domoticz&lt;/a&gt; for managing&#xA;my zwave devices. I worked flawlessly for 2 years on an old rpi 2. I&#xA;decided to move it to my docker swarm cluster but keep this as my&#xA;zwave controller as it worked so well and is integrated with MQTT&#xA;too (see 3.).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Lightweight messaging&lt;/strong&gt;:&#xA;&lt;a href=&#34;https://fr.wikipedia.org/wiki/MQTT&#34;&gt;MQTT&lt;/a&gt; is the best and main&#xA;choice for this, and &lt;a href=&#34;https://mosquitto.org/&#34;&gt;Eclipe Mosquitto&lt;/a&gt; is&#xA;the most common MQTT broker used.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Dashboard&lt;/strong&gt;: As said in 1., Nodered provides this too :).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Chatbot&lt;/strong&gt;: I was already using &lt;a href=&#34;https://telegram.org&#34;&gt;Telegram&lt;/a&gt;&#xA;and don&amp;rsquo;t see reasons to change yet. I wish I could create a Signal&#xA;bot instead but it is not doable without a dedicated SIM and phone&#xA;number. So I settle to creating my own dedicated&#xA;&lt;a href=&#34;https://core.telegram.org/bots&#34;&gt;Telegram Bot&lt;/a&gt; to manage any&#xA;communication from outside (and thus also limit the available&#xA;commands available through telegram). More on this later! :)&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Multi room soud system&lt;/strong&gt;: As it is related and not really related to&#xA;my home automation system, I kept my previous system in place based&#xA;on &lt;a href=&#34;https://github.com/badaix/snapcast&#34;&gt;Snapcast&lt;/a&gt; but I have an&#xA;item in &lt;a href=&#34;https://bacardi55.io/posts/2020/04/03/manage-your-personal-project-todos-with-kanboard-and-docker-swarm/&#34;&gt;my kanboard&lt;/a&gt; to study if this is still the right solution (but to be&#xA;honest, it works really well :)).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Music server&lt;/strong&gt;: I&amp;rsquo;m using &lt;a href=&#34;https://mopidy.com/&#34;&gt;mopidy&lt;/a&gt; connected&#xA;to my spotify account. It support &lt;a href=&#34;https://www.musicpd.org/&#34;&gt;mpd&lt;/a&gt;,&#xA;has a web UI and connect to spotify. Perfect for my needs :-).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Media center&lt;/strong&gt;: &lt;a href=&#34;https://kodi.tv&#34;&gt;Kodi&lt;/a&gt; user for a long time, I&#xA;didn&amp;rsquo;t see any reasons to change yet, a bit like my sound system.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Camera&lt;/strong&gt;: Fisheye Picamera on a raspberry pi 0, controlled via MQTT&#xA;messages.&lt;/li&gt;&#xA;&lt;li&gt;Nodered, Mosquitto and Domoticz will be installed on my homelab&#xA;cluster (We&amp;rsquo;ll see how in the next posts, especially for domoticz).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;This should help understand the diagram above and this is basically it!&#xA;The heart of my system is nodered, zwave devices are managed via&#xA;domoticz and any communication between different system (including the&#xA;picamera and cec bridge&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;) is achieved via MQTT.&lt;/p&gt;&#xA;&lt;p&gt;Because I&amp;rsquo;m going to stop now before entering the interesting (setup)&#xA;and fun (automation) things, I&amp;rsquo;ll leave here one of the screen of my&#xA;dashboard, made with &lt;a href=&#34;https://flows.nodered.org/node/node-red-dashboards://flows.nodered.org/node/node-red-dashboard&#34;&gt;nodered dashboard nodes&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;figure&gt;&lt;img src=&#34;https://bacardi55.io/images/posts/2020/04/12/homeautomationp1/dashboard.png&#34;&#xA;    alt=&#34;Figure 2: My Home Automation dashboard&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 2: &lt;/span&gt;My Home Automation dashboard&lt;/p&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;p&gt;I have this dashboard in place on a touchscreen in my living room to&#xA;easily control the house from my couch :).&lt;/p&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;That&amp;rsquo;s it for now! I&amp;rsquo;ll talk in the next posts on this series about the&#xA;actual setup of the main components :). Later, I&amp;rsquo;ll start posting about&#xA;the different automation and tasks I&amp;rsquo;ve setup since! Because it will be&#xA;a series of ongoing blog posts, I&amp;rsquo;ve setup a dedicated [[][Home&#xA;Automation page]]&lt;/p&gt;&#xA;&lt;p&gt;So far, I have in mind for this set of blog posts:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Context and Architecture choices (this post :)&lt;/li&gt;&#xA;&lt;li&gt;Initial setup part1: Nodered and MQTT&lt;/li&gt;&#xA;&lt;li&gt;Initial setup part2: Domoticz&lt;/li&gt;&#xA;&lt;li&gt;MultiRoom Sound system setup&lt;/li&gt;&#xA;&lt;li&gt;PiCamera managed via MQTT&lt;/li&gt;&#xA;&lt;li&gt;TV control via CEC&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;And of course, I&amp;rsquo;ll write about the different automation flow that&#xA;manage all this :).&lt;/p&gt;&#xA;&lt;p&gt;*[IoT]: Internet of Things&lt;/p&gt;&#xA;&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;&#xA;&lt;hr&gt;&#xA;&lt;ol&gt;&#xA;&lt;li id=&#34;fn:1&#34;&gt;&#xA;&lt;p&gt;WAF: &lt;a href=&#34;https://en.wikipedia.org/wiki/Wife_acceptance_factor&#34;&gt;https://en.wikipedia.org/wiki/Wife_acceptance_factor&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li id=&#34;fn:2&#34;&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Internet_of_thingss://en.wikipedia.org/wiki/Internet_of_things&#34;&gt;https://en.wikipedia.org/wiki/Internet_of_thingss://en.wikipedia.org/wiki/Internet_of_things&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li id=&#34;fn:3&#34;&gt;&#xA;&lt;p&gt;I will write a specific post about cec bridge, which is a great&#xA;tool to command your tv via hdmi!&#xA;&lt;a href=&#34;https://github.com/michaelarnauts/cec-mqtt-bridges://github.com/michaelarnauts/cec-mqtt-bridge&#34;&gt;https://github.com/michaelarnauts/cec-mqtt-bridges://github.com/michaelarnauts/cec-mqtt-bridge&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/div&gt;&#xA;</description></item>
    <item>
      
      <title>Entering the domotic game</title><link>https://bacardi55.io/2017/03/15/entering-the-domotic-game/</link><pubDate>Wed, 15 Mar 2017 00:00:00 +0100</pubDate><author>bac@rdi55.pl (bacardi55)</author><guid>https://bacardi55.io/2017/03/15/entering-the-domotic-game/</guid><description>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;&#xA;&lt;p&gt;So far, most of the things I do with Kalliope could be considered as not&#xA;really domitic (maybe more domogeek ^^).&lt;/p&gt;&#xA;&lt;p&gt;Indeed, so far I use Kalliope to:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Get data from API (&lt;a href=&#34;https://github.com/bacardi55/google-calendar&#34;&gt;Google calendar&lt;/a&gt;, &lt;a href=&#34;https://github.com/bacardi55/kalliope-gmaps&#34;&gt;Google Maps&lt;/a&gt;, &lt;a href=&#34;https://github.com/bacardi55/kalliope-uber&#34;&gt;Uber&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;li&gt;Get &lt;a href=&#34;https://github.com/kalliope-project/kalliope_neuron_rss_reader&#34;&gt;RSS feeds&lt;/a&gt; info (lequipe.fr mainly) - &lt;a href=&#34;https://github.com/bacardi55/kalliope-web-scraper&#34;&gt;Scrap web page&lt;/a&gt;&#xA;to get content (Google news, TV program, Cinema program, joke of the&#xA;day, &amp;hellip;)&lt;/li&gt;&#xA;&lt;li&gt;Get Kalliope to reminds things using &lt;a href=&#34;https://github.com/bacardi55/kalliope-starter55/blob/master/script/reminder.py&#34;&gt;a script&lt;/a&gt; and the &lt;a href=&#34;https://github.com/bacardi55/kalliope-repeat&#34;&gt;repeat neuron&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://github.com/bacardi55/kalliope-mpd&#34;&gt;Play music&lt;/a&gt; via my &lt;a href=&#34;http://mopidy.com/&#34;&gt;mopidy&lt;/a&gt; server&lt;/li&gt;&#xA;&lt;li&gt;Play video on my &lt;a href=&#34;https://kodi.tv/&#34;&gt;Kodi&lt;/a&gt; server via &lt;a href=&#34;https://github.com/bacardi55/kalliope-starter55/blob/master/script/find-episode.sh&#34;&gt;a  script&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The last 2 items could be considered as domotic, but I consider them as&#xA;media management, but the line is grey :)&lt;/p&gt;&#xA;&lt;h2 id=&#34;domotic&#34;&gt;Domotic&lt;/h2&gt;&#xA;&lt;h3 id=&#34;what-for&#34;&gt;what for?&lt;/h3&gt;&#xA;&lt;p&gt;Usage are legions and I don&amp;rsquo;t intend to describe all of them here, just&#xA;the one I&amp;rsquo;m going to use. Bear in mind than I&amp;rsquo;m just starting so my&#xA;knowledge is limited and the devices I have are not numerous :).&lt;/p&gt;&#xA;&lt;p&gt;I have several ideas to start with, like managing internal sensors&#xA;(temp, light, motion detector, &amp;hellip;) or managing switches (Lamp, electric&#xA;plug, &amp;hellip;)&lt;/p&gt;&#xA;&lt;h3 id=&#34;how&#34;&gt;How:&lt;/h3&gt;&#xA;&lt;h4 id=&#34;the-protocol-z-wave&#34;&gt;The protocol: Z-wave&lt;/h4&gt;&#xA;&lt;p&gt;But first, I needed to find the basic of all this: How to manage these&#xA;devices from a central control point. I read online some documentation,&#xA;about protocol and devices and finally end up choosing device compatible&#xA;with the z-wave protocol, as there is the openzwave opensource lib that&#xA;seems to work well. Main issue of Z-wave is that the company behind it&#xA;are owner of the z-wave chip.&lt;/p&gt;&#xA;&lt;p&gt;I let you read online additional info on z-wave if you wish, there are a&#xA;lot about it.&lt;/p&gt;&#xA;&lt;h4 id=&#34;the-main-controller-domoticz&#34;&gt;The main controller: &lt;a href=&#34;https://domoticz.com/&#34;&gt;Domoticz&lt;/a&gt;&lt;/h4&gt;&#xA;&lt;p&gt;So I ended up buying a usb stick z-wave controller and a z-wave multi&#xA;sensor (temp/hum, light, motion detection) to start poking at it. But I&#xA;still needed an app to manage all the z-wave devices.&lt;/p&gt;&#xA;&lt;p&gt;For this, 2 solutions:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Create a neuron that leverage the openzwave python library&lt;/li&gt;&#xA;&lt;li&gt;Use a tool that manage domotic devices&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I think that the simplest, yet most powerful approach was to choose the&#xA;2nd option, and choose a software that was exactly meant to manage&#xA;domotic device. I could have choose several:&#xA;&lt;a href=&#34;https://www.jeedom.com&#34;&gt;jeedom&lt;/a&gt;, &lt;a href=&#34;http://www.openhab.org/&#34;&gt;openhab&lt;/a&gt;, &amp;lt;Home-Assistant.io&amp;gt;, &amp;hellip;&lt;/p&gt;&#xA;&lt;p&gt;I ended up choosing &lt;a href=&#34;https://domoticz.com/&#34;&gt;Domoticz&lt;/a&gt;, very light and&#xA;powerful app in C++ with a web app and a mobile app. It was very easy to&#xA;install on an old rpiB+ and to setup my z-wave sensor.&lt;/p&gt;&#xA;&lt;p&gt;It also provide &lt;a href=&#34;https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Retrieve_status_of_specific_device&#34;&gt;APIs&lt;/a&gt;&#xA;to do a lot of actions so that kalliope could send action :)&lt;/p&gt;&#xA;&lt;p&gt;APIs provide options to (non exhaustive, go to their doc page for full&#xA;API endpoints):&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Get device status (and value): Important for me to get metric from&#xA;sensor&lt;/li&gt;&#xA;&lt;li&gt;Set on/off on device: I&amp;rsquo;ll soon have a zwave electrig plug, and I want&#xA;to be able to switch it on and off via kalliope&lt;/li&gt;&#xA;&lt;li&gt;Get / Set scene/groups state: Scene and groups are option in domoticz&#xA;to regroup devices together (group mean all device has same state (on&#xA;or off) and group state can be change. Scene has only one state, but&#xA;devices can have different states).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;That&amp;rsquo;s the main I&amp;rsquo;ll start poking at, in that order!&lt;/p&gt;&#xA;&lt;h4 id=&#34;kalliope-integration&#34;&gt;Kalliope integration&lt;/h4&gt;&#xA;&lt;!--list-separator--&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Pymoticz&lt;/p&gt;&#xA;&lt;p&gt;I did find online an &lt;a href=&#34;https://github.com/EirikAskheim/pymoticz/network&#34;&gt;old python code&lt;/a&gt; to manage domoticz. I also found a more recent fork of it&#xA;&lt;a href=&#34;https://github.com/wackoracoon/pymoticz&#34;&gt;here&lt;/a&gt; that worked well.&lt;/p&gt;&#xA;&lt;p&gt;Only issue is that is was forcing the use of http and didn&amp;rsquo;t allow&#xA;https. So I &lt;a href=&#34;https://github.com/bacardi55/pymoticz&#34;&gt;forked it&lt;/a&gt; to add https support. There is &lt;a href=&#34;https://github.com/wackoracoon/pymoticz/pull/1&#34;&gt;pull request here&lt;/a&gt; to&#xA;merge it.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;!--list-separator--&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Kalliope Neuron&lt;/p&gt;&#xA;&lt;p&gt;As you would have guess, a neuron is coming up. You can find it in a&#xA;draft mode &lt;a href=&#34;https://github.com/bacardi55/kalliope-domoticz&#34;&gt;on&#xA;github&lt;/a&gt;. For now, it is very limited but in development. It does&#xA;include directly the pymoticz library so no manual addition needed&#xA;there.&lt;/p&gt;&#xA;&lt;p&gt;For now, you can only request data value from a device. So for example,&#xA;I can retrieve the temperature and the light level from the sensor.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Brain example&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      ---&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        - name: &amp;#34;domoticz-get-temp-living-room&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          signals:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            - order: &amp;#34;living room temperature&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          neurons:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            - domoticz:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                host: &amp;#34;{{domoticz_host}}&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                action: &amp;#34;get_device&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                device: &amp;#34;6&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                ssl_verify: &amp;#34;False&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                say_template: &amp;#34;Living temperature is {{devices[0][&amp;#39;Temp&amp;#39;] | safe}} degrees and humidity is {{devices[0][&amp;#39;Humidity&amp;#39;] | safe}} %&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        - name: &amp;#34;domoticz-get-lux-living-room&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          signals:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            - order: &amp;#34;brightness in living room&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          neurons:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            - domoticz:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                host: &amp;#34;{{domoticz_host}}&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                action: &amp;#34;get_device&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                device: &amp;#34;5&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                ssl_verify: &amp;#34;False&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                say_template: &amp;#34;Living room brightness is {{devices[0][&amp;#39;Data&amp;#39;] | safe}}&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;what-s-next&#34;&gt;What&amp;rsquo;s next&lt;/h2&gt;&#xA;&lt;p&gt;As I said above, there are a lot to be able to do: set on/off devices,&#xA;get / set scenes and groups, &amp;hellip; A lot of fun to have marrying Kalliopé&#xA;and domoticz :)&lt;/p&gt;&#xA;&lt;p&gt;Stay tuned!&lt;/p&gt;&#xA;</description></item>
  </channel>
</rss>
