<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Smart Home on Making Clean Tech</title><link>https://nunrg.eu/tags/smart-home/</link><description>Recent content in Smart Home on Making Clean Tech</description><generator>Hugo -- 0.136.5</generator><language>en-us</language><copyright>2024 Franci Kopač</copyright><lastBuildDate>Thu, 20 Mar 2025 12:58:48 +0100</lastBuildDate><atom:link href="https://nunrg.eu/tags/smart-home/index.xml" rel="self" type="application/rss+xml"/><item><title>Solar System Monitor Using Three Analog Dials On E-paper</title><link>https://nunrg.eu/posts/epaper-servo-gauge/</link><pubDate>Thu, 20 Mar 2025 12:58:48 +0100</pubDate><guid>https://nunrg.eu/posts/epaper-servo-gauge/</guid><description>A solar-system monitor that shows live data on three analog-style dials drawn on an e-paper display, driven by an ESP32.</description><content:encoded><![CDATA[<p>You can support me by <a href="https://medium.com/@francikopa/solar-system-monitor-using-three-analog-dials-on-e-paper-fc45434353f0">reading this article on Medium</a> or
you can buy me a beer <a href="https://paypal.me/FranciKopac?country.x=SI&amp;locale.x=en_US">here</a>.</p>
<h2 id="introduction">Introduction</h2>
<p>Last fall I came across an interesting article in <a href="https://hackaday.com/2024/11/25/e-ink-screen-combined-with-analog-dial-is-epic-win/">Hackaday</a>, where <a href="https://arnweb.nl/gitea/arne/EinkAnalog">Arne van Itersen</a> made an interesting solar power display with an analog gauge and an e-paper screen.</p>
<p>It immediately grabbed my attention because it solves the biggest problem with e-paper displays—they need a few seconds to refresh, making them unsuitable for displaying continuously changing data like solar power. A simple analog needle takes care of that problem but is limited to displaying one thing only. But if you put the needle in front of an e-paper screen, you get continuous power information from the needle. You can then use the e-paper display for displaying things that only change every few minutes, like storage battery level, daily production, and system operation mode.</p>
<p>But using an analog dial from a multimeter seemed a bit fiddly to me, and I thought about how to improve on that. Using a small servo instead would be better, because I could use needles of any size. Controlling the servos is quite simple too, I needed the ESP32 to control the e-paper display anyway. It took a weekend to put together a simple prototype for a one gauge display, which I used for my DIY EV-charger.</p>
<figure>
    <img src="/images/epaper/1semafor.jpg" alt="EV-charger display using a needle over an e-paper display">
    <figcaption>The first try, a 1-gauge display for my EV charger</figcaption>
  </figure>
  
<p>The thing worked like a charm and got me thinking about how to improve it. I was thinking about updating my solar system display for a while now, and this seemed like a good solution.</p>
<h2 id="thinking-about-the-design">Thinking About The Design</h2>
<p>One needle wasn&rsquo;t going to cut it this time—I wanted one for solar power, one for power coming from the grid, and one for the power going into the house. After thinking about it for a while, I decided to put the grid and house power servos on the left and right side of the display. The solar servo would be on the bottom. This provides some spatial logic too—power flows from the grid (left) or solar (bottom) to the house (right). I guess putting the solar need on top could also work, but that didn&rsquo;t look right to me for some reason.</p>
<p>I wanted to put the display outside, where it would be exposed to the elements, so it needed a weatherproof housing. So I had to think a bit on how to make a housing that would be both weatherproof and easy to assemble. It&rsquo;s easy to build a two part shell, but how to design it in a way you can assemble and then disassemble it easily while keeping it watertight? I decided to approach it differently. I designed a mounting plate for the servos and the e-paper display first and gave it a flange on the sides and on the bottom. Then I designed a one-piece housing with a window and a simple top cover. This housing had simple guides to hold the flanges of the mounting plate. The window can be closed using some acrylic glued with silicone to make it weatherproof. The top cover is designed to have rainproof downslopes and only needs a drop of superglue on each side to keep it in place. This makes the assembly and testing really simple, you can do everything with the mounting plate alone.</p>
<figure>
    <img src="/images/epaper/mountplate.jpg" alt="The mounting plate with installed servos, e-paper display, and connected ESP32">
    <figcaption>The assembled mounting plate, ready for testing, only the needles are missing</figcaption>
  </figure>
  
<h2 id="the-software">The Software</h2>
<p>I&rsquo;m used to Arduino, so this is what I used. E-paper in Arduino is IMO best used with the GxEPD2 library, which includes the Adafruit GFX functions, the servos are controlled using the Servo library, data exchange is done using Adafruit MQTT, and network connectivity uses WiFi.</p>
<p>The program is subscribed to several MQTT topics, containing the values for grid power, house power, solar power, solar production, battery level, and system mode. Each of these topics is linked to a callback function that triggers on topic updates. The callback functions for grid, house and solar power all move the respective servo needles. The callbacks for battery level and solar production only update the relevant global variables. Screen refresh is only directly triggered by a system mode topic change or every 10 minutes, but this updates the display with the latest data stored in the globals.</p>
<p>Startup makes a full sweep of all the needles, serving as a kind of servo calibration check, then starts the main loop. The main loop is really short and only keeps the MQTT connection alive and resets the whole thing if Wi-Fi drops.</p>
<h3 id="getting-the-data-to-the-topics">Getting the Data To the Topics</h3>
<p>The one remaining job on the software side was to get the data from my solar system to the MQTT topics. The solar system is connected to my Home Assistant installation, so it was really easy to set up some automations that publish the relevant data to MQTT topics when the relevant sensor states change. I used state changes for triggers and the MQTT Publish service to send the data to the MQTT topic. I already had a MQTT broker set up for my other projects, so I just used that one.</p>
<h2 id="build">Build</h2>
<p>Once I was satisfied with the results, it was plain sailing:</p>
<ul>
<li>3D-print the enclosure using ABS</li>
<li>Cut the acrylic to size and glue it to the enclosure using some silicone glue</li>
<li>Drill a hole for the power cable on the appropriate spot, then use some mounting glue to fix the enclosure to the wall</li>
<li>Connect the power and insert the mounting plate in the housing.</li>
</ul>
<figure>
    <img src="/images/epaper/3semafor.jpg" alt="The finished and closed enclosure">
    <figcaption>The end product on a sunny day while charging my EV. Note to self—it&#39;s really easy to scratch acrylic with screw heads 🤦‍♂️</figcaption>
  </figure>
  
<p>You can find all the relevant code and files on <a href="https://github.com/FrenkK/servo-epaper-gauge">Github</a></p>
<p>If you found this article useful, you can buy me a beer <a href="https://paypal.me/FranciKopac?country.x=SI&amp;locale.x=en_US">here</a>.</p>
]]></content:encoded></item><item><title>Wireless Control Through 800 Year Old Walls using LoRA</title><link>https://nunrg.eu/posts/lora_basics/</link><pubDate>Tue, 14 Jan 2025 08:18:04 +0100</pubDate><guid>https://nunrg.eu/posts/lora_basics/</guid><description>How to control a heating system through metre-thick heritage walls using LoRa — a wireless retrofit solution for old buildings.</description><content:encoded><![CDATA[<p>You can support me by <a href="https://medium.com/@francikopa/wireless-control-through-800-year-old-walls-using-lora-967e7168a1dc">reading this article on Medium</a></p>
<h2 id="part-1-how-to-control-a-distributed-heating-system-through-meter-thick-walls-you-are-not-allowed-to-drill">Part 1: How to control a distributed heating system through meter-thick walls you are not allowed to drill?</h2>
<figure>
    <img src="/images/lora/okno.jpg" alt="A very old restored monastery window">
    <figcaption>The monastery window, attribution: Matevz1400, CC BY-SA 4.0, via Wikimedia Commons</figcaption>
  </figure>
  
