<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>die-welt.net (Posts about home-automation)</title><link>https://www.die-welt.net/</link><description></description><atom:link href="https://www.die-welt.net/category/home-automation.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2026 &lt;a href="mailto:evgeni@golov.de"&gt;evgeni&lt;/a&gt; </copyright><lastBuildDate>Fri, 06 Mar 2026 14:03:30 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Home Assistant, Govee Lights Local, VLANs, Oh my!</title><link>https://www.die-welt.net/2025/12/home-assistant-govee-lights-local-vlans-oh-my/</link><dc:creator>evgeni</dc:creator><description>&lt;p&gt;We recently bought some &lt;a href="https://eu.govee.com/products/govee-glide-hexa-light-panels"&gt;Govee Glide Hexa Light Panels&lt;/a&gt;, because they have a &lt;a href="https://app-h5.govee.com/user-manual/wlan-guide"&gt;local LAN API&lt;/a&gt; that is &lt;a href="https://www.home-assistant.io/integrations/govee_light_local/"&gt;well integrated into Home Assistant&lt;/a&gt;.
Or so we thought.&lt;/p&gt;
&lt;p&gt;Our network is not &lt;em&gt;that&lt;/em&gt; complicated, but there is a dedicated VLAN for IOT devices.
Home Assistant runs in a container (with &lt;code&gt;network=host&lt;/code&gt;) on a box in the basement, and that box has a NIC in the IOT VLAN so it can reach devices there easily.
So far, this has never been a problem.&lt;/p&gt;
&lt;p&gt;Enter the Govee LAN API.
Or maybe its &lt;a href="https://pypi.org/project/govee-local-api/"&gt;Python implementation&lt;/a&gt;.
Not exactly sure who's to blame here.&lt;/p&gt;
&lt;p&gt;The API involves sending JSON over multicast, which the Govee device will answer to.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;No devices found on the network&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;After turning logging for &lt;code&gt;homeassistant.components.govee_light_local&lt;/code&gt; to 11, erm &lt;code&gt;debug&lt;/code&gt;, we see:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;DEBUG (MainThread) [homeassistant.components.govee_light_local.config_flow] Starting discovery with IP 192.168.42.2
DEBUG (MainThread) [homeassistant.components.govee_light_local.config_flow] No devices found with IP 192.168.42.2
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;That's not the IP address in the IOT VLAN!&lt;/p&gt;
&lt;p&gt;Turns out the integration &lt;a href="https://github.com/home-assistant/core/pull/128123"&gt;recently got support for multiple NICs&lt;/a&gt;,
but Home Assistant doesn't just use all the interfaces it sees by default.&lt;/p&gt;
&lt;p&gt;You need to go to &lt;em&gt;Settings&lt;/em&gt; → &lt;em&gt;Network&lt;/em&gt; → &lt;em&gt;Network adapter&lt;/em&gt; and deselect "Autoconfigure",
which will allow your to select individual interfaces.&lt;/p&gt;
&lt;p&gt;Once you've done that, you'll see &lt;code&gt;Starting discovery with IP&lt;/code&gt; messages for all selected interfaces and adding of Govee Lights Local will work.&lt;/p&gt;</description><category>english</category><category>home-automation</category><category>linux</category><category>planet-debian</category><category>software</category><guid>https://www.die-welt.net/2025/12/home-assistant-govee-lights-local-vlans-oh-my/</guid><pubDate>Sun, 14 Dec 2025 15:48:08 GMT</pubDate></item><item><title>Controlling Somfy roller shutters using an ESP32 and ESPHome</title><link>https://www.die-welt.net/2021/06/controlling-somfy-roller-shutters-using-an-esp32-and-esphome/</link><dc:creator>evgeni</dc:creator><description>&lt;p&gt;Our house has solar powered, remote controllable roller shutters on the roof windows, built by the German company named HEIM &amp;amp; HAUS. However, when you look closely at the remote control or the shutter motor, you'll see another brand name: SIMU. As the shutters don't have any wiring inside the house, the only way to control them is via the remote interface. So let's go on the Internet and see how one can do that, shall we? ;)&lt;/p&gt;
&lt;p&gt;First thing we learn is that SIMU remote stuff is just re-branded Somfy. Great, another name! Looking further we find that Somfy uses &lt;a href="https://pushstack.wordpress.com/somfy-rts-protocol/"&gt;some obscure protocol to prevent (replay) attacks&lt;/a&gt; (spoiler: it doesn't!) and there are tools for &lt;a href="https://pushstack.wordpress.com/2014/05/17/somfy-rtl-sdr/"&gt;RTL-SDR&lt;/a&gt; and &lt;a href="https://github.com/Nickduino/Somfy_Remote"&gt;Arduino&lt;/a&gt; available. That's perfect!&lt;/p&gt;
&lt;h3&gt;Always sniff with RTL-SDR first!&lt;/h3&gt;
&lt;p&gt;Given the two re-brandings in the supply chain, I wasn't 100% sure our shutters really use the same protocol. So the first "hack" was to listen and decrypt the communication using RTL-SDR:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;git&lt;span class="w"&gt; &lt;/span&gt;clone&lt;span class="w"&gt; &lt;/span&gt;https://github.com/dimhoff/radio_stuff
&lt;span class="gp"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;radio_stuff
&lt;span class="gp"&gt;$ &lt;/span&gt;make&lt;span class="w"&gt; &lt;/span&gt;-C&lt;span class="w"&gt; &lt;/span&gt;converters&lt;span class="w"&gt; &lt;/span&gt;am_to_ook
&lt;span class="gp"&gt;$ &lt;/span&gt;make&lt;span class="w"&gt; &lt;/span&gt;-C&lt;span class="w"&gt; &lt;/span&gt;decoders&lt;span class="w"&gt; &lt;/span&gt;decode_somfy
&lt;span class="gp"&gt;$ &lt;/span&gt;rtl_fm&lt;span class="w"&gt; &lt;/span&gt;-M&lt;span class="w"&gt; &lt;/span&gt;am&lt;span class="w"&gt; &lt;/span&gt;-f&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;433&lt;/span&gt;.42M&lt;span class="w"&gt; &lt;/span&gt;-s&lt;span class="w"&gt; &lt;/span&gt;270K&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;./converters/am_to_ook&lt;span class="w"&gt; &lt;/span&gt;-d&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-t&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;2000&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;./decoders/decode_somfy
&lt;span class="go"&gt;&amp;lt;press some buttons on the remote&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The output contains the buttons I pressed, but also the id of the remote and the command counter (which is supposed to prevent replay attacks). At this point I could just use the id and the counter to send own commands, but if I'd do that too often, the real remote would stop working, as its counter won't increase and the receiver will drop the commands when the counters differ too much.&lt;/p&gt;
&lt;p&gt;But that's good enough for now. I know I'm looking for the right protocol at the right frequency. As the end result should be an ESP32, let's move on!&lt;/p&gt;
&lt;h3&gt;Acquiring the right hardware&lt;/h3&gt;
&lt;p&gt;Contrary to an RTL-SDR, one usually does not have a spare ESP32 with 433MHz radio at home, so I went shopping: a NodeMCU-32S clone and a CC1101. The CC1101 is important as most 433MHz chips for Arduino/ESP only work at 433.92MHz, but Somfy uses 433.42MHz and using the wrong frequency would result in really bad reception. The CC1101 is essentially an SDR, as you can tune it to a huge spectrum of frequencies.&lt;/p&gt;
&lt;p&gt;Oh and we need some cables, a bread board, the usual stuff ;)&lt;/p&gt;
&lt;p&gt;The wiring is rather simple:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://raw.githubusercontent.com/LSatan/SmartRC-CC1101-Driver-Lib/50512abf62a4b86c457426f142ae05d1faff5aa3/img/Esp32_CC1101.png"&gt;&lt;img alt="ESP32 wiring for a CC1101" src="https://raw.githubusercontent.com/LSatan/SmartRC-CC1101-Driver-Lib/50512abf62a4b86c457426f142ae05d1faff5aa3/img/Esp32_CC1101.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And the end result isn't too beautiful either, but it works:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.die-welt.net/upload/esp32_cc1101.jpg"&gt;&lt;img alt="ESP32 and CC1101 in a simple case" src="https://www.die-welt.net/upload/esp32_cc1101.jpg"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: I've been told (by Bert, hi Bert!) that there are now slightly different &lt;a href="https://nl.aliexpress.com/item/1005005933665919.html"&gt;CC1101 boards sold on the internet&lt;/a&gt;. Mine has 10 pins, but VCC and GND are doubled. The new boards just don't have these double pins anymore and have only 8 in total. They still work, you just need to look where which pin is. :)&lt;/p&gt;
&lt;h3&gt;Acquiring the right software&lt;/h3&gt;
&lt;p&gt;In my initial research I found an Arduino sketch and was totally prepared to port it to ESP32, but luckily &lt;a href="https://github.com/Legion2/Somfy_Remote_Lib"&gt;somebody already did that for me&lt;/a&gt;! Even better, it's explicitly using the CC1101. Okay, okay, I cheated, I actually ordered the hardware &lt;em&gt;after&lt;/em&gt; I found &lt;a href="https://github.com/EinfachArne/Somfy_Remote"&gt;this&lt;/a&gt; port and the reference to CC1101. ;)&lt;/p&gt;
&lt;p&gt;As I am using &lt;a href="https://esphome.io"&gt;ESPHome&lt;/a&gt; for my ESPs, the idea was to add a "Cover" that's controlling the shutters to it. Writing some C++, how hard can it be?&lt;/p&gt;
&lt;p&gt;Turns out, not &lt;em&gt;that&lt;/em&gt; hard. You can see the code in my &lt;a href="https://github.com/evgeni/esphome-configs/"&gt;GitHub repo&lt;/a&gt;. It consists of two (relevant) files: &lt;a href="https://github.com/evgeni/esphome-configs/blob/devel/somfy_cover.h"&gt;&lt;code&gt;somfy_cover.h&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://github.com/evgeni/esphome-configs/blob/devel/somfy.yaml"&gt;&lt;code&gt;somfy.yaml&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;somfy_cover.h&lt;/code&gt; essentially wraps the communication with the &lt;code&gt;Somfy_Remote_Lib&lt;/code&gt; library into an almost boilerplate &lt;a href="https://esphome.io/components/cover/custom.html"&gt;Custom Cover for ESPHome&lt;/a&gt;. There is nothing too fancy in there. The only real difference to the "Custom Cover" example from the documentation is the split into &lt;code&gt;SomfyESPRemote&lt;/code&gt; (which inherits from &lt;code&gt;Component&lt;/code&gt;) and &lt;code&gt;SomfyESPCover&lt;/code&gt; (which inherits from &lt;code&gt;Cover&lt;/code&gt;) -- this is taken from the &lt;a href="https://esphome.io/components/sensor/custom.html#bonus-sensors-with-multiple-output-values"&gt;Custom Sensor documentation&lt;/a&gt; and allows me to define one "remote" that controls multiple "covers" using the &lt;code&gt;add_cover&lt;/code&gt; function. The first two params of the function are the NVS name and key (think database table and row), and the third is the rolling code of the remote you're building (stored in &lt;code&gt;somfy_secrets.h&lt;/code&gt;, which is not in Git). Don't use the code of an existing remote, or the rolling code counter will get out of sync and neither the original remote, nor your fake will work anymore.&lt;/p&gt;
&lt;p&gt;In ESPHome a &lt;code&gt;Cover&lt;/code&gt; shall define its properties as &lt;code&gt;CoverTraits&lt;/code&gt;. Here we call &lt;code&gt;set_is_assumed_state(true)&lt;/code&gt;, as we don't know the state of the shutters - they could have been controlled using the other (real) remote - and setting this to &lt;code&gt;true&lt;/code&gt; allows issuing open/close commands at all times. We also call &lt;code&gt;set_supports_position(false)&lt;/code&gt; as we can't tell the shutters to move to a specific position.&lt;/p&gt;
&lt;p&gt;The one additional feature compared to a normal &lt;code&gt;Cover&lt;/code&gt; interface is the &lt;code&gt;program&lt;/code&gt; function, which allows to call the "program" command so that the shutters can learn a new remote.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;somfy.yaml&lt;/code&gt; is the ESPHome "configuration", which contains information about the used hardware, WiFi credentials etc. Again, mostly boilerplate. The interesting parts are the loading of the additional libraries and attaching the custom component with multiple covers and the additional &lt;code&gt;PROG&lt;/code&gt; switches:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nt"&gt;esphome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;somfy&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;ESP32&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nt"&gt;board&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;nodemcu-32s&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nt"&gt;libraries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;SmartRC-CC1101-Driver-Lib@2.5.6&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;Somfy_Remote_Lib@0.4.0&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;EEPROM&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nt"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;somfy_secrets.h&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;somfy_cover.h&lt;/span&gt;
&lt;span class="l l-Scalar l-Scalar-Plain"&gt;…&lt;/span&gt;

