How I made Tuya-Local work with full color controls

HOWTO: TuyaLocal and full color control under HomeAssistant

I spent a lot of time- weeks- trying to find instructions for how to do all of this. I never did find a coherent decription of how to do any of this, so I figured I’d help those who come after me. I have personally observed this process to work for DayBetter and Feit Electric smart bulbs. It probably works for other generic Tuya-based bulbs that can be controlled with the SmartHome app. Thanks to Tinkerer and NR in the HomeAssistant Discord for giving me enough foundational knowledge to make this HOWTO possible.

Before beginning: Install HACS first, then use HACS to install LocalTuya. Use the web page at GitHub - rospogrigio/localtuya: local handling for Tuya devices for instructions on how to do this. This same page includes instructions for how to set up an account at iot.tuya.com, which is required for getting access to the encryption key on each bulb. Don’t skip this step, and follow the instructions very precisely.

This HOWTO assumes you already have python and NMP installed.

If you haven’t already, install the tuya-cli utility by doing this at the command prompt:

  npm i @tuyapi/cli -g

Pairing the bulbs: Follow the instructions on the box that the bulbs came in (they may vary depending on the time of manufacture and the firmware installed.) Use a piece of tape and label each bulb so you can keep track of which one goes where. Make a note of the bulb friendly name and leave room for the IP address and encryption key. Write small if you have to.

It helps to keep order and sanity if you set up static IP addresses assignments for each of the bulbs in your router or DHCP server. If the bulbs change addresses, you can lose local control of each bulb, but cloud-based control will continue to work. This can be somewhat confusing and annoying.

Keep track of the names, tuya device IDs and IP addresses as you go. After the bulbs are checked in, you can use the tuya-cli utility to collect the encryption keys from each bulb.

After the bulbs are added, use the tuya-cli utility to get the encryption keys for each bulb/device. From the command line, execute this:

tuya-cli wizard

You will be asked for your API credentials on the first run, but those will get cached for subsequent runs. After that you will be asked for a single device ID for one of the tuya devices in your network. All it needs is one. The utility will produce JSON-formatted text containing the names, device IDs and encryption keys for each device attached to your tuya developer account. Make notes of these and don’t lose them.

Adding the bulbs to LocalTuya:
I added mine one at a time. There may be other ways, but the one at a time model gave me some stability in the process. Act as the spirit moves you. When adding the bulbs, there are many options in three separate steps.

The first step is where you pick a bulb from the list of known tuya devices, by its IP address and the name listed in the Tuya app.

The second step is where you give the bulb a frienldy name and put in the encryption key. Scroll down to the bottom of the data entry form and ensure that the bulb is listed as “20” with a checkmark beside it.

If this second step is successful, in the third step you will be asked what type of device this is. Answer that it is a “light.” If the IP address of the bulb has changed (look for static IP, above) You will be brought back to the second step.

The fourth (final) step is to add the particular data points for the bulb.
Set “Brightness” to “22”.
Set “Color Temperature” to “22”.
Set “Color Mode” to “21”
Set “Color” to “24”
All other setpoints can remain in their original state.

I have to admit that none of these settings make the slightest bit of sense to me. I found these settings to work through brute force twiddling the values over a very long period of time and learned that these particular gave me color wheel, temperature and brightness settings that I wanted to have access to. I will gladly revise and extend this howto if anyone discovers how a better way to do it.

2 Likes

Thanks just what i needed