<p>A couple of years ago a friend had a problem: He is in charge of an 800-year-old monastery building now used as a conference center and an event venue. This majestic building was thoroughly renovated about 10 years ago, but the otherwise excellent new heat-pump-based underfloor heating system was missing the provisions for temperature control in individual rooms. Heating all the rooms all the time was wasteful and there was no way to set the temperature higher (e.g. in the conference hall) or lower (for custodial or temporarily unused spaces). Fortunately, the system already included the necessary underfloor heating loop valves, we just needed to find a way to control them.</p>
<p>The building spans about 100 meters with a square footprint and has very thick walls (meter or more). It is of course heritage protected as well, so drilling for new cabling was out of the question. We also really did not want to change the existing cabling; the long cable runs would be both expensive and time-consuming. We had to go wireless.</p>
<p>But there was a big problem: Wireless communication over more than 100 meters of distance and through meter-thick walls is too much for most of the known technologies, like WiFi, Zigbee, Bluetooth, etc. There is also the issue of licensing. What to do?</p>
<h2 id="lora">LoRa</h2>
<p>The solution was to use <a href="https://en.wikipedia.org/wiki/LoRa">LoRa (Long Range) technology</a>. It is a low-cost, long-range wireless communication technology that uses frequency bands from 400 to 900MHz. The LoRa protocol is much slower (kilobits instead of megabytes) than e.g. WiFi, but this is offset by the fact that it will work over distances of several kilometers in the open. Or, in our case, over 100 meters and through several thick walls. It also does not require a radio license (but you do have to check for legal limits in your area like permissible frequency bands, transmit powers, and duty cycles).</p>
<h3 id="timing">Timing</h3>
<p>LoRa transfers data at low speeds, between 0.3 to 50 kbits/s. This is not enough to visit  websites, control a robot, or listen to music, but plenty for a heating control system that needs at least several minutes to respond to changing inputs. This is why LoRa is used for  monitoring and control of remote systems like weather stations, reservoirs, and even satellites. There are many systems out there that only need to send or receive a few tens of bytes every few minutes or hours.</p>
<h3 id="complexity">Complexity</h3>
<p>The LoRa protocol is complex to implement from the ground up, but you can buy off-the-shelf gateways and sensor stations, e.g. from <a href="https://www.rakwireless.com/">RAK</a>. If you want to build custom systems, there are comprehensive software stacks and hardware modules available for all major micro-controller families, e.g. from <a href="https://www.seeedstudio.com/lora-solution.html">Seeed</a>. All this makes it possible to build a basic prototype quite quickly.</p>
<h3 id="an-iot-solution-or-a-closed-system">An IoT Solution or a Closed System?</h3>
<p>LoRa is a popular IoT solution and there are internet-connected public LoRa networks all over the world, many requiring a low-cost subscription. This makes it a great solution for mobile stations, e.g. location monitoring for machinery etc., or smaller systems where you don&rsquo;t want to set up a gateway yourself.</p>
<p>In our case, we had to install a LoRa gateway because of the difficult environment (a public network was available, but the signal would not reach the inside stations). We also have over 20 stations, so the gateway was not a big expense. And there is the issue of control system safety and reliability, both easier to achieve using own gateway.</p>
<h2 id="control-system">Control System</h2>
<h3 id="system-structure">System structure</h3>
<p>So what does the structure of the whole system look like?</p>
<figure>
    <img src="/images/lora/structure.png" alt="Structure of a control system showing a LoRa gateway in the center, connected to an application server, the temperature sensor stations, and the control stations">
    <figcaption>System Structure</figcaption>
  </figure>
  
<h3 id="application-server">Application Server</h3>
<p>The application server is the heart of the whole system. It runs on a <a href="https://www.raspberrypi.com/for-home/">Raspberry Pi</a>, runs Home Assistant, and is connected to the MQTT server in the LoRa gateway.</p>
<h3 id="home-assistant">Home Assistant</h3>
<p><img loading="lazy" src="/images/lora/homeassistant.png" alt="The Home Assistant logo"  />
</p>
<p><a href="https://www.home-assistant.io/">Home Assistant</a> is an open-source home automation platform that runs on Python. It provides many different components, including a web-based front end with authentication and integrations for climate control, MQTT, backups, data logging, and more. It provides a GUI for our whole system.</p>
<h3 id="connection-to-the-sensors-and-control-stations">Connection To the Sensors and Control Stations</h3>
<p>The LoRa gateway makes it possible to talk to all the LoRa sensors and control stations using <a href="https://mqtt.org/">MQTT</a>. Each underfloor heating valve is represented as an MQTT switch in Home Assistant, while the temperature/humidity/air quality sensors are represented as MQTT sensors. The actual temperature control is done using Home Assistant&rsquo;s <a href="https://www.home-assistant.io/integrations/climate/">Climate integration</a> as simple thermostats reading the MQTT temperature sensors and controlling the MQTT switches for underfloor heating valves.</p>
<h3 id="data-logging">Data Logging</h3>
<p>The system includes temperature, humidity, and air quality sensors. Their values are all <a href="https://www.home-assistant.io/integrations/history/">logged inside the Home Assistant system</a> and <a href="https://www.home-assistant.io/integrations/recorder/">stored in a database</a>.</p>
<h2 id="conclusion">Conclusion</h2>
<p>This article is an outline of the control system solution and I will be going into more detail in the following articles, where I will be talking about the control station design, the LoRa gateway config, and the Home Assistant config.</p>
<p>LoRa turns out to be an excellent solution for retrofitting monitoring and control into existing distributed systems, giving us the option to avoid expensive cabling and making it easier to respect the heritage protection rules.</p>
<p>Home Assistant was designed for home automation by enthusiasts but grew into a lovely  solution for diverse automation needs, including small and medium-sized HVAC and related systems. It needs some attention as the ecosystem grows and changes, but one update a year with maybe some config updates doesn&rsquo;t take a lot of time. It gives you a gorgeously looking GUI and all the features you need for control and data logging.</p>
<p>One of the larger challenges of decarbonization is the legacy systems. These will often use energy inefficiently (heating everything all the time is an excellent example) and lack things like temperature control, which is important for comfort. Sometimes, it makes sense to rebuild them completely, e.g. to replace fossil-fuel-based systems, but some legacy systems really only need some additional control. In these cases, using LoRa can be a comparatively simple and extremely low-cost solution with incredible ROI.</p>
<p>If you found this article useful, you can buy me a beer <a href="https://paypal.me/FranciKopac?country.x=SI&amp;locale.x=en_US">here</a>.</p>
]]></content:encoded></item><item><title>EV Charging With Rooftop Solar and Storage</title><link>https://nunrg.eu/posts/ev_charging_solar/</link><pubDate>Thu, 31 Oct 2024 18:00:02 +0100</pubDate><guid>https://nunrg.eu/posts/ev_charging_solar/</guid><description>How to charge an EV with rooftop solar and battery storage, using Home Assistant to maximise self-consumption and cut charging costs.</description><content:encoded><![CDATA[<p>You can support me by <a href="https://medium.com/@francikopa/ev-charging-with-rooftop-solar-and-storage-a0e1e91a7d62">reading this article on Medium</a></p>
<p>In the <a href="https://nunrg.eu/posts/ev_charging_strategies/">previous article</a> we looked at how to rationally charge EVs if you have the option to install your home own charger (<a href="https://en.wikipedia.org/wiki/Charging_station">EVSE</a>). But if you can install your home charger, chances are you can install a rooftop solar system too. And once you have that, a home storage battery is the logical next step.</p>
<p>These two investments finally let you take matters into your own hands and, combined with a heat-pump, effectively decarbonize the majority of your energy use. You will still be dependent on the grid, but instead of being dependent all the time, your dependence shrinks to 3-4 months a year, depending on the sizing and where you live. 🥳</p>
<p>But let&rsquo;s stick to EV charging for now:</p>
<h2 id="the-basic-concept">The Basic Concept</h2>
<p>The best way to explain this is to pretend you are a farmer 😃 Your rooftop solar is a bit like a farm in that it&rsquo;s dependent on the weather. When the sun is shining, your solar plant is producing kilowatts of power. When it&rsquo;s heavily overcast, rainy, or at night, you get next to no production. So when you see the sun shining brightly, charge your car!</p>
<p>This brings all kinds of advantages:</p>
<ul>
<li>The solar energy is effectively free, except for installation costs. You should recover the installation costs in <a href="https://energyefficiency.ie/blog/solar-panels-as-a-financial-investment/">6-7 years</a>.</li>
<li>Any energy you charge from your solar system is carbon neutral, expect for the carbon debt of the installation (I don&rsquo;t like greenwashing, but this happens only once as well and with rational use, it is <a href="https://hcb-solar.com.au/understanding-the-carbon-footprint-of-solar-panels/">negligible in comparison to the avoided emissions</a>).</li>
<li>You are actively contributing to your grid stability. Not only will you be a smaller burden on your grid in general, but with some automation, you can actively act as a good citizen and act to reduce grid load in peak times. Why push power into the grid if you can charge your car instead? Why charge your car with grid power at night if you could have taken advantage of the sun during the day?</li>
</ul>
<figure>
    <img src="/images/EV_charging/solarEVcharger.jpg" alt="Solar EV charging station with storage">
    <figcaption>A simple picture of the concept, credit: Electrek</figcaption>
  </figure>
  
