Converting Tuya devices to Tasmota

Screenshot of the Tasmota web site

I’ve mentioned that I have a few Tuya smart plug sockets around the home. It’s possible to convert these to run on open source firmware called Tasmota, to gain some additional features, and it’s something I’ve been considering.

The logic boards for many Tuya devices are from the Espressif ESP family, which can easily be flashed with different firmware. Tasmota is one such provider, as is ESPHome which is a sister project to Home Assistant.

What’s wrong with Tuya?

Tuya mostly manufacture ‘white label’ devices that are then sold under a variety of brands. Mine are branded ‘Coosa’ but I’ve seen others called ‘Hey!’ being advertised. Often, they come with their own branded app, but you can use them with Tuya’s own app as well.

I bought them a few years ago because they work well with Google Assistant and IFTTT (which I no longer use). They also work well with Home Assistant (especially since last month). They don’t work with Apple HomeKit natively but can be bridged in using Home Assistant or Homebridge. The other advantage was that you didn’t need a separate hub for them to work – they connect directly to your home Wifi network.

However, Tuya is a Chinese company. Though they claim to have servers in the EU, it could be that every time I use their switches, my request goes via China. In Home Assistant, there are a couple of custom integrations in HACS called LocalTuya and TuyaLocal that can issue commands locally on your home network. But if you use Google Assistant, the commands get sent across the web.

Local control with Tasmota

The Tasmota project offers a tool called Tuya Convert, which replaces Tuya’s official firmware and allows for local control. It mainly uses the MQTT protocol, which is openly documented and used by a variety of different Internet of Things devices. Once flashed onto your devices, they can be controlled locally and don’t need to communicate with external servers. Home Assistant has extensive MQTT support and an official Tasmota integration.

They also work well with Alexa devices, by emulating a Belkin WeMo or Philips Hue device.

This all sounds good to me, but I haven’t gone ahead and done it. Unfortunately, whilst Amazon Alexa is supported, Tasmota doesn’t easily interact with Google Assistant. And once I’ve flashed a device with Tasmota, it may be difficult or impossible to go back to the official Tuya firmware.

Of course, I can configure Home Assistant to work with Google Assistant. I haven’t yet, even though there are two ways to do it:

  1. Sign up for Home Assistant Cloud from Nabu Casa, which costs £6.50 per month
  2. Set up Google Assistant manually with Home Assistant, which is lengthy and may need to be reconfigured every 30 days.

I suppose if we used Amazon Echo devices instead of Google Home, this would be a no-brainer.

In the long run, replacing these smart plugs with ones that use Matter would be better and cheaper. My Home Assistant install is pretty-much Matter ready, with no need for an additional hub. Matter, like Zigbee, mostly works locally, and therefore doesn’t have the privacy implications of my current web-based Tuya plugs.

How to: install Home Assistant Supervised on a Raspberry Pi

Screenshot of Home Assistant showing Supervisor installed

There are several ways to install Home Assistant. The easiest way (besides buying a dedicated device such as Home Assistant Yellow or Green with it pre-installed) is to use what is known as ‘Home Assistant Operating System’. This bundles Home Assistant with a system manager called Supervisor and an underlying Linux distro.

There are other methods, and I’ll probably write another blog post comparing them all later. Probably the most difficult is Home Assistant Supervised, which includes the Supervisor from Home Assistant OS (HAOS), but with a self-administered Linux operating system. I’ve got over 10 years of experience working with Debian Linux, as this blog runs on it, but it took some trial and error on my part to get working.

By setting up Linux yourself first, you gain more control over your system than is offered by HAOS. For example, whilst you can enable shell access on HAOS, it’s a limited user account with no root access. And, bizarrely, HAOS doesn’t support USB mass storage devices. So even though you can install Plex from within HAOS, if your media is on an external hard disk, you can’t grant Plex access to it.

At the weekend, I set up my Raspberry Pi 4 with Home Assistant Supervised. Here’s how I went about it.

Note: This guide was current in January 2024. The instructions below may not necessarily work on future releases of Debian and Home Assistant.

Step 1: Installing Debian 12 (Bookworm)