&lt;span class="nt"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;custom&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p p-Indicator"&gt;|-&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;auto somfy_remote = new SomfyESPRemote();&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;somfy_remote-&amp;gt;add_cover("somfy", "badezimmer", SOMFY_REMOTE_BADEZIMMER);&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;somfy_remote-&amp;gt;add_cover("somfy", "kinderzimmer", SOMFY_REMOTE_KINDERZIMMER);&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;App.register_component(somfy_remote);&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;return somfy_remote-&amp;gt;covers;&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;covers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"somfy"&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Somfy&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Cover"&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"somfy2"&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Somfy&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Cover2"&lt;/span&gt;

&lt;span class="nt"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;template&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"PROG"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;turn_on_action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p p-Indicator"&gt;|-&lt;/span&gt;
&lt;span class="w"&gt;          &lt;/span&gt;&lt;span class="no"&gt;((SomfyESPCover*)id(somfy))-&amp;gt;program();&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;template&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"PROG2"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;turn_on_action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p p-Indicator"&gt;|-&lt;/span&gt;
&lt;span class="w"&gt;          &lt;/span&gt;&lt;span class="no"&gt;((SomfyESPCover*)id(somfy2))-&amp;gt;program();&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The switch to trigger the program mode took me a bit. As the Cover interface of ESPHome does not offer any additional functions besides movement control, I first wrote code to trigger "program" when "stop" was pressed three times in a row, but that felt really cumbersome and also had the side effect that the remote would send more than needed, sometimes confusing the shutters. I then decided to have a separate button (well, switch) for that, but the compiler yelled at me I can't call &lt;code&gt;program&lt;/code&gt; on a &lt;code&gt;Cover&lt;/code&gt; as it does not have such a function. Turns out, you need to explicitly cast to &lt;code&gt;SomfyESPCover&lt;/code&gt; and then it works, even if the code becomes really readable, NOT. Oh and as the switch does not have any code to actually change/report state, it effectively acts as a button that can be pressed.&lt;/p&gt;
&lt;p&gt;At this point we can just take an existing remote, press PROG for 5 seconds, see the blinds move shortly up and down a bit and press PROG on our new ESP32 remote and the shutters will learn the new remote.&lt;/p&gt;
&lt;p&gt;And thanks to the awesome integration of ESPHome into HomeAssistant, this instantly shows up as a new controllable cover there too.&lt;/p&gt;
&lt;h3&gt;&lt;del&gt;Future&lt;/del&gt; Additional Work&lt;/h3&gt;
&lt;p&gt;I started writing this post about a year ago… And the initial implementation had some room for improvement…&lt;/p&gt;
&lt;h4&gt;More than one remote&lt;/h4&gt;
&lt;p&gt;The &lt;a href="https://github.com/evgeni/esphome-configs/blob/6ab67057d8bdd609e55c4f7ae593234f416c6119/somfy_cover.h"&gt;initial&lt;/a&gt; code only created one remote and one cover element. Sure, we could attach that to all shutters (there are 4 of them), but we really want to be able to control them separately.&lt;/p&gt;
&lt;p&gt;Thankfully I managed to read enough ESPHome docs, and learned how to operate &lt;code&gt;std::vector&lt;/code&gt; to make the code dynamically accept new shutters.&lt;/p&gt;
&lt;h4&gt;Using ESP32's NVS&lt;/h4&gt;
&lt;p&gt;The ESP32 has a &lt;a href="https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/nvs_flash.html"&gt;non-volatile key-value storage&lt;/a&gt; which is much nicer than throwing bits at an emulated EEPROM. The first library I used for that explicitly used EEPROM storage and it would have required quite some hacking to make it work with NVS. Thankfully the library I am using now has a plugable storage interface, and &lt;a href="https://github.com/Legion2/Somfy_Remote_Lib/pull/8"&gt;I could just write the NVS backend myself&lt;/a&gt; and upstream now supports that. Yay open-source!&lt;/p&gt;
&lt;h4&gt;A 3d-printed case&lt;/h4&gt;
&lt;p&gt;I've just put my setup in a junction box and called it a day.
&lt;a href="https://www.printables.com/@BertHaverkamp_15340"&gt;Bert&lt;/a&gt; decided that's not good enough (and he's right!), so he designed &lt;a href="https://www.printables.com/model/996065-somfy-controler-box"&gt;a nice 3D-printable case&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I think I might just print that one for me too. Looks so much better!&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.die-welt.net/upload/esp32_cc1101_printed_bert.webp"&gt;&lt;img alt="ESP32 and CC1101 in a 3D-printed case" src="https://www.die-welt.net/upload/esp32_cc1101_printed_bert.webp"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Remaining issues&lt;/h3&gt;
&lt;h4&gt;Real state is unknown&lt;/h4&gt;
&lt;p&gt;As noted above, the ESP does not know the real state of the shutters: a command could have been lost in transmission (the Somfy protocol is send-only, there is no feedback) or the shutters might have been controlled by another remote. At least the second part &lt;em&gt;could&lt;/em&gt; be solved by listening all the time and trying to decode commands heard over the air, but I don't think this is worth the time -- worst that can happen is that a closed (opened) shutter receives another close (open) command and that is harmless as they have integrated endstops and know that they should not move further.&lt;/p&gt;
&lt;h4&gt;Can't program new remotes with ESP only&lt;/h4&gt;
&lt;p&gt;To program new remotes, one has to press the "PROG" button for 5 seconds. This was not exposed in the old library, but the new one does support "long press", I just would need to add another ugly &lt;code&gt;switch&lt;/code&gt; to the config and I currently don't plan to do so, as I do have working remotes for the case I need to learn a new one.&lt;/p&gt;</description><category>english</category><category>hardware</category><category>home-automation</category><category>planet-debian</category><guid>https://www.die-welt.net/2021/06/controlling-somfy-roller-shutters-using-an-esp32-and-esphome/</guid><pubDate>Sun, 06 Jun 2021 09:22:27 GMT</pubDate></item><item><title>Building a Shelly 2.5 USB to TTL adapter cable</title><link>https://www.die-welt.net/2020/05/building-a-shelly-25-usb-to-ttl-adapter-cable/</link><dc:creator>evgeni</dc:creator><description>&lt;p&gt;When you want to flash your Shelly 2.5 with anything but the original firmware for the first time, you'll need to attach it to your computer. Later flashes can happen over the air (at least with ESPHome or Tasmota), but the first one cannot.&lt;/p&gt;
&lt;p&gt;In theory, this is not a problem as the Shelly has a quite exposed and well documented interface:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Shelly 2.5 pinout" src="https://shelly.cloud/wp-content/uploads/2020/06/pin_out.png"&gt;&lt;/p&gt;
&lt;p&gt;However, on closer inspection you'll notice that your normal jumper wires don't fit as the Shelly has a connector with 1.27mm (0.05in) pitch and 1mm diameter holes.&lt;/p&gt;
&lt;p&gt;Now, there are various tutorials on the Internet how to build a compatible connector using &lt;a href="https://tasmota.github.io/docs/devices/Shelly-2.5/"&gt;Ethernet cables and hot glue or with female header socket legs&lt;/a&gt;, and you can even buy &lt;a href="https://www.amazon.de/dp/B07TS2KPW7/"&gt;cables on Amazon for 18€&lt;/a&gt;! But 18€ sounded like a lot and the female header socket thing while working was pretty finicky to use, so I decided to build something different.&lt;/p&gt;
&lt;p&gt;We'll need 6 female-to-female jumper wires and a 1.27mm pitch male header. Jumper wires I had at home, the header I got is a &lt;a href="https://www.reichelt.de/20pol-stiftleiste-gerade-rm-1-27-sl-1x20g-1-27-p51694.html"&gt;SL 1X20G 1,27 from reichelt.de&lt;/a&gt; for 0.61€. It's a 20 pin one, so we can make 3 adapters out of it if needed. Oh and we'll need some isolation tape.&lt;/p&gt;
&lt;p&gt;&lt;img alt="SL 1X20G 1,27" src="https://www.die-welt.net/upload/shelly/SL1X20G.jpg"&gt;&lt;/p&gt;
&lt;p&gt;The first step is to cut the header into 6 pin chunks. Make sure not to cut too close to the 6th pin as the whole thing is rather fragile and you might lose it.&lt;/p&gt;
&lt;p&gt;&lt;img alt="SL 1X20G 1,27 cut into pieces" src="https://www.die-welt.net/upload/shelly/SL1X20G_cut.jpg"&gt;&lt;/p&gt;
&lt;p&gt;It now fits very well into the Shelly with the longer side of the pins.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Shelly 2.5 with pin headers attached" src="https://www.die-welt.net/upload/shelly/shelly_with_pins.jpg"&gt;&lt;/p&gt;
&lt;p&gt;Second step is to strip the plastic part of one side of the jumper wires. Those are designed to fit 2.54mm pitch headers and won't work for our use case otherwise.&lt;/p&gt;
&lt;p&gt;&lt;img alt="jumper wire with removed plastic" src="https://www.die-welt.net/upload/shelly/jumper_wire_remove.jpg"&gt;&lt;/p&gt;
&lt;p&gt;As the connectors are still too big, even after removing the plastic, the next step is to take some pliers and gently press the connectors until they fit the smaller pins of our header.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Shelly 2.5 with pin headers and a jumper wire attached" src="https://www.die-welt.net/upload/shelly/shelly_with_pins_and_cable.jpg"&gt;&lt;/p&gt;
&lt;p&gt;Now is the time to put everything together. To avoid short circuiting the pins/connectors, apply some isolation tape while assembling, but not too much as the space is really limited.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Shelly 2.5 with pin headers and a jumper wire attached and taped" src="https://www.die-welt.net/upload/shelly/shelly_with_pins_and_cable_and_tape.jpg"&gt;&lt;/p&gt;
&lt;p&gt;And we're done, a wonderful (lol) and working (yay) Shelly 2.5 cable that can be attached to any USB-TTL adapter, like the pictured FTDI clone you get almost everywhere.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Shelly 2.5 with full cable and FTDI attached" src="https://www.die-welt.net/upload/shelly/shelly_with_ftdi.jpg"&gt;&lt;/p&gt;
&lt;p&gt;Yes, in an ideal world we would have soldered the header to the cable, but I didn't feel like soldering on that limited space. And yes, shrink-wrap might be a good thing too, but again, limited space and with isolation tape you only need one layer between two pins, not two.&lt;/p&gt;</description><category>english</category><category>hardware</category><category>home-automation</category><category>planet-debian</category><guid>https://www.die-welt.net/2020/05/building-a-shelly-25-usb-to-ttl-adapter-cable/</guid><pubDate>Tue, 12 May 2020 10:44:35 GMT</pubDate></item><item><title>Controlling roller shutters using a Shelly 2.5, ESPHome and Home Assistant</title><link>https://www.die-welt.net/2020/04/controlling-roller-shutters-using-a-shelly-25-esphome-and-home-assistant/</link><dc:creator>evgeni</dc:creator><description>&lt;p&gt;Our house has roller shutters on all windows and most of them have an electric motor to open and close them. The motors are Schellenberg shaft motors (not sure this is the right English term), that you can configure end positions for and then by applying current to the right pair of pins they move the shutters up and down until the current is removed or one of the endstops is reached. As the motors were installed over a long period of time, the attached control units varied in functionality: different ways to program open/close times, with and without battery for the clock/settings etc, but they all had something in common: no central management and pretty ugly. We decided to replace those control units with regular 2 gang light switches that match the other switches in the house. And as we didn't want to lose the automatic open/close timer, we had to add some smarts to it.&lt;/p&gt;
&lt;h3&gt;Shelly 2.5 and ESPHome&lt;/h3&gt;
&lt;p&gt;Say hello to &lt;a href="https://shelly.cloud/shelly-25-wifi-smart-relay-roller-shutter-home-automation/"&gt;Shelly 2.5&lt;/a&gt;! The Shelly 2.5 is an ESP8266 with two relays attached to it in a super tiny package you can hide in the wall behind a regular switch. Pretty nifty. It originally comes with a &lt;a href="https://mongoose-os.com/"&gt;Mongoose OS&lt;/a&gt; based firmware and an own app, but ain't nobody needs that, especially nobody who wants to implement some crude logic. That said, the original firmware isn't bad. It has a no-cloud mode, a REST API and does support MQTT for integration into Home Assistant and others.&lt;/p&gt;
&lt;p&gt;My ESP firmware of choice is &lt;a href="https://esphome.io/"&gt;ESPHome&lt;/a&gt;, which you can flash easily onto a Shelly (no matter 1, 2 or 2.5) using a USB TTL adapter that provides 3.3V. Home Assistant has native ESPHome support with auto-discovery, which is much nicer than manually attaching things to MQTT topics.&lt;/p&gt;
&lt;p&gt;To get ESPHome compiled for the Shelly 2.5, we'll need a basic configuration like this:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nt"&gt;esphome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;shelly25&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;ESP8266&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nt"&gt;board&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;modwifi&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nt"&gt;arduino_version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;2.4.2&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We're using &lt;code&gt;board: modwifi&lt;/code&gt; as the Shelly 2.5 (and all other Shellys) has 2MB flash and the usually recommended &lt;code&gt;esp01_1m&lt;/code&gt; would only use 1MB of that - otherwise the configurations are identical (see the PlatformIO entries for &lt;a href="https://docs.platformio.org/en/latest/boards/espressif8266/modwifi.html"&gt;modwifi&lt;/a&gt; and &lt;a href="https://docs.platformio.org/en/latest/boards/espressif8266/esp01_1m.html"&gt;esp01_1m&lt;/a&gt;). And &lt;code&gt;arduino_version: 2.4.2&lt;/code&gt; is what the Internet suggests is the most stable SDK version, and who will argue with the Internet?!&lt;/p&gt;
&lt;p&gt;Now an ESP8266 without network connection is boring, so we add a WiFi configuration:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nt"&gt;wifi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nt"&gt;ssid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;!secret&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;wifi_ssid&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nt"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;!secret&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;wifi_password&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nt"&gt;power_save_mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;none&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;!secret&lt;/code&gt; commands load the named variables from &lt;a href="https://github.com/evgeni/esphome-configs/blob/master/secrets.yaml.example"&gt;&lt;code&gt;secrets.yaml&lt;/code&gt;&lt;/a&gt;. While testing, I found the network connection of the Shelly very unreliable, especially when placed inside the wall and thus having rather bad bad reception (-75dBm according to ESPHome). However, setting &lt;code&gt;power_save_mode: none&lt;/code&gt; explicitly seems to have fixed this, even if &lt;a href="https://esphome.io/components/wifi.html#wifi-power-save-mode"&gt;&lt;code&gt;NONE&lt;/code&gt; is supposed to be the default on ESP8266&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;At this point the Shelly has a working firmware and WiFi, but does not expose any of its features: no switches, no relays, no power meters.&lt;/p&gt;
&lt;p&gt;To fix that we first need to find out the GPIO pins all these are connected to. Thankfully we can basically copy paste the definition from the &lt;a href="https://tasmota.github.io/docs/"&gt;Tasmota&lt;/a&gt; (another open-source firmware for ESPs) &lt;a href="https://templates.blakadder.com/shelly_25.html"&gt;template&lt;/a&gt;:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nt"&gt;pin_led1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;GPIO0&lt;/span&gt;
&lt;span class="nt"&gt;pin_button1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;GPIO2&lt;/span&gt;
&lt;span class="nt"&gt;pin_relay1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;GPIO4&lt;/span&gt;
&lt;span class="nt"&gt;pin_switch2n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;GPIO5&lt;/span&gt;
&lt;span class="nt"&gt;pin_sda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;GPIO12&lt;/span&gt;
&lt;span class="nt"&gt;pin_switch1n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;GPIO13&lt;/span&gt;
&lt;span class="nt"&gt;pin_scl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;GPIO14&lt;/span&gt;
&lt;span class="nt"&gt;pin_relay2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;GPIO15&lt;/span&gt;
&lt;span class="nt"&gt;pin_ade7953&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;GPIO16&lt;/span&gt;
&lt;span class="nt"&gt;pin_temp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;A0&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If we place that into the &lt;code&gt;substitutions&lt;/code&gt; section of the ESPHome config, we can use the names everywhere and don't have to remember the pin numbers.&lt;/p&gt;
&lt;p&gt;The configuration for the &lt;a href="https://esphome.io/components/sensor/ade7953.html"&gt;ADE7953 power sensor&lt;/a&gt; and the &lt;a href="https://esphome.io/components/sensor/ntc.html"&gt;NTC temperature sensor&lt;/a&gt; are taken verbatim from the ESPHome documentation, so there is no need to repeat them here.&lt;/p&gt;
&lt;p&gt;The configuration for the switches and relays are also rather straight forward:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nt"&gt;binary_sensor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;gpio&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;pin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;${pin_switch1n}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Switch&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;#1"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;internal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;true&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;switch1&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;gpio&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;pin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;${pin_switch2n}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Switch&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;#2"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;internal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;true&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;switch2&lt;/span&gt;