<h2 id="the-setup">The Setup</h2>
<p>The base for this article are a solar system with storage and a controllable car charger (EVSE), connected to a Home Assistant system. I&rsquo;m going to describe a solution with a hybrid inverter, but solutions with a separate power-wall will be similar, depending on the way your power-wall is controlled.</p>
<p>The charging logic will implemented using a Python script in AppDaemon, the rest are normal integrations, automations and entities in Home Assistant.</p>
<h2 id="the-charging-strategy">The Charging Strategy</h2>
<p>There are several things to take care of here:</p>
<ul>
<li>
<p>We need to supervise the total current of the installation to prevent overloads. If you have a 3x 20A home installation, you need to take care not to exceed 20A on any of the phases at any time, regardless of the resulting grid current including solar.</p>
</li>
<li>
<p>We need to prepare separate options at least for green charging and low-cost charging.</p>
<ul>
<li>Green charging will only turn on when you have an excess of energy available and only charge the excess energy without taking any from the grid.</li>
<li>Low-cost charging will charge the car when the energy prices are low using all the available power.</li>
<li>You could also add an &ldquo;express&rdquo; mode which will give you all available power at any time while still ensuring you don&rsquo;t blow any fuses.</li>
</ul>
</li>
<li>
<p>We want to monitor the following at all times:</p>
<ul>
<li>The phase currents. If any one of them is above the installation limit, we need to reduce charging current of the EVSE.</li>
<li>The storage battery charge level. Our strategy will depend on it.</li>
<li>The power coming from/going into the storage battery. This will help us set the EVSE charging power in the green mode.</li>
<li>The power coming from/going into the grid. This will help us avoid the grid utilization penalties.</li>
<li>Status of car connection to the EVSE. This is one of the inputs when deciding whether to turn on charging.</li>
<li>The grid utilization time-slots and limits. This is again helping us to avoid the grid utilization penalties.</li>
<li>Information about consumed energy at the EVSE. This is just to know how much charge was delivered to the car.</li>
</ul>
</li>
</ul>
<h3 id="limiting-currents">Limiting Currents</h3>
<p>This is the simplest part of it all.</p>
<ol>
<li>
<p>We set a current limit, 15A in my case due to limits of the inverter. I could actually go up to 20A, but there are other things to think about outside this scope&hellip;</p>
</li>
<li>
<p>We check the phase currents of the installation every minute.</p>
<p>The interval is important: Too fast and the EVSE does not have the time to respond to current changes. Too slow and we run the risk of blowing a fuse. Fuses work relatively slowly, so you should have about 10 minutes before anything bad happens. But it&rsquo;s better to do it as fast as your car can follow. You see, when the car charger sets the current, it basically tells your car what the maximum current it can take from the EVSE. The on-board charger of the car (OBC) will then honor this limit with a certain delay depending on the manufacturer. But one minute should be ok for most cars.</p>
</li>
<li>
<p>If any of the phase currents is above the limit, we:</p>
<ol>
<li>Calculate the excess current. E.g. if we set the limit to 15A and the biggest phase current is 18A, the excess is 3A.</li>
<li>Then we check the EVSE set curent (e.g. 10A) and subtract the excess (3A) to get the needed current setting (7A).</li>
<li>Most cars can only charge with a minimum of 6A. So if the new current setting is lower than that, we need to turn off the EVSE for a while (e.g. 5 minutes). This will give the fuses some time to cool down.</li>
<li>If limit is over minimum, we set the new current limit (7A) on the EVSE.</li>
</ol>
</li>
<li>
<p>Conversely, if all the phase currents are well below the limit (more than a tolerance we set, normally just the setting resolution, i.e. 1A), we do the above steps in the other direction, increasing the EVSE current limit as needed or turning it on if we had to turn it off previously.</p>
</li>
<li>
<p>Rinse and repeat forever.</p>
</li>
</ol>
<p>This process needs to have an absolute top priority, because it is the only part that can cause problems with our installation. Any strategy we implement will be using it.</p>
<h4 id="example-code">Example Code</h4>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">currentControl</span>(self, limit):    
</span></span><span style="display:flex;"><span>    headroom <span style="color:#f92672">=</span> limit <span style="color:#f92672">+</span> CURRENT_TOLERANCE <span style="color:#f92672">-</span> INSTALLATION_MAXIMUM
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> headroom <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">0</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">#Current too high, calculate wanted charging current to compensate</span>
</span></span><span style="display:flex;"><span>      wanted_current <span style="color:#f92672">=</span> int(self<span style="color:#f92672">.</span>set_current <span style="color:#f92672">+</span> int(headroom))
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">if</span> wanted_current <span style="color:#f92672">&gt;=</span> MIN_CHARGE_CURRENT:
</span></span><span style="display:flex;"><span>        self<span style="color:#f92672">.</span>setEVSE(wanted_current)
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">elif</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>powerOff:
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># Turn off to cool off if no headroom</span>
</span></span><span style="display:flex;"><span>        self<span style="color:#f92672">.</span>powerOff <span style="color:#f92672">=</span> <span style="color:#66d9ef">True</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">elif</span> headroom <span style="color:#f92672">&gt;</span> CURRENT_TOLERANCE:
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">#Current too low, calculate wanted charging current to compensate</span>
</span></span><span style="display:flex;"><span>      wanted_current <span style="color:#f92672">=</span> int(self<span style="color:#f92672">.</span>set_current <span style="color:#f92672">+</span> headroom)
</span></span><span style="display:flex;"><span>      self<span style="color:#f92672">.</span>setEVSE(wanted_current)
</span></span></code></pre></div><p><em>This function will be called every minute, regardless of the chosen charging mode, as long as charging is active.</em></p>
<h3 id="green-charging">Green Charging</h3>
<p>Now that the current limiting is out of the way, we can start thinking about green charging.</p>
<p>The first thing to consider is whether the storage battery is at least partially charged. It will act as our buffer when setting the charging power, taking or receiving any power we will not be able to fully compensate by setting the charger current. The storage battery voltage is not an exact measurement of charge level, but close enough. So I simply decided on the lower storage battery voltage limit to enable green charging, corresponding to about 20% of it&rsquo;s capacity. I also set a hysteresis so the charging does not turn on/off repeatedly when we are near the limit. And the charging power near the limit is minimal to avoid spikes.</p>
<p>Next we must take care of proper turning on and off of the car charger. We do this by looking at the car connection status of the charger (in my case 1 means nothing is connected, 2 means connected but not charging, 3 means connected and charging). If the car is connected, but not charging, we should turn on the charger. If the car is not corrected, we should turn it off.</p>
<p>Most importantly, we need to look at the power being charged to the storage battery. This is effectively the excess solar power available and we should charge the car with it. The approach I took is simple, but works well: If the excess power exceeds a certain value (1A of charging current, i.e. 690W + losses), increase the charging current by 1A. If the excess power drops below zero (i.e. we are draining the storage battery), decrease the charging current by 1A. This approach is really simple, but it also helps to smooth out spikes that happen in the solar system due to e.g. clouds shifting quickly.</p>
<p>If you were careful, you might wonder how this works together with the current limiting. For simplicity I decided to adapt the current limiting function to take two values, the current control maximum and the charging logic maximum resulting from excess power.</p>
<p>Finally, I think it&rsquo;s useful to try to speed up the charging when the sun is plentiful. So if the storage battery is more than half-full, I simply charge with full power until it gets down to half-full. This makes the charging faster.</p>
<h4 id="example-code-1">Example Code</h4>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">doGreenCharge</span>(self):
</span></span><span style="display:flex;"><span>    <span style="color:#75715e"># Set current to minimum at start of charge, only start if voltage high</span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e"># enough, only start if enough headroom</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> self<span style="color:#f92672">.</span>battery_voltage <span style="color:#f92672">&gt;</span> (LOW_BATTERY_LIMIT <span style="color:#f92672">+</span> VOLTAGE_HYSTERESIS):
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">if</span> (self<span style="color:#f92672">.</span>vehicle_state <span style="color:#f92672">==</span> <span style="color:#ae81ff">2</span>) <span style="color:#f92672">and</span> ((MAX_INVERTER_CURRENT <span style="color:#f92672">-</span> self<span style="color:#f92672">.</span>highest_inverter_current) <span style="color:#f92672">&gt;=</span> MIN_CHARGE_CURRENT):
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (self<span style="color:#f92672">.</span>set_current <span style="color:#f92672">==</span> <span style="color:#ae81ff">0</span>) <span style="color:#f92672">or</span> (self<span style="color:#f92672">.</span>set_current <span style="color:#f92672">&gt;</span> MIN_CHARGE_CURRENT):
</span></span><span style="display:flex;"><span>          self<span style="color:#f92672">.</span>setEVSE(MIN_CHARGE_CURRENT)
</span></span><span style="display:flex;"><span>    <span style="color:#75715e"># If the battery if full enough, charge</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (self<span style="color:#f92672">.</span>battery_voltage <span style="color:#f92672">&gt;</span> LOW_BATTERY_LIMIT) <span style="color:#f92672">and</span> (self<span style="color:#f92672">.</span>vehicle_state <span style="color:#f92672">==</span> <span style="color:#ae81ff">3</span>):
</span></span><span style="display:flex;"><span>      <span style="color:#75715e"># Do the excess power control</span>
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">if</span> (self<span style="color:#f92672">.</span>battery_power<span style="color:#f92672">&lt;-</span><span style="color:#ae81ff">800</span>) <span style="color:#f92672">and</span> (self<span style="color:#f92672">.</span>greenCurrent<span style="color:#f92672">&gt;</span>MIN_CHARGE_CURRENT):
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (self<span style="color:#f92672">.</span>battery_voltage <span style="color:#f92672">&lt;</span> (LOW_BATTERY_LIMIT <span style="color:#f92672">+</span> VOLTAGE_HYSTERESIS)):
</span></span><span style="display:flex;"><span>          self<span style="color:#f92672">.</span>greenCurrent<span style="color:#f92672">=</span>MIN_CHARGE_CURRENT
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span>          self<span style="color:#f92672">.</span>greenCurrent<span style="color:#f92672">=</span>self<span style="color:#f92672">.</span>greenCurrent<span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">elif</span> (self<span style="color:#f92672">.</span>battery_power<span style="color:#f92672">&gt;</span><span style="color:#ae81ff">800</span>) <span style="color:#f92672">and</span> (self<span style="color:#f92672">.</span>greenCurrent<span style="color:#f92672">&lt;</span>MAX_INVERTER_CURRENT):
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (self<span style="color:#f92672">.</span>battery_voltage <span style="color:#f92672">&lt;</span> (LOW_BATTERY_LIMIT <span style="color:#f92672">+</span> VOLTAGE_HYSTERESIS)):
</span></span><span style="display:flex;"><span>          self<span style="color:#f92672">.</span>greenCurrent<span style="color:#f92672">=</span>MIN_CHARGE_CURRENT
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span>          self<span style="color:#f92672">.</span>greenCurrent<span style="color:#f92672">=</span>self<span style="color:#f92672">.</span>greenCurrent<span style="color:#f92672">+</span><span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>      <span style="color:#75715e"># Do full power with full storage battery</span>
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">elif</span> (self<span style="color:#f92672">.</span>battery_voltage <span style="color:#f92672">&gt;</span> HIGH_BATTERY_LIMIT):
</span></span><span style="display:flex;"><span>        self<span style="color:#f92672">.</span>greenCurrent<span style="color:#f92672">=</span>MAX_CHARGE_CURRENT
</span></span><span style="display:flex;"><span>      self<span style="color:#f92672">.</span>currentControl(MAX_INVERTER_CURRENT, self<span style="color:#f92672">.</span>greenCurrent)
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">currentControl</span>(self, limit, preference):    
</span></span><span style="display:flex;"><span>    headroom <span style="color:#f92672">=</span> limit <span style="color:#f92672">+</span> CURRENT_TOLERANCE <span style="color:#f92672">-</span> MAX_INVERTER_CURRENT
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> headroom <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">0</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">#Current too high, calculate wanted charging current to compensate</span>
</span></span><span style="display:flex;"><span>      wanted_current <span style="color:#f92672">=</span> int(self<span style="color:#f92672">.</span>set_current <span style="color:#f92672">+</span> int(headroom))
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">if</span> wanted_current <span style="color:#f92672">&gt;=</span> MIN_CHARGE_CURRENT:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> wanted_current <span style="color:#f92672">&gt;</span> preference:
</span></span><span style="display:flex;"><span>          self<span style="color:#f92672">.</span>setEVSE(preference)
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span>          self<span style="color:#f92672">.</span>setEVSE(wanted_current)
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">elif</span> <span style="color:#f92672">not</span> self<span style="color:#f92672">.</span>powerOff:
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># Turn off to cool off if no headroom</span>
</span></span><span style="display:flex;"><span>        self<span style="color:#f92672">.</span>powerOff <span style="color:#f92672">=</span> <span style="color:#66d9ef">True</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">elif</span> headroom <span style="color:#f92672">&gt;</span> CURRENT_TOLERANCE:
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">#Current too low, calculate wanted charging current to compensate</span>
</span></span><span style="display:flex;"><span>      wanted_current <span style="color:#f92672">=</span> int(self<span style="color:#f92672">.</span>set_current <span style="color:#f92672">+</span> headroom)
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">if</span> wanted_current <span style="color:#f92672">&gt;</span> preference:
</span></span><span style="display:flex;"><span>        self<span style="color:#f92672">.</span>setEVSE(preference)
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span>        self<span style="color:#f92672">.</span>setEVSE(wanted_current)
</span></span></code></pre></div><p><em>Called every minute, calls adapted currentControl function to control the charge current</em></p>
<h2 id="results">Results</h2>
<p>Let&rsquo;s look at a typical mostly sunny day using green charging:</p>
<figure>
    <img src="/images/EV_charging/curves.png" alt="The curves when the system is working">
    <figcaption>The EVSE Charging Power, the Maximum Phase Current and the Storage Battery Level When Charging on a Sunny Day</figcaption>
  </figure>
  