I strongly advise you to start with a fresh Linux installation; trying to bolt this onto an existing Linux image may break other things. Home Assistant is designed to run on Debian 12 – and not Raspberry Pi OS, although I’ve seen some forum posts from users who are using this. For this guide, I’m using Debian 12.

For the most part, you can simply follow the instructions on this guide to flash an SD card and complete the initial setup. The newer versions of the Raspberry Pi imager may ask if you want to configure Wifi and SSH access for your image; don’t bother, as this won’t work on Debian. The other thing to bare in mind with this guide is the Wifi settings, where you un-comment several lines in a configuration file if you’re not using an Ethernet connection. This is fine at this stage, but you’ll need to re-comment those lines later.

The other thing that I did in addition to this guide was type in dpkg-reconfigure tzdata and set my timezone to Europe/London rather than UTC.

You can stop following the guide at the point at which it tells you to install a graphical user interface, as this isn’t needed for Home Assistant. Of course, if you’re planning to use this device for other things and a graphical UI would help you, then follow the whole guide by all means.

Step 2: Install the necessary additional packages for Home Assistant

Here, we start following this official guide from HA. You’ll need to install various additional packages to enable the Home Assistant Supervisor to run.

Once installed, I found that I had to edit the /etc/NetworkManager/NetworkManager.conf file and change managed=false to true. This was also the point where I needed to re-comment the wifi settings. Without doing this, my Raspberry Pi wasn’t able to connect to the internet for the next step.

Step 3: Install Docker

As per the official instructions, run curl -fsSL get.docker.com | sh to install Docker. This took quite a while, so maybe go and grab some lunch.

If you’re getting an error about being unable to resolve get.docker.com, then go back to step 2.

At this point, I found it easier to continue the installation remotely over SSH, rather using the keyboard and a screen.

Step 4: Install the OS Agent

Next, you’ll need to install the latest version of the OS Agent. For a Raspberry Pi 3 or later, you’ll need the aarch64 version. I downloaded the ‘os-agent_1.6.0_linux_aarch64.deb‘ file and then uploaded this using WinSCP, but you could also download it using curl or wget. You’ll then need to run the command dpkg -i os-agent_1.6.0_linux_aarch64.deb as root.

The next command to run is gdbus introspect --system --dest io.hass.os --object-path /io/hass/os . This should give some multi-coloured code and not an error; if you get an error about the ‘gdbus’ command not being found, then you may have missed the libglib2.0-bin package in step 2.

Step 5: Install Home Assistant Supervised

Finally, we’re at the stage where we can actually install Home Assistant. Here’s the command to run:

wget -O homeassistant-supervised.deb https://github.com/home-assistant/supervised-installer/releases/latest/download/homeassistant-supervised.deb apt install ./homeassistant-supervised.deb

Once this is complete, wait a few minutes and go to http://[your IP]:8123/ and you should be greeted with the Home Assistant web UI. It may take a minute or to before you can start the onboarding process. If you’re migrating to Home Assistant Supervised, then you can also restore a backup at this stage, but be aware that such a backup can take a long time to restore.

And then you’re done. You may get some warning messages about the system being ‘unhealthy’ but these seem to disappear after a reboot, in my experience.

Things to consider

Although installing Home Assistant this way does allow it to co-exist with other software, bare the following in mind:

  • Even if you mount a USB hard disk/flash drive to your device, Home Assistant doesn’t seem to want to know about it, or let you attach it to any addons.
  • Although you need to install Docker for Supervisor to work, you’ll get errors in your Home Assistant settings if you install any other Docker images that are not managed as Home Assistant Addons. So, if you want to install any other software, do it manually, or in another container system like Snap. Or you could try Kubernetes I suppose, if you really hate yourself.

Installing Home Assistant Supervised is by far the most difficult method, but for me, it offers the best balance of overall control, and ease of use once set up. If you can find the time to set it up, then once it’s up and running, it’s easier to add new devices and configure on an ongoing basis. Whereas setting up HTTPS and HomeKit can be a challenge on Home Assistant Container, enabling these on Supervised is much more straightforward.

That being said, if you can dedicate a device to running Home Assistant on its own, then I would definitely recommend just running Home Assistant Operating System.

Home Assistant with HTTPS and HomeKit

A screenshot of Home Assistant running in a web browser with HTTPS enabled and no certificate errors

