Home Automation with Tuya Devices

Last Update: Jan 17, 2024 @ 13:57 Information subject to change.

Tuya is a large Chinese company that makes an extensive range of IoT devices which are badge-engineered and sold by many companies. Tuya runs cloud data-center facilities world wide: there’s one in Toronto, Canada. There are free IoS and Android apps that allow devices to be controlled remotely from anywhere.

All Tuya devices are recognized by the Google Home app.

This page describes how to configure a set of four LA-WF7 Energy Monitoring Smart Plugs, first using the TuyaSmart app (Android version) and then using the third-party Tuyapi JavaScript library (via GitHub).

When a configured Smart Plug is powered up, the router will assign an IPv4 address to each device’s unique MAC identifier. This can and will vary if other devices come and go in the LAN. The solution is to use the Router DHCP Table to reserve a specific IPv4 address for the Smart Plug MAC. If the first time the set of Smart Plugs is configured, marking each one as Reserved will lock that IPv4 address to the MAC. For example, these addresses might be|146|176|185.

Most routers also have an option to create a limited number of static IP addresses (say, 8) with a user-defined IPv4 address. Assuming that there is space available in the Static Address Table, these addresses might be|142|143|144.

Functionally, DHSP reserved and Static reserved addresses ensure that when the Smart Plugs are powered up, they always get the same IPv4 address.

Configuring the LA-WF7 Devices

The TuyaSmart app is found in the Google App Store, and is free. When first run, there is the option of creating an account, which can be completed later. All that is required is to Add Devices.

When a LA-WF7 is plugged in, you can manually turn on the plug, and the Red indicator appears. Press again to turn the plug off.

To start the configuration phase, each LA-WF7 requires the button to be pressed for around 10 seconds, which causes the Blue indicator to start flashing, which means the firmware is broadcasting as a server. The App can identify this and connect to it.

The TuyaSmart app does not care if the IPv4 address changes: remote control is always accessible.

Configuring the LA-WF7 takes about 1 minute, at which point the Blue indicator stops flashing and is constantly on. When you use the App to turn on a plug, the Red indicator appears, replacing the Blue.

Setting up nodejs and the tuyapi libraries

nodejs has versions that run on linux, Raspbian, ubuntu, android and Windows (32 and 64 bit).

tuyapi expects to find the nodejs files on the host system. We started with Raspbian on a RPi 4B.

< More to add, please check again soon.>

Copyright © 2024 PiXCL Automation Tech Notes, Canada. All Rights Reserved.