&lt;span class="nt"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;gpio&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;pin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;${pin_relay1}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Relay&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;#1"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;internal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;true&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;relay1&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;interlock&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;&amp;amp;interlock_group&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p p-Indicator"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;relay1&lt;/span&gt;&lt;span class="p p-Indicator"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;relay2&lt;/span&gt;&lt;span class="p p-Indicator"&gt;]&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;gpio&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;pin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;${pin_relay2}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Relay&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;#2"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;internal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;true&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;relay2&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;interlock&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;*interlock_group&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;All marked as &lt;code&gt;internal: true&lt;/code&gt;, as we don't need them visible in Home Assistant.&lt;/p&gt;
&lt;h3&gt;ESPHome and Schellenberg roller shutters&lt;/h3&gt;
&lt;p&gt;Now that we have a working Shelly 2.5 with ESPHome, how do we control Schellenberg (and other) roller shutters with it?&lt;/p&gt;
&lt;p&gt;Well, first of all we need to connect the Up and Down wires of the shutter motor to the two relays of the Shelly. And if they would not be marked as &lt;code&gt;internal: true&lt;/code&gt;, they would show up in Home Assistant and we would be able to flip them on and off, moving the shutters. But this would also mean that we need to flip them off each time after use, as while the motor knows when to stop and will do so, applying current to both wires at the same time produces rather &lt;em&gt;interesting&lt;/em&gt; results. So instead of fiddling around with the relays directly, we define a &lt;a href="https://esphome.io/components/cover/time_based.html"&gt;time-based cover&lt;/a&gt; in our configuration:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nt"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;time_based&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"${location}&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Rolladen"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;rolladen&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;open_action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;switch.turn_on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;relay2&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;open_duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;${open_duration}&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;close_action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;switch.turn_on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;relay1&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;close_duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;${close_duration}&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;stop_action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;switch.turn_off&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;relay1&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;switch.turn_off&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;relay2&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We use a time-based cover because that's the easiest thing that will also turn the relays off for us after the shutters have been opened/closed, as the motor does not "report" any state back. We &lt;em&gt;could&lt;/em&gt; use the integrated power meter of the Shelly to turn off when the load falls under a threshold, but I was too lazy and this works just fine as it is.&lt;/p&gt;
&lt;p&gt;Next, let's add the physical switches to it. We could just add &lt;a href="https://esphome.io/components/binary_sensor/index.html#binary-sensor-on-press"&gt;&lt;code&gt;on_press&lt;/code&gt; automations to the binary GPIO sensors&lt;/a&gt; we configured for the two switch inputs the Shelly has. But if you have kids at home, you'll know that they like to press ALL THE THINGS and what could be better than a small kill-switch against small fingers?&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nt"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;previous definitions go here&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p p-Indicator"&gt;]&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;template&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;block_control&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"${location}&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Block&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Control"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;optimistic&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;true&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;template&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Move&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;UP"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;internal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;true&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p p-Indicator"&gt;|-&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;if (id(switch1).state &amp;amp;&amp;amp; !id(block_control).state) {&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="no"&gt;return true;&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;} else {&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="no"&gt;return false;&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;on_turn_on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="nt"&gt;then&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nt"&gt;cover.open&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;rolladen&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;on_turn_off&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="nt"&gt;then&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nt"&gt;cover.stop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;rolladen&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;template&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"Move&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;DOWN"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;internal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;true&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p p-Indicator"&gt;|-&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;if (id(switch2).state &amp;amp;&amp;amp; !id(block_control).state) {&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="no"&gt;return true;&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;} else {&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="no"&gt;return false;&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;on_turn_on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="nt"&gt;then&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nt"&gt;cover.close&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;rolladen&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;on_turn_off&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="nt"&gt;then&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nt"&gt;cover.stop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;rolladen&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This adds three more &lt;a href="https://esphome.io/components/switch/template.html"&gt;template switches&lt;/a&gt;.
The first one, "Block Control", is exposed to Home Assistant, has no &lt;code&gt;lambda&lt;/code&gt; definition and is set to &lt;code&gt;optimistic: true&lt;/code&gt;, which makes is basically a dumb switch that can be flipped at will and the only thing it does is storing the binary on/off state.
The two others are almost identical. The name differs, obviously, and so does the &lt;code&gt;on_turn_on&lt;/code&gt; automation (one triggers the cover to open, the other to close). And the really interesting part is the &lt;code&gt;lambda&lt;/code&gt; that monitors one of the physical switches and if that is turned on, &lt;em&gt;plus&lt;/em&gt; "Block Control" is off, reports the switch as turned on, thus triggering the automation.
With this we can now block the physical switches via Home Assistant, while still being able to control the shutters via the same.&lt;/p&gt;
&lt;p&gt;All this (and a bit more) can be found in my &lt;a href="https://github.com/evgeni/esphome-configs"&gt;esphome-configs&lt;/a&gt; repository on GitHub, enjoy!&lt;/p&gt;</description><category>english</category><category>hardware</category><category>home-automation</category><category>linux</category><category>planet-debian</category><category>software</category><guid>https://www.die-welt.net/2020/04/controlling-roller-shutters-using-a-shelly-25-esphome-and-home-assistant/</guid><pubDate>Thu, 23 Apr 2020 19:54:37 GMT</pubDate></item></channel></rss>