Welcome to the latest chapter of getting Home Assistant working on a Raspberry Pi using Docker. Last time, I’d managed to get it working in Docker, but only over a regular HTTP connection and without HomeKit. The good news is that I’ve solved both of these problems.

Using SWAG to enable HTTPS

Firstly, I recommend reading this paragraph whilst listening to ‘Swagger Jagger’ by Cher Lloyd.

I’ve tried lots of different ways to get Home Assistant working over SSL/TLS. There’s a good reason why this is one of the key selling points of Home Assistant Cloud, as it can be difficult. Thankfully, there’s a Docker image called SWAG (Secure Web Application Gateway) that handles much of the legwork. Once you’ve installed SWAG, follow this guide, and you should find that you can access your Home Assistant setup at https://homeassistant.[yourusername].duckdns.org/ . No need to specify a port, or accept any certificate warnings.

Inside SWAG, there’s a DNS client, which will automatically renew the SSL certificates every 90 days for you, using ZeroSSL or Let’s Encrypt. There’s also nginx, which is used to set up a reverse proxy, and support for dynamic DNS services like DuckDNS.

SWAG has sample configurations for lots of different services, including calibre-web, so I have SSL access to my calibre-web image too. My only issues with it so far were last week when DuckDNS went down on Sunday morning. Most services, like Home Assistant, need to be mounted as subdomains (as above), but others (like calibre-web) can be mounted as subfolders, e.g. https://[yourusername].duckdns.org/calibre-web. This reduces the number of subdomains that you need SSL certificates for; ZeroSSL only offers 3 subdomains for a free account so it’s worth considering subfolders if you want to add more services.

If you have your own domain, then you can also add a CNAME to it to point it at your DuckDNS account, should you wish to use that rather than a [something].duckdns.org address.

Getting Apple HomeKit working

Carrying on the musical theme, here’s ‘Carry Me Home’ by Gloworm, a 90s dance classic which has only recently become available on digital platforms again.

After getting my swagger jagger on and getting HTTPS working, the final issue I’ve been having with Home Assistant is the HomeKit bridge. Adding Home Assistant devices to Apple’s Home app is something that normally works out of the box if you install Home Assistant OS, but takes more work if you use Docker.

The instructions which helped me where these on the Home Assistant forums. You’re going to need to install another Docker image containing avahi; there are several but this one worked for me. It’s bang up to date, unlike the most common Docker image which is, um, 8 years out of date and also only works on x86 machines. Which isn’t much help for my arm64-based Raspberry Pi 4.

Once you’ve installed avahi, added the relevant lines to configuration.yaml in Home Assistant and restarted it, HomeKit should work. To get started, add the HomeKit integration to Home Assistant – you may want to specify which devices will show if you don’t want all of them. Then, use your iPhone or iPad to scan the QR code in your Home Assistant notification panel, and add the bridge. If all goes well, it should immediately tell you that it’s an unsigned device, but will then let you set up each device in turn.

If it just sits there for several minutes and then gives up, you’ll need to do some more digging. Don’t worry, this happened to me too. I suggest downloading the Discovery app, which shows all of the mDNS devices broadcasting on your network. If you can’t see ‘_hap._tcp’ in the list, then there’s a problem. In my case, this turned out to be because my Raspberry Pi wasn’t connected to the same wifi network. It’s plugged in to my ADSL router with a network cable, but we use Google Wifi which results in a ‘double NAT’ situation. Connecting the Raspberry Pi to both wired and wireless connections seemed to fix the issue.

Indeed, as a side effect Home Assistant managed to autodiscover some additional devices on my network, which was nice.

Home Assistant Core in Docker? Done it, mate

All in all, I’ve successfully managed to get Home Assistant to where I want it to be – self-updating in Docker, secure remote access, and a HomeKit bridge so that I can ask Siri to manage my devices. I’m looking forward to being able to turn my heating on whilst driving, for example.

It’s been a challenge, requiring a lot of skimming through the Home Assistant forums and various StackExchange discussions. Ideally, I would have a spare computer to run Home Assistant OS, which would have taken some of the leg work out of this, but I’m happy with the setup. Finding SWAG and getting it to work was a moment of joy, after all the setbacks I’d had before.

