In this post, I want to share something I’ve created; a set of Python scripts to ensure the lights currently controlled by Detached Mode relays will work from the switch if Home Assistant isn’t available.
Background
I’ve been using the Detached mode in my Shelly Relays since about 2001. I have six Shelly 1 relays controlling a few WiFi Bulbs and aside from one self inflicted outage (erased by HDD), the only time we have a problem is when I’m updating Home Assistant or the Ubuntu machine it’s running on.
I keep both Home Assistant and Ubuntu up-to-date and whilst the downtime is short, it is surprisingly annoying for my wife and kids.
I has also made me worried that a problem with Home Assistant or the machine it’s running on would render a lot of the lights in my house inoperable i.e. can’t turn them on or turn them off. It’s unlikely to happen, but a possibility none the less.
My Solution
To mitigate this issue, most people run a script of some description on their Shelly 1 and it will automatically fall back to Toggle/Edge mode in the event of a problem.
For me, most of my Shelly hardware is 5 or 6 years old (Generation 1) and as such, doesn’t have the scripting feature. To plug this gap, I created a set of Python scripts and called it the Shelly Failsafe.
It’s basically a script that I run on a Raspberry Pi that monitors Home Assistant. If it goes down, the script will switch the button mode on my relays back to Toggle. This means the physical light switches will once again have control! It’s not perfect, but it’s better than nothing.
Trying it out
I have published everything up on GitHub if you want to take a look:
tomasmcguinness/shelly-detached-mode-python-ha-watchdog
It’s still being improved and tweaked, but do take a look.
I’ve also made a YouTube video about it, showing it in action