<p>It was a sunny day and I decided to charge up the car in green mode at around 12:20:</p>
<ul>
<li>You can see how the charging power ramps up quickly due to there being so much solar power available at around 12:30, around 8kW.</li>
<li>The power stays almost constant until around 13:20, when another large load (the oven) turns on. This in turn causes the charging power to drop to about 3.5kW due to current limiting until the oven is done. During this time, the system is unable to take all available power (the oven only works on one phase), so the storage battery gets charged up a bit.</li>
<li>At around 13:40 the oven thermostat turns off and the charging power ramps up again. There is another cycle of the oven thermostat with power reducing again due to current control. The oven is finally turned off at about 13:50.</li>
<li>After 14:00 the solar power begins to slowly drop as the afternoon begins. It is clear to see how the system reduces charging power accordingly until about 16:00. There are some short current spikes, but current control takes quick care of them.</li>
<li>At 16:30 the solar power finally drops to a value below minimal charging power and we can finally see a clear trend in the storage battery voltage. The minimal charging power is maintained until the shutoff limit is reached at about 18:15 when the charging shuts off for the day.</li>
</ul>
<p>This was in late October, so I was able to charge only 11.6kWh that day (my personal best was 39,6kWh, almost 2/3 of my Kona), but this is still enough charge to do two errands. It was free in all important aspects—I didn&rsquo;t have to pay anything, it caused no carbon emissions and the power control prevented unnecessary cycling of the storage battery. It is a win-win-win 😀
If I needed more charge that day, I could still simply turn on the cheap charging option and charge to full at night. But it turns out that with my driving, the green option is all I need from about March to about October.</p>
<h2 id="what-if-you-dont-have-storage">What If You Don&rsquo;t Have Storage?</h2>
<p>This same approach would still work if you didn&rsquo;t have a storage battery in your solar system. Instead of looking at the storage battery charging power you would have to look at grid power, but all the rest would be the same.</p>
<p>The only difference is that you would be using the grid as your battery. This means you are not worried about wear on the battery, but you can still be a good citizen and reduce your usage during the maximum grid load times. Sadly, the old-style net-metering with constant energy price does not give you any financial incentive to do that, but I&rsquo;m assuming this will change soon.</p>
<h2 id="conclusion">Conclusion</h2>
<p>This was a short description of the principles of EV charging control in a smart home installation with solar, storage battery, and a car charger. As you can see, home automation is an interesting way to reduce your carbon footprint, save energy (costs), and reduce grid load.</p>
<p>To keep thing simple, I did not discuss the grid utilization limit handling here. If there is interest, I&rsquo;ll write a separate article about that.</p>
<p>The code examples are only snippets and intended as an illustration of principle. If you are interested in details, add a comment below and let&rsquo;s discuss!</p>
<p>If you found this article useful, you can buy me a beer <a href="https://paypal.me/FranciKopac?country.x=SI&amp;locale.x=en_US">here</a>.</p>
]]></content:encoded></item><item><title>EV Charging Constraints and Strategies</title><link>https://nunrg.eu/posts/ev_charging_strategies/</link><pubDate>Sun, 27 Oct 2024 08:53:00 +0100</pubDate><guid>https://nunrg.eu/posts/ev_charging_strategies/</guid><description>The technical and economic constraints of EV charging, and practical strategies to charge cheaper, smarter and more sustainably.</description><content:encoded><![CDATA[<p>You can support me by <a href="https://medium.com/@francikopa/ev-charging-constraints-and-strategies-bf8a11e4f7d7">reading this article on Medium</a></p>
<p>Charging an EV can be really straightforward—have a charger (EVSE) installed, plug the car in and wait until the battery is full. But there is a lot more to it than that—the technical constraints, the varying costs, the desire for sustainability all play a role.</p>
<figure>
    <img src="/images/EV_charging/evplugged.jpg" alt="An EV Plugged Into a Home Charger">
    <figcaption>Looks simple, doesn&#39;t it? (Picture credit: CarPro)</figcaption>
  </figure>
  
