Why should Tuya be integrated with Home Assistant?

Why should Tuya be integrated with Home Assistant

Recently there are many developers expect the ‘Powered by Tuya’ devices to support integration with the Home Assistant and be controlled using the Home Assistant app or Home Assistant for the web.

With all the expectations, Tuya released the Tuya Home Assistant Integration, and there is a Tuya Beta Test Programfor developers, let’s check it out.

1. Background

Why Home Assistant?

Home Assistant is a Python-based, open-source smart home project that supports various smart home devices of various brands and enables easy implementation of voice control and home automation. Home Assistant features an easy-to-use, mobile-friendly interface that helps users control all their smart devices while not storing any data in the cloud to protect personal privacy.

It is one of the most popular IoT smart hardware open-source projects on GitHub with 44,000 stars and 14,300 forks and comprises 130,000 community members on Reddit. Home Assistant is a popular option for home automation on Raspberry Pi (RPi) and has a large user base.


Who is Home Assistant designed for?

Smart Home Enthusiasts : Buy smart home products and build your smart home solutions with Home Assistant.

Developers/Geeks : Make your ‘Powered by Tuya’ devices compatible with different products and brands to enable better home automation and device linkage.

Independent software or hardware vendors (ISVs/IHVs) : Implement the development of ‘Powered by Tuya’ products and integration with Home Assistant based on the Tuya Home Assistant Integration, for example, by providing driver software development services and custom smart home control systems on mobile apps, apps for the web, RPi, and more.


System integrators (SIs) : Develop smart products and drivers based on the Home Assistant platform and the Tuya Home Assistant Integration and integrate them with your smart product ecosystem (such as Control4) to provide complete integration solutions and software platform services as well as implement cloud development based on the Tuya’s OpenAPIs.

2. Technical Principles

What technologies are behind Tuya Home Assistant Integration?

·

Python

·

Python is an interpreted high-level, general-purpose programming language. Python’s design philosophy emphasizes code readability with its notable use of significant indentation. It is an interpreted, interactive, and object-oriented scripting language. Python is an open-source language and has been ported to (changed to make it work on) many platforms.

·

Raspberry Pi (RPi)

·

The Raspberry Pi is a microcomputer of the size of a credit card. Its operating system (OS) is based on Debian. Because of its low prices and powerful functions, it has been sought after by many computer fanciers and makers since its inception and has been highly popular in the IoT open source field.

·

OpenAPIs

·

Tuya’s IoT cloud open capabilities cover core scenarios such as device control, smart home management, and scene automation. Developers can quickly build the smart business, smart industry, and other industrial solutions based on Tuya’s OpenAPIs.

·

MQTT

·

The Message Queuing Telemetry Transport (MQTT) is a lightweight, publish-subscribe network protocol first released by International Business Machines (IBM) in 1999. The protocol usually runs over TCP/IP. The biggest advantage of the MQTT is that it enables real-time, reliable messaging between devices. It is helpful for connections with remote locations where a “small code footprint” is required or the network bandwidth is limited. As a publish-subscribe network protocol with low power consumption and low bandwidth consumption, the MQTT is widely used in the IoT field, small devices, mobile apps, and more.

Home Assistant is developed in Python. The cross-platform feature of Python makes Home Assistant compatible with Raspberry Pi OS, Windows, macOS, Linux, and other mainstream operating systems.

The Tuya Home Assistant Integration obtains device information from Tuya IoT Cloud through Tuya’s OpenAPIs and displays it in the Home Assistant app or Home Assistant for the web.

Standard commands are sent to Tuya IoT Cloud through the OpenAPIs, from which the commands are delivered to the device through Open IoT Hub over MQTT for device control.

Device status changes are reported to Tuya IoT Cloud over MQTT and then are sent to the Tuya Home Assistant Integration over MQTT. The integration updates the local device cache, notifies Home Assistant, and refreshes device status in Home Assistant.


3. Driver Development

Home Assistant provides a set of basic entities that make it easier for developers to develop integrations. We develop the Tuya Home Assistant Integration driver to integrate ‘Powered by Tuya’ devices with Home Assistant.

The driver consists of two parts: the basic driver logic and the device driver class.

·

The basic driver logic is similar to that of other drivers, with the majority part for adding ‘Powered by Tuya’ devices to the Home Assistant.

·

·

The device driver class maps the Tuya device Things Data Model (TDM) with the Home Assistant entity, and implements the following data point code logic: Home Assistant entities <-> data points <-> Tuya standard instruction sets.

·

4. Scenarios

IoT device integration system