Running Home Assistant in Docker and Snap

A screenshot of the Home Assistant installation instructions for Docker

So, as I mentioned a couple of weeks ago, I’ve set up Home Assistant (HA) to control the various smart devices that we have around the home. At the time, I just used a snap package, but now I’ve migrated to using Docker, and here’s why.

Firstly, there are some disadvantages of installing Home Assistant using a snap package. Namely:

  1. The snap package isn’t an official release by the Home Assistant project, and is instead built by a third party.
  2. This means that, at time of writing, it’s a couple of releases behind the latest official release.
  3. It also means that it’s not a formally supported way of running Home Assistant, and there are fewer resources out there to help you if you’re stuck.
  4. I had issues updating previously installed custom components from HACS

Meanwhile, there’s an official Home Assistant Docker image that is updated at the same time as new releases, and it’s mentioned in the installation guide.

So, on the whole, Docker is better for running HA than Snap. But I wanted to run HA on my Raspberry Pi 4 which has Ubuntu Core on it, and that only offers Snap. But wait… you can install Docker on Snap, and the Docker Snap package is one maintained by Canonical so it’s regularly updated.

You can see where this is going. What if I install Docker using Snap, and then install Home Assistant into Docker? Well, that’s what I did, and I’m pleased to inform you that it works.

Docker on Snap, step-by-step

If you want to try this yourself, here’s the steps that I followed. However, please be aware that you can’t migrate a Home Assistant setup from Snap to Docker. Whilst HA does offer a backup tool, the option to restore a backup is only available on Home Assistant Operating System, and it seems that manually copying the files across won’t work either. So, if you currently use Snap, you’ll have to set up HA again from scratch afterwards. You’ll also, at the very least, need to run snap stop home-assistant-snap before you start.

  1. Install Docker. You can do this by logging into your machine using SSH and typing in snap install docker.
  2. Enable networking. There’s probably a better way of doing this, but for me, just running chmod 777 /var/run/docker.sock worked.
  3. Install Home Assistant. You’ll need to enter quite a long shell command, which is:
    docker run -d \
    --name homeassistant \
    --privileged \
    --restart=unless-stopped \
    -e TZ=MY_TIME_ZONE \
    -v /PATH_TO_YOUR_CONFIG:/config \
    --network=host \
    ghcr.io/home-assistant/home-assistant:stable

    The two variables in bold will need changing. For ‘MY_TIME_ZONE‘ you’ll need to type in your time zone, which in my case is ‘Europe/London‘, and for ‘PATH_TO_YOUR_CONFIG‘ is a folder where you want your configuration files. I suggest /home/[username]/homeassistant .
  4. Grab a drink, as the installation will take a few minutes, and then open http://[your IP address]:8123 in a web browser. If it’s worked, then you’ll be presented with HA’s onboarding screen.

Again, if you had the HA snap package installed, then if everything’s working with Docker, you’ll need to uninstall any related HA packages (like HACS, toolbox and configurator) and then the home-assistant-snap itself. And then you’ll need to set up all of your devices again. The good news is that, if you decide to move your HA installation to a new machine, you can just migrate the Docker image in future.

Wouldn’t it be better just running Docker?

Okay, so you may be wondering why I’ve set up HA this way. After all, it would probably be easier just to install Raspberry Pi OS Lite and put Docker on that, without using Snap. Well, there’s a method to my madness:

  • I like running Ubuntu Core because it’s so minimalist. It comes with the bare minimum of software installed, which means that there’s less risk of your system being compromised if a software vulnerability is found and exploited.
  • I already have Plex running quite happily in Snap, and didn’t want to have to migrate that as well.

In other words, this was the easiest way of running HA in Docker with my current setup. And I’m happy with it – I’m running the latest version of HA and it seems to work better.

There are a couple of additional steps that I still need to complete, which are:

  • Enabling SSL/TLS for remote access
  • Enabling mDNS broadcasts for Apple HomeKit integration

I’m working on these. Home Assistant Cloud is the easiest way of setting up secure access and I’m considering it. It’s a paid-for service, but it does financially support HA’s development, and seems to much easier than the alternatives. As for mDNS, I’m still working on this, and I imagine there’ll be things I need to tweak in both Docker and Snap to get it to work.

