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.

A basic Home Assistant automation

A screenshot of Home Assistant showing an automation to turn off a smart plug after 18 hours

One of the biggest benefits of running Home Assistant in your home is its powerful automation tools for controlling your smart devices. In this example, I have a smart plug socket which I want to run for 18 hours, and then automatically switch off. This is the smart plug that we use for our heated drying rack, and it ensures that the rack doesn’t continue heating for longer than necessary, to save energy. As I run Home Assistant on a Raspberry Pi 4, it only uses 15 watts of power, compared to the few hundred watts that the drying rack requires.

Automations in Home Assistant have become much easier in recent releases. In times gone by, you’d have to write YAML scripts to automate your devices, but now there’s a relatively straightforward interface. Generally, automations work on the principal of ‘if this, then that’ – a bit like IFTTT, but it runs in your own home.

Tuya me, to you

For my automation, I use the trigger of the smart socket being turned on. In my case, this is a Tuya wifi-enabled smart plug, which I’ve called ‘Cuthbert’. We have four Tuya plugs, all with silly names like Cuthbert, just because. Tuya are a white label manufacturer, and so the brand names on the plugs vary despite them being exactly the same. I wouldn’t necessarily recommend them, as presumably every time you turn them on and off, your request goes via Chinese-controlled servers. I would probably buy Matter-enabled plugs instead now but they work fine. Plus, the recent 2024.02 release of Home Assistant massively improves Tuya support and no longer requires you to create a developer account, which is nice.

Automation actions

Anyway, having selected the ‘When’ event, we now need to specify the ‘Then do’ actions to take. First of all, we need a time delay, otherwise as soon as the socket is turned on, Home Assistant will turn it off again. The ordering of actions is important, as I found out the hard way; I originally had the delay after the command which meant that the socket just turned off straight-away. So, we specify a delay and then the action to turn the socket off.

The third action is optional, but it just sends a notification to my phone to tell me that the automation has completed. I’m using the Home Assistant Companion app but you could use an app like Pushover, or trigger an email.

This is a really simple automation, but you can create more complex ones. I’m hoping that, at some point in the future, we’ll have some smart blinds in our kitchen, and I’ll be able to use Home Assistant’s sun integration to open and close them at sunrise and sunset.