The open-source Home Assistant platform has attracted many developers to develop integrations to achieve device integration across various manufacturers, such as Xiaomi, Hikvision, Honeywell, and Yeelight. With the Tuya Home Assistant Integration, you can easily build a Home Assistant-based local IoT device integration system that enables managing ‘Powered by Tuya’ devices and devices from multiple manufacturers in one place.


Python integration into Tuya IoT Cloud

The Tuya Home Assistant Integration is developed based on tuya-iot-py-sdk. tuya-iot-py-sdk is a Python SDK based on the Tuya IoT Cloud APIs. It encapsulates the network request authentication logic, token refresh logic, Open IoT Hub integration logic, and MQTT reconnection logic, and provides them to SDK callers in the form of Python functions. SDK callers can use these functions directly without having detailed logic implementation.

You can easily integrate your Python-based systems with Tuya IoT Cloud using the SDK without high integration and learning curves.

How does it benefit you?

Home Assistant is a vendor-neutral and open source project. It is easy to learn how to use Home Assistant, even for beginners.

Driven by your interests and with the help from the community, you can easily improve your programming skills during your experience with the Tuya Home Assistant Integration and have a deeper understanding of Tuya ecosystem capabilities. You can participate in the iterations of the integration or develop drivers to extend the scope of supported device types.

5. Postscript

The Tuya Home Assistant Integration is available on GitHub repo. It supports custom development and smart home cloud projects. Feel free to try it.

This is the Tuya Beta Test Program on GitHub Tuya home assistant repo. You could get your development gifts and make a contribution to the integration. Your feedback is valuable to the whole community.

1 Like

Does the integration support local control of Tuya devices?
This is important to me and a lot of other users.

The Tuya Home Assistant Integration obtains device information from Tuya IoT Cloud through Tuya’s OpenAPIs and displays it in the Home Assistant app or Home Assistant for the web.

The v2 (beta) is said to do so in the future.
But I think it does local control now given how fast it is.

In the past pressing the button on the smart plug would mean it took minutes before HA noticed it was on, now it’s immediately. If that is not local then I don’t know how they did it.
But this is just my speculations.

September was touted as the timeline for local control release testing.

Still requires enrolment via the cloud though.

So it’s still cloud based?
Wow… How can it be so quick then.

No, you enrol/discover the devices using the cloud but control and feedback is direct Device <—> Home Assistant.

1 Like

… which makes Zigbee/Tasmota etc. still superior over Tuya.

Just my 2 cent though …

Zigbee is pretty darn good, but compared to Tuya there’s a limited range of devices. (Zigbee kettle?, panel heater?, etc…).

It’s getting harder and harder to find wifi devices you can flash alternative firmware to. Then there are people who don’t want to DIY alternative firmware or wire a Sonoff relay to a panel heater. They can just go out and buy a Tuya controlled panel heater or kettle.

You are absolutely correct, Tom.

Well, Tuya did a good job to accomplish this. Just think about their early 2020 update which was obviously just released to get rid of tuya-convert.

But yes, for people who don’t want to fiddle with devices and firmware Tuya is certainly great. As for me personally I am just not feeling comfy with sharing data to some (dubious) servers located somewhere. As there is that saying: There is NO CLOUD, just other people’s computers. :stuck_out_tongue_winking_eye:

Thanks for your feedback. Now I’ll wait, because local control is my priority. I don’t want to be addicted to the cloud.

What a palaver this new integration is. Or at least, it was for me! I hated it.
Thankfully, I only had one light bulb that operated through Tuya, a GU10 blub, only because my current mass usage doesn’t do GU10 bulbs. So it’s gone in the bin!
Instead, I’ve bought a Yeelight GU10 bulb and it was SO easy to set up, both with the app and with HA. A doddle in fact. AND it supports direct control (non cloud) if so required.
And it’s got so many features built in that I’ve never seen with other bulbs (light to music and pattern modes similar to WLED), I love it. I’ll not hessitate to buy Yeelight again in future and thoroughly recommend them. :blush:

@tom_I, I have a bunch of devices that I can see on the Tuya IoT platform. However, many of them do not show up in HA.

I see 23 devices in the Tuya IoT platform.



However, I only see 12 in HA, excluding the 4 scenes:
image

Anything I can do to fix this?

Maybe wait for 2021.11.0. The Tuya integration is still currently under development

No idea why you tagged me, I don’t use the Tuya integration. I flashed all my Tuya devices with alternative firmware that allows local control.

Because you seemed to be the most knowledgeable person on this tread. Sorry for any inconvenience.