<h2 id="technical-constraints">Technical Constraints</h2>
<h3 id="grid-connection-capacity">Grid Connection Capacity</h3>
<p>Many European single-family houses will have a hard limit on on grid connection capacity. For my own home this amounts to 230V, 3-phase, 20A per phase, i.e. 13.8kVA. Plug in any more than that and the distribution fuse blows, leaving you in the dark with an expensive addition to your next electrical bill.</p>
<p>The usual car chargers (EVSE) for family homes in Europe will have a 3x 16A (11kW) charging capacity. This is enough to charge a car at home, but it&rsquo;s not much more than the grid connection capacity of my house. So if the charger is dumb and I try to charge my car while baking some cookies, the combined current on one phase will shoot to 16A (charger) + 8A (oven) = 24 A and I&rsquo;m going to end up in the dark, with an empty battery and no cookies 🫠</p>
<h4 id="solutions">Solutions</h4>
<h5 id="buy-more-capacity">Buy More Capacity</h5>
<p>The old way of solving this would be to install bigger distribution fuses, but this is not an optimal solution and it will be expensive:</p>
<ul>
<li>Your monthly capacity cost will be bigger.</li>
<li>You might have to rewire a part of your house wiring for bigger current.</li>
<li>Depending on the utilization of the transformer in your neighborhood, you might not get the extra capacity even if you are willing to pay for it.</li>
<li>You will be paying for mostly unused capacity.</li>
</ul>
<h5 id="use-a-smart-charger">Use a Smart Charger</h5>
<p>A much better solution is to simply look at the current you are taking from the grid and take action when it exceeds the limit.</p>
<p>You can do this manually to some extent, you just need to be the nagging presence that scolds anyone who even thinks about turning on any big load while you charge your car. This should also immensely improve your relationships! 🤪</p>
<p>A much better solution is to automate this. It&rsquo;s called &ldquo;dynamic charging&rdquo; and most modern home charging stations are able to do it at least to some extent. It works like this: You have a current meter installed on the main electrical connection to your home and a mechanism of some sort regularly checks the load. If the load exceeds your limit, this mechanism (a smart home automation or a function of the charger itself) commands to charger to temporarily reduce the charging current until everything is back to normal. Your car will charge a bit slower sometimes, but you get to eat your cookies, stay warm and keep the lights on. 😃</p>
<p>These days, you can buy an off the shelf home car charger with dynamic charging support and <a href="https://www.carplug.eu/wallbox">there are a lot of models available</a>. But if you are interested in DIY solutions, I wrote an article <a href="https://nunrg.eu/posts/example_diy_charging_point/">about building one yourself</a>.</p>
<h2 id="varying-costs">Varying Costs</h2>
<h3 id="time-based-energy-costs">Time-Based Energy Costs</h3>
<p>Depending on where you live, the cost of electric energy will vary through the day. Where I live, daytime electrical energy is about 50% more expensive, so charging your car will be much cheaper at night and on weekends here.</p>
<h3 id="grid-utilization-costs">Grid Utilization Costs</h3>
<p>Depending on where you live, you might have time-slot based grid utilization costs charged extra. We just got these added to our system and they can make a major difference, a couple hundred Euro or more per year.</p>
<p>It works like this: you choose a connection capacity for each time slot and pay an upfront fixed cost for that. The busy time-slots (during office hours and daytime in winter) are really expensive per kilowatt, so it makes sense to book just enough capacity during the expensive time-slots and all the available capacity during the cheap ones. But there is a catch: if you don&rsquo;t book enough capacity, you will pay a couple of Euros for each 15 minutes you have exceeded it. It will add up quickly!</p>
<p>At first glance, this boils down to the same thing as varying energy costs—charging from grid on off-peak times is cheaper. But this cost basically forces you to really think about your energy use. If you book low capacity during expensive time-slots, you can save hundreds of Euro per year, but if you then blow through those limits, you will pay much more in penalties.</p>
<h3 id="solution">Solution</h3>
<p>Both of these issues can be taken care of manually by being careful about when you decide to charge your car. Of course, having a bit of automation can help a lot, especially with the grid utilization costs and the varying capacities in individual time slots.</p>
<p>A good automated solution will automatically limit the charging power to the capacity limits of the individual time-slots and give you an option to allow or disallow daytime charging. Most cars also have built-in charge schedulers that can help you charge them when the energy is cheaper.</p>
<h2 id="sustainability">Sustainability</h2>
<p>If you care about the climate emergency, you care about carbon intensity of the electric energy you use. In an ideal world, this would have been taken care of by the utilities for you, but we are still a long way from that.</p>
<p>Of course, many utilities are happy to sell you an &ldquo;All Renewables&rdquo; package for your electricity bill, where you pay a little extra so the energy is bought from renewable sources. I support this wholeheartedly, because it gives the energy producers the right incentives to build more renewables. On the other hand, we have to be realistic and acknowledge that you are always consuming electric energy with the average carbon intensity your grid is producing at any given time. There is no way to select for less-carbon intensive electrons, unfortunately 😞</p>
<p>This means you must think about the energy mix in your area and this is something your utility is compelled by law to report transparently. You should get a diagram showing the percentages of energy that come from coal, natural gas, nuclear, solar, hydro, wind etc with all your electricity bills.</p>
<figure>
    <img src="/images/EV_charging/energy_mix.png" alt="Energy Mix in Slovenia in 2023">
    <figcaption>The Energy Mix in Slovenia in 2023, credit SURS</figcaption>
  </figure>
  