Getting started with Home Assistant

A screenshot of Home Assistant

A recent project of mine has been to set up Home Assistant, as a way of controlling the various smart devices in our home.

From bridge to assistant

You may remember, back in February, that I had dabbled with Homebridge, a more basic tool which was designed to bridge devices into Apple’s HomeKit universe which aren’t otherwise supported.

I’ve ditched Homebridge, as it didn’t really do what I wanted it to do. If you want to primarily use Apple’s Home ecosystem, but have a few devices which don’t support it, then it’s great. But that doesn’t really apply to our home – although I’m an iPhone and iPad user, I no longer have a working Mac and so I use a Windows desktop, and my wife uses Android devices. Consequently, the only device that we own which natively supports HomeKit is our LG smart TV.

Home Assistant is essentially a replacement for Apple Home, Google Home, Samsung SmartThings and whatever Amazon’s Alexa provides. That means that it provides its own dashboard, and lots of possibilities for automations. But instead of your dashboard being hosted on a cloud server somewhere, it’s on a device in your own home.

Setting it up

Like with Homebridge and HOOBS, you can buy a Home Assistant hub with the software pre-installed. If you already have a device, such as a spare Raspberry Pi, then you can either install HAOS (a complete operating system based around Home Assistant) or just install Home Assistant on an existing system. I chose the latter, and now I have Home Assistant sat on the same device as my Plex Server, using Ubuntu Core and the relevant Snap package.

Once set up, Home Assistant will auto-discover some devices; it immediately found both my ADSL router and my Google Wifi hub using UPnP. You can then add devices yourself. Home Assistant supports way, way more devices than its competitors, due to its hobbyist nature. For example, there’s an IPP integration which means that you can view your printer’s status, including how much ink is left. Despite it being a ‘smart device’ of sorts, Google Home won’t show this in its app. You can also bring in web services like Google Calendar and last.fm.

Some integrations are easier to set up than others though. In most cases, one of the first instructions for setting up an integration is ‘sign up for a developer account with your device manufacturer’. Whilst the instructions are usually quite clear, you’ll find yourself spending lots of time copying and pasting OAuth keys and client secrets to be able to connect your devices. In the case of my Nest Thermostat, this included paying a non-refundable $5 USD charge to access the relevant APIs.

It should also be noted that, whilst Home Assistant does offer integration with Apple HomeKit, I’ve yet to get this to work. Which is ironic as this was the reason why I previously used HomeBridge.

Remote access

Another thing which took some trial and error to get right was enabling remote access. If you want to be able to view and control your devices when you’re out of the home, then there’s a few additional steps you’ll need to complete. These include:

  • Configuring port forwarding on your router
  • Setting up a DNS server

Home Assistant recommends DuckDNS, which is pretty simple and seems to work okay, but again it’s something that requires some technical know-how.

One limitation of using Home Assistant as a Snap on Ubuntu Core is that you can’t use addons, so setting up DuckDNS meant manually editing Home Assistant’s configuration.yaml file. Indeed, some integrations require this, and so it’s worth backing up this file regularly. You can, however, install a separate snap which enables the Home Assistant Community Store (HACS), and this allows you to install additional (but less-well tested) integrations. I initially couldn’t get this to work, but managed to install it literally whilst writing this paragraph.

If you’re willing to pay, then for £6.50 per month, you can get Home Assistant Cloud. As well as providing an income for Home Assistant’s developers, it offers an easier and secure remote access solution, and integrates Google Assistant and Alexa.

Privacy matters

It should also be noted that Home Assistant has a greater focus on privacy. By hosting an IoT hub yourself, you can limit how much data your devices send to cloud servers, which may be in places like China with markedly different attitudes to privacy. Indeed, the integration with my Solax inverter (for our solar panels) connects directly to the inverter, rather than the Solax Cloud service. It’s therefore not surprising that many of the Home Assistant developer team are based in Europe.

Looking to the future, I’m hoping more of my devices will support Matter – indeed, this week, Matter 1.2 was released, adding support for devices like dishwashers. Theoretically, our existing Google Home devices can all be Matter hubs, but none of my other devices yet support it, and may never will. Home Assistant can work with Matter devices, if you buy their SkyConnect dongle, and again, it will mean that more of your device communications can be done within in your home and not using the cloud. That should be faster, and better for privacy.