<p>But keep in mind, this mix is an average and the actual values vary:</p>
<ul>
<li><strong>Depending on time of day:</strong> If you have a big nuclear backbone, like my country does, you will be consuming mostly nuclear at night, which is low carbon. If you don&rsquo;t, the cheaper night-time energy will probably have a much bigger carbon footprint, coming from coal and natural gas. But some countries have a lot of hydro&hellip;</li>
<li><strong>Depending on the weather:</strong> If your country has a lot of solar, daytime electricity will be almost carbon free unless the weather is bad. A rainy day can cut solar production by 80% or more.</li>
<li><strong>Then there are the seasons:</strong> Hydroelectric plants produce much more energy when the water is plentiful, e.g. in spring and fall. Solar is less plentiful in winter and the opposite holds for wind power.</li>
</ul>
<p>The good thing is, you don&rsquo;t really have to work all of this out yourself. There are services that will give you a good estimate of current carbon intensity in your area, like <a href="https://www.electricitymaps.com/">Electricity Maps</a>, which also has an API and there is even a Home Assistant integration for it.</p>
<figure>
    <img src="/images/EV_charging/carbon_intensity.png" alt="My Electricity Maps Readout">
    <figcaption>My Electricity Maps Readout</figcaption>
  </figure>
  
<h3 id="solution-1">Solution</h3>
<p>You can do a lot here if you just behave rationally. Find the data and act accordingly. But there is also the potential to automate things using the publicly available services like Electricity Maps mentioned above.</p>
<h2 id="conclusion">Conclusion</h2>
<p>EVs have the potential to strongly reduce your carbon footprint and cost per kilometer driven, if you use them rationally. But this is not trivial and there are many factors to consider.</p>
<p>If you want to do EV-charging right, you need to think at least about:</p>
<ul>
<li>Dynamic charging</li>
<li>Time-based energy costs</li>
<li>Grid utilization costs</li>
<li>The energy mix in your area</li>
<li>The variations of the energy mix because of time of day, weather and seasons</li>
</ul>
<p>Keep in mind that you can still think about your energy mix even if you are not able to charge at home. You will, of course, make sure to keep yourself mobile first, but once you take care of that, you can start thinking about other things like carbon intensity.</p>
<p>To keep this article somewhat manageable, I did not discuss other very important factors, like your driving habits, choosing an efficient car and, most importantly, alternative mobility solutions. But let&rsquo;s face it, these are way more important than any charging strategy and the one thing you should think about at the very beginning. Our dependence on cars is toxic to us and the planet, so the best car is still the one that never got built.</p>
<h2 id="the-second-conclusion">The Second Conclusion</h2>
<p>You may have noticed  I did not mention rooftop solar or home energy storage. This is intentional, for two reasons: Most people do not have rooftop solar systems. And of those that do, only few have storage. I wanted to focus on a regular home owner buying their first EV, trying to help them understand the potential and behave rationally, both in terms of costs and environmental concerns.</p>
<p>But rooftop solar, especially combined with storage, opens a whole new dimension of options. I explored these in the next article, <a href="https://nunrg.eu/posts/ev_charging_solar/">EV Charging With Rooftop Solar and Storage</a>.</p>
<p>If you found this article useful, you can buy me a beer <a href="https://paypal.me/FranciKopac?country.x=SI&amp;locale.x=en_US">here</a>.</p>
]]></content:encoded></item><item><title>The Importance of Topology in a Smart Home Installation</title><link>https://nunrg.eu/posts/smarthome_topology/</link><pubDate>Sat, 19 Oct 2024 09:47:22 +0200</pubDate><guid>https://nunrg.eu/posts/smarthome_topology/</guid><description>Why topology matters in a smart home: comparing centralised and decentralised wiring approaches, their costs, cabling and trade-offs.</description><content:encoded><![CDATA[<p>You can support me by <a href="https://medium.com/@francikopa/how-to-connect-things-the-importance-of-topology-in-a-smart-home-installation-90ce5bd84485">reading this article on Medium</a></p>
<h2 id="so-what-do-i-mean-by-topology">So What do I Mean by Topology?</h2>
<p><a href="https://en.wikipedia.org/wiki/Topology">Topology</a> can be inexpertly defined as the science of how things are connected.</p>
<p>The basic concept of our smart home installation (what is connected to what and where to put the controller(s)) turns out to be immensely important in terms of costs, flexibility, complexity, and, consequently, reliability.</p>
<h2 id="a-modern-home">A Modern Home</h2>
<p>To help explain the concept I prepared a simple schematic of a small modern home. It only has 5 residential rooms, a machine room and some external installations. Most homes will tend to be bigger (e.g. a room for the kids, etc.) and more complicated (e.g. separate fuses for outlets, solar systems, dimmable lights, etc.), but it&rsquo;s a good starting point for our discussion.</p>
<figure>
    <img src="/images/smarthome/house.png" alt="The Basics of a Modern Home">
    <figcaption>The Basics of a Modern Home</figcaption>
  </figure>
  
<p>The schematic shows the equipment of our model home, divided into seven units: five residential rooms, one machine room and the outside equipment.</p>
<p>Each unit contains the minimum equipment it needs, e.g. lights, switches, sensors, actuators, etc.</p>
<p>At the top the units are marked with the wiring requirements. E.g. 24/5/4 means a unit needs 24 wires in total (power, control and I/O), 5 of those will need control (relays), and 4 are general I/O (digital inputs, outputs, and field busses).</p>
<h2 id="the-approaches-to-smart-home-automation">The Approaches to Smart Home Automation</h2>
<h3 id="the-one-large-plc-approach">The &ldquo;One Large PLC&rdquo; Approach</h3>
<p>Years ago, smart homes were really expensive and so rich people hired contractors used to industrial automation to build them. Our model home may look complicated, but it&rsquo;s about on par with a medium-sized machine in a factory. These were traditionally built around one big PLC in a central cubicle and everything was wired from there.</p>
<figure>
    <img src="/images/smarthome/bigplcwiring.png" alt="Schematic of a smart home wired with one big PLC">
    <figcaption>Schematic of a Smart Home Wired With One Big PLC (PLC image credit: Industrial Shields)</figcaption>
  </figure>
  
<p>This seems like a pretty straightforward way of doing things, but it has some serious drawbacks:</p>
<h4 id="wiring-length-and-cost">Wiring Length and Cost</h4>
<p>Every. Single. Wire. Has to be routed from the machine room with the giant PLC cubicle to the switch, sensor, or load that needs to be connected to it. This means a lot of cable: 2.2km for our simple example, but more like 8-10km for a medium size smart home with all the bells and whistles.</p>
<p>But wire is pretty cheap compared to the whole house, right? Not really: You need to route it throughout the house using cable conduits. In a brick-built European home, this means A LOT of carving of spaces for conduits and holes into the walls, which is expensive. These conduits also need to be quite large. The wires themselves also become a noticeable expense once you go beyond a kilometer or two.</p>
<h4 id="complexity">Complexity</h4>
<p>Programming PLCs is not trivial and this is not a small installation. If you don&rsquo;t have extensive experience, this approach way will take a professional programmer and their time is expensive. You will also need to rehire them for changes to the system. This effectively means you ceded control to your smart home to somebody else. You also lost one of it&rsquo;s main advantages—the ability to easily reconfigure it.</p>
<h4 id="reliability">Reliability</h4>
<p>Industrial PLCs are really reliable, so it&rsquo;s unlikely that the control system itself will break. It&rsquo;s much more likely that a relay will fail. Depending on your PLC this can mean you have to replace the whole PLC or just an output module. The option to replace individual relays is rare.</p>
<p>The main problem with replacement of the PLC is not the cost, but the fact that you will need to rewire everything and program the PLC. This both takes time and is possibly something you will not be able to do yourself, see &ldquo;Complexity&rdquo; above. And maybe, in 10 years, your PLC model will not be available anymore and you are looking at a complete redesign of the PLC cubicle. The same goes if you decide to do a major reconfiguration (e.g. increase the number of outputs).</p>
<h4 id="reconfigurability">Reconfigurability</h4>
<p>Say you wanted to change the way you use a room or do a renovation, maybe add an extension to the house? You will most likely have to replace (<a href="https://nunrg.eu/posts/smarthome_topology/#reliabilty">Reliability</a>), rewire, and reprogram (<a href="https://nunrg.eu/posts/smarthome_topology/#complexity">Complexity</a>) the PLC, and find a good way to integrate the new wiring with the existing system. All of this is non-trivial.</p>
<h3 id="the-distributed-approach">The Distributed Approach</h3>
<p>Looking at the drawbacks of the &ldquo;One Large PLC&rdquo; approach, we can see that most of them stem from one basic feature: centralization. Everything is done in one place and this is inefficient (most centralized systems are). So how can we approach this in a better way?</p>
<p>The answer is to use several small controllers instead of the one big PLC and put them close to where we need them, typically in a small control cubicle in the room it controls. This way we only need to route an Ethernet (or other control bus) cable, and power wiring to the controllers. The individual devices are then wired directly to the local controllers, which is much simpler and shorter.</p>
<figure>
    <img src="/images/smarthome/distributed.png" alt="Schematic of a Smart Home Wired With Distributed Controllers">
    <figcaption>Schematic of a Smart Home Wired With Distributed Controllers (Raspberry Pi image credit: Botland)</figcaption>
  </figure>
  
<h4 id="wiring-length-and-cost-1">Wiring Length and Cost</h4>
<p>Let&rsquo;s compare the wiring here with the &ldquo;One Big PLC&rdquo; scenario:</p>
<ul>
<li>The total wiring length comes out to about 1.5km, which is about a third less than with the centralized approach (I count the ethernet cables as single wires, nobody would ever run individual twisted pairs separately in a conduit).</li>
<li>You can reuse the Ethernet cables for the network infrastructure you are going to need anyway (for computers, NAS, home cinema etc.)</li>
<li>The cable conduits to the local controllers can be much smaller.</li>
<li>You don&rsquo;t need the big PLC and cubicle in the machine room any more (I put the main controller, a Raspberry Pi 4 SBC, inside the Ethernet switch cubicle I needed anyway), but you do need several smaller controllers with mini installation cubicles, one in each room.</li>
</ul>
<p>All in all, you should be looking at about a 50% reduction in wiring costs.</p>
<p>Connecting the main controller and local controllers is trivial, they just need power and networking.</p>
<p>The bulk of the wiring work is needed at the local controllers. You still need to connect each switch, sensor and load directly to the local controller, but the cable runs are much shorter now, so at least wiring is less labor intensive and you can afford to be more lax when tagging the individual wires and cables.</p>
<p>With local cubicles, you get the additional benefit of having the option to do RCDs and other protections at the room level. This means that most faults will not trip the whole house, only the room affected. Lightning protectors will work better this way too, the wiring resistance between the primary and the secondary suppressor will help reduce the voltage spikes.</p>
<h4 id="complexity-1">Complexity</h4>
<p>The programming gets easier here. You can use &ldquo;smart&rdquo; (i.e. with some internal logic) or &ldquo;dumb&rdquo; (simple Modbus or MQTT relay/input boxes). Depending on the approach you take, you need to program either several small and simple controllers and/or implement some or all of the logic in your main smart home controller (e.g. Home Assistant).</p>
<p>If something fails, you deal with one room/block at the time and so the troubleshooting is much easier: Is it the local controller, programming, wiring or one of the devices? You go from hundreds to tens of potential sources of errors, especially on the code side.</p>
<h4 id="reliability-1">Reliability</h4>
<p>Both &ldquo;smart&rdquo; and &ldquo;dumb&rdquo; local controllers, as well as Linux SBCs are really reliable, as are Ethernet switches. And if something does break, they are all really cheap to replace. And if you use &ldquo;dumb&rdquo; local controllers, replacing them  simply means wiring them into the cubicle and configuring the new local controller address, a trivial repair.</p>
<h4 id="reconfigurability-1">Reconfigurability</h4>
<p>I already listed some important benefits of the distributed approach, but they pale in comparison to the improved reconfigurability:</p>
<ul>
<li>Want to build an annex or furnish an attic? Just run some Ethernet and power to the new room and add a local controller—the rest of the system stays exactly the same.</li>
<li>Want to add some new hard-wired equipment (e.g. home cinema with motorized screen, new lighting, ceiling fans, etc.) to an existing the room? If you have enough inputs/outputs on the local controller, it&rsquo;s simply a matter of wiring. If you run out of these, replacing the existing controller is much simpler that with a centralized PLC. But the simplest option of all is most often just to add an additional local controller, possibly in the same cubicle, if there is enough space, or near the new equipment.</li>
</ul>
<p>The flexibility of this approach is simply incredible.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Building a smart home is not a trivial matter, but you can make choices that make it significantly easier, cheaper, and more useable. Thinking about architecture/topology first will save you a lot of money and frustration in the long run. If you have a contractor, make sure you are on the same page on this!</p>
<p>If you found this article useful, you can buy me a beer <a href="https://paypal.me/FranciKopac?country.x=SI&amp;locale.x=en_US">here</a>.</p>
]]></content:encoded></item><item><title>An Introduction to Smart Homes</title><link>https://nunrg.eu/posts/smarthome_intro/</link><pubDate>Wed, 16 Oct 2024 11:28:21 +0200</pubDate><guid>https://nunrg.eu/posts/smarthome_intro/</guid><description>An introduction to planning a smart home: how to think about controllers, wiring, reliability and openness before you build or renovate.</description><content:encoded><![CDATA[<p>You can support me by <a href="https://medium.com/@francikopa/an-introduction-to-smart-homes-4e88b88af677">reading this article on Medium</a>.</p>
<p>When you decide to build or extensively renovate your home, you will need to do a LOT of planning. This series of posts will give you some insights on how to begin to plan your smart home installation.</p>
<h2 id="the-old-way-of-doing-things">The Old Way of Doing Things</h2>
<p>Our homes weren&rsquo;t smart until about 10, maybe 15 years ago (for some rare enthusiasts like me).</p>
<p>The old way was to run two circuits of power wiring on separate fuses to each room, one for lamps, the other for outlets. Then you would have the lamps directly hard-wired to the switches and the switches to the power circuit (using wires in cable conduits inside the walls). The outlets would be directly wired to the other power circuit.</p>
<p>For large loads (washing machine, oven, water heater) you would have a separate fuse and power circuit, again directly hard-wired to the corresponding outlet.</p>
<p>All the fuses and a RCD were collected in a main distribution box somewhere near the entrance of the house.</p>
<h3 id="pros">Pros</h3>
<ul>
<li>Simple to install</li>
<li>Minimal length of wiring, minimal costs</li>
</ul>
<h3 id="cons">Cons</h3>
<ul>
<li>Very hard to make any changes after installation, everything is hard-wired</li>
<li>Very hard to automate</li>
<li>Very hard to log useful data</li>
</ul>
<h2 id="what-is-a-smart-home-then">What Is a Smart Home Then?</h2>
<p>For me, the defining feature of a smart home installation is the fact that hard-wiring of functions is, to the extent this is sensible, replaced with software and automation elements.</p>
<p>Instead of wiring a switch directly to the lamp the old way, the switch is wired to a controller digital input and the lamp is wired to the controller relay output. When we press the switch, the controller software senses this and switches the relay, turning the lamp on or off.</p>
<figure>
    <img src="/images/smarthome/hardwire.png" alt="Hardwired v. Controlled">
    <figcaption>The Paradigm Shift</figcaption>
  </figure>
  
<p>At first glance, this seems like a really roundabout way of doing things, but it opens all kinds of possibilities:</p>
<ul>
<li>You can turn the lamp off automatically once the presence sensor is inactive for a while to save energy.</li>
<li>You can turn the lamp on automatically when someone enters the room, but only if the illumination sensor shows it&rsquo;s dark in there.</li>
<li>If you are deaf, you can set the lights to blink three times if somebody rings at the door.</li>
<li>You can turn things (e.g. heat) on or off remotely, so you come home from a long trip to a warm home.</li>
<li>You can reuse the same sensors for different purposes, e.g. presence sensors can be used for alarms, energy saving functions and comfort.</li>
</ul>
<p>The possibilities are really endless and can help you save money and energy, have more comfort, be safer, etc.</p>
<h2 id="what-are-the-main-features-of-a-well-designed-smart-home-system">What Are the Main Features of a Well Designed Smart Home System?</h2>
<h3 id="reconfigurability">Reconfigurability</h3>
<p>We all know how we try to make plans and then life happens.</p>
<p>You want to use a different switch for a certain lamp? With a good smart home system, all you need to do is change a line of a YAML file. Adding many features often entails simply installing and configuring a plugin. <a href="https://nunrg.eu/posts/smarthome_topology/">A well designed system also allows easy hardware upgrades and system extensions (e.g. adding a room) due to it&rsquo;s modular and distributed nature.</a></p>
<h3 id="reliability">Reliability</h3>
<p>Things break. A smart home will have many more parts than a traditional installations and you are certain to have a failure every now and then. It is important the system is built as resiliently as possible.</p>
<p>I cannot overstate the importance of good backup, which is the backbone of reliability in any software-controlled system. It is the difference between an utter catastrophe and an inconvenient chore once something breaks or you are hacked. <strong>Make at least daily backups of any relevant files locally</strong> (you need a NAS anyway) and <strong>invest in a good well-encrypted online backup service</strong> to backup at least the important files from there. I found <a href="https://www.idrive.com/">IDrive</a> to work on any Linux SBC and the pricing is reasonable.</p>
<p>Modularity is an important part of reliability—a <a href="https://nunrg.eu/posts/smarthome_topology/">set of several smaller subsystems</a> will be more reliable, less complex, and easier to troubleshoot than an equivalent big system. There is also an added benefit that most of the overall system will continue to work despite a part being down.</p>
<p>Another important part is wiring. Wireless connectivity can be really helpful where wiring things is impractical, but you should wire everything else. This gives you several advantages:</p>
<ul>
<li>No need for batteries. Batteries wear out and this is bad for two reasons: First there are the natural resources being wasted and secondly, a lot of e-waste comes from devices that are simply thrown away instead of replacing the battery (if that is even possible).</li>
<li>Wireless works most of the time. Wired works all the time.</li>
<li>Some devices need to be responsive: When you press a button, the lamp should light up in less than a second or you will think there is a problem. Wireless loses packets all the time and you will get weird delays/issues when you least expect them.</li>
</ul>
<h3 id="sustainability">Sustainability</h3>
<p>Sustainability has several dimensions:</p>
<h4 id="sustainable-use-of-materials">Sustainable Use of Materials</h4>
<p>Choosing the <a href="https://nunrg.eu/posts/smarthome_topology/">right system topology</a> can substantially reduce the amount of work and materials needed. This will also have knock-on effects on reliability and reconfigurability.</p>
<h4 id="sustainable-choice-of-platforms">Sustainable Choice of Platforms</h4>
<p>To put it very simply: If you are building a system that needs to work for a couple of decades, you must <strong>actively avoid any closed source products!</strong></p>
<p>15 or 20 years later, that fancy PLC will not be available to buy if you need to replace it. Even more, the programming software for it will likely not work on the future OS (Windows 17?). And since it&rsquo;s all closed source, you can&rsquo;t port or hack it. All the expensive gear and precious natural resources will go to waste and you will have to start almost from scratch.</p>
<p>Bought a cloud-enabled app-controlled EV charger? Read about <a href="https://www.theverge.com/2024/10/2/24260316/juicebox-ev-chargers-enel-x-way-closing-discontinued-app">Juicebox</a> and imagine being locked out of your smart home because somebody ran their company into the ground and simply turned off the cloud computers.</p>
<p>What will work forever? Open source software (Linux, Home Assistant and a lot more), open hardware (any Linux SBC or PC, Modbus or MQTT relay/input boxes, etc.) and open industrial communication protocols/standards (Modbus, RS232, RS485, Ethernet, MQTT, and a lot more). If something breaks, these are cookie-cutter modules—even if the one you want to replace is not available anymore, just buy a similar one and reconfigure (RaspberryPi 12 is sure to happen someday).</p>
<h4 id="sustainable-use-of-energy">Sustainable Use of Energy</h4>
<p>As you are planning your home, remember that efficiency pays for itself quickly. Buy better performing machines, but don&rsquo;t pay extra for gimmicks:</p>
<ul>
<li>Better home insulation will be more expensive, but then you need a smaller and cheaper heat pump, air conditioning, etc., so it should pay for itself.</li>
<li>A heat pump does not need a fancy app to control it, just a Modbus interface for your system and the best COP you can afford.</li>
<li>Invest in ventilation with heat recuperation. Or live with mold. Forget about apps, choose the model with efficient motors and some kind of communication interface. An integrated CO2/VOC sensor is a plus, so you only run it when needed.</li>
<li>Buy an EV charger that will be locally controllable (i.e. it has a control interface) by your smart-home system so you can charge efficiently. Or <a href="https://nunrg.eu/posts/diy_ev_charging/">build one yourself</a>.</li>
<li>Some EVs will consume 12kWh/100km, some will consume 25. Buy what you need, but not more. Same size cars from different manufacturers can have very different consumption. Why am I including your car in this article about smart homes? It will be a major consumer of energy, but also has the potential for a LOT of optimization, from smart charging control to <a href="https://en.wikipedia.org/wiki/Vehicle-to-grid">V2G</a>. Most important: For the love of Earth, don&rsquo;t replace it until it stops working or you <em>really</em> need a different one. Buying a new car every few years is easily the most expensive habit of your life and a colossal waste of resources.</li>
<li>Heating/air-conditioning is easily your biggest energy consumer. Install temperature and humidity sensors in all the residential rooms and make the heating controllable so you can only use the energy you really need.</li>
</ul>
<h2 id="questions-you-need-to-ask-yourself">Questions You Need To Ask Yourself</h2>
<p>Having a smart home can save you money, increase comfort and safety, and make your life more sustainable, mainly by reducing your energy consumption. But there are some important questions:</p>
<ul>
<li>Could you build it yourself, even if you choose to use a contractor?</li>
<li>If not, do you understand it well enough to communicate your desires, needs, and concepts to the contractor?</li>
<li>Do you trust the contractor?</li>
<li>Is the design clear and well-documented enough for somebody else to continue maintaining the system in case you want to change the contractor?</li>
<li>Are you able to reconfigure the system yourself after it is built or will you need ongoing support here as well? What about repairs?</li>
<li>Have you thought enough about the sustainability of the system?</li>
<li>Did you avoid pitfalls related to closed systems?</li>
</ul>
<p>Be honest with yourself, the answers to these questions are important! Depending on them, your smart home can be an awesome thing or a source of SEVERE frustration. Good luck!</p>
<p>If you found this article useful, you can buy me a beer <a href="https://paypal.me/FranciKopac?country.x=SI&amp;locale.x=en_US">here</a>.</p>
]]></content:encoded></item><item><title>Wiznet220IO Configuration Tool Problems in Windows 11</title><link>https://nunrg.eu/posts/wiznet/</link><pubDate>Thu, 16 Feb 2023 00:00:00 +0000</pubDate><guid>https://nunrg.eu/posts/wiznet/</guid><description>The Wiznet220IO configuration tool 1.1.2 fails on Windows 11 — a quick fix using compatibility mode to get the legacy tool running again.</description><content:encoded><![CDATA[<h2 id="wiznet220io-configuration-tool-112-does-not-work-in-windows-11-but-you-can-fix-it-using-compatibility-mode">Wiznet220IO Configuration Tool 1.1.2 Does Not Work in Windows 11, But You Can Fix it Using Compatibility Mode</h2>
<p><img loading="lazy" src="/images/wiznet.png" alt="Wiznet config page"  />
</p>
<p>If you happen to use the Wiznet220UI modules like me, you may have noticed that the configuration tool stopped working in Windows 11. As it starts up, there is a strange error message (it was probably originally written in Chinese and my OS does not know how to display that properly).</p>
<p>You can fix this by right-clicking the tool shortcut, choosing <em>Open in folder</em>, then right-clicking the shortcut, selecting <em>Properties</em> and then selecting the <em>Compatibility</em> tab. In my case, I set the compatibility to <em>Windows 8</em> and it started up normally. But it did not find any modules when I clicked <em>Search</em>. As I closed the files, Windows asked me if compatibility settings worked. I answered <em>No</em> and it set some different compatibility settings that solved all the problems.</p>
<p>It’s not rocket science, but it works 🙂</p>
<p>It is also a good reminder that most software tools will simply stop working in about a decade or so, unless the author is really diligent about updating them regularly. This will usually not matter for computer software like image and document editors, but it becomes <em>very</em> relevant when you are, for example, building a smart home; you probably don&rsquo;t want to strip all the hardware out every 10 years or so just because the configuration software is out of date.</p>
]]></content:encoded></item></channel></rss>