Overall, I’m quite happy Home Assistant, even though it’s taken a long time to get every device added and some trial and error. I appreciate being able to see (almost) all of my devices on one dashboard, and it feels like I have more oversight and control over the smart devices in our home. I hope that, with greater Matter support, it’ll become easier for less-experienced users to use in future.

Adventures in setting up Homebridge for HomeKit

A screenshot of the Homebridge dashboard

A recent project of mine has been to get Homebridge up and running. It’s a server-based program that acts as a bridge between smart devices in the home, and Apple’s Home app on iOS.

One thing, I don’t know why

HomeKit, the technology underpinning Home, is famously limited; whilst most smart devices support Amazon’s Alexa and Google Assistant, very few support HomeKit. Indeed, out of the various smart speakers, plug sockets, dishwasher, thermostat, smoke alarm and TV that we have in our house, it’s only the TV that natively supports HomeKit.

Whilst just about everything else (except the smoke alarm) supports Google Assistant, and the Google Home app, it would be helpful to be able to use these devices with Siri. For example, when I’m driving, I want to be able to use the Hey Siri command to turn the heating on, so that we don’t come home to a cold house.

I tried so hard, and got so far

There’s a few ways to run Homebridge. If you have money to spare, then by far the easiest way is to buy a HOOBS box. HOOBS stands for ‘Homebridge Out of Box System‘, and you’ll get a plug-in device with a customised version of Homebridge that is simple to set up. You can also buy HOOBS on an SD card, that can be slotted into your own Raspberry Pi. Or, you can just download the HOOBS SD card image for a donation of £10.

I have two Raspberry Pis – a RPi 400 which is our seven-year-old’s computer, and a RPi 4 which is my Plex server. The latter runs Plex under Ubuntu Core, a minimal version of Ubuntu Linux which doesn’t include a graphical user interface, or even the Aptitude package manager. Instead, apps can be installed using Snap packages, which enforces greater sandboxing and security. There is a Snap package for Homebridge, but I couldn’t actually get it to work; once installed, I couldn’t open the browser page as instructed.

So, I’ve installed it using Apt on our child’s Raspberry Pi 400, and followed the proper instructions.

There’s only one thing you should know

When you first start Homebridge, it won’t do much initially. To get it talking to your devices, you’ll need to install the appropriate plugins, which you can do through the web UI. I suggest going with the plugins that have been ‘verified’ first, as you’ll probably find that there’s more than one plugin for some of the more popular services like Nest. Whilst installing plugins is relatively easy, configuring them can be difficult:

  • The Nest plugin, for example, has you logging into your Google Nest account in Chrome’s Incognito mode, whilst having Developer Tools open. You then have to copy and paste various data from the HTTP headers.
  • I have a series of smart plug sockets which use the Tuya Smart Life platform, but I had them registered under a different app which Homebridge can’t connect to. I had to de-register them and then set them up again on the official Tuya app.
  • Despite following the instructions, I couldn’t get my Bosch smart dishwasher to connect

Setting up Homebridge is therefore something best reserved for people who are comfortable using the Linux command line and with at least an intermediate understanding of how devices work. However, it does mean that I now have these devices in HomeKit as planned.

Homebridge even supports my Solar Inverter, although in a rather odd way. It appears as 12(!) separate accessories in the Home app, seeing as HomeKit doesn’t ‘know’ what a solar panel is. You can also make the Google Home app talk to Homebridge – again, this is the only way that I can make my Solax system work with Google.

But in the end, it doesn’t even Matter

Those of you who follow news in the smart devices/Internet of Things space will be aware of Matter, a new unified smart device standard with the support of Amazon, Apple, Google and Samsung. Matter will hopefully do away with the separate ecosystems that each company offers, and any Matter approved device should work with any other. However, the final Matter specification was only agreed last year, and I’m not expecting many of my existing devices to be updated to support it. At best, my Google Nest Mini devices will be updated soon, and my thermostat may be updated. For others, I would probably have to replace them with Matter-enabled devices in due course. Therefore, Homebridge offers me the flexibility that Matter will hopefully bring as an interim solution.