Glen Akins Pythonizes a Set of XMCOSY RGBW Patio Lights for Automated Per-Light Control

With some oscilloscope-staring and traffic-sniffing, Akins gets some low-cost patio lights talking to WLED — and to Python via TinyTuya.

Glen Akins has redecorated his garden with low-cost off-the-shelf RGB LED patio lights — cleverly reverse-engineered and upgraded for compatibility with WLED and, optionally, TinyTuya.

"Two years ago, I hung a set of generic G50 RGB globe lights in the backyard. They weren't exactly waterproof and the individual lights became waterlogged and started acting erratically," Akins writes by way of background to the project. "This year, I replaced them with two sets of XMCOSY+ RGBW Patio String Lights. The new XMCOSY lights look great and I like that there's real white LEDs in them so they can provide both decoration and functional illumination for my backyard."

The lights are designed to be controlled from the Tuya Smart Life smartphone app, being based on a Tuya microcontroller board. "I think the app is adequate for most people's needs," Akins says. "I intend to use the Smart Life app most of the time with these lights but was interested in being able to control them from crontab and a Python script."

While Tuya provides an application programming interface (API) for this, Akins decided to attack the problem a different way: reverse-engineering the control signals, finding — with a quick look at the oscilloscope traces — that the lights used the WS2811 protocol at 800kHz with 5V signalling.

With that information in hand, Akins was able to control the lights from an Athom Tech WLED controller — providing support for Christian Schwinne's popular lighting control system on an Espressif ESP32 microcontroller, with Athom's particular board adding infrared and radio-frequency remote compatibility.

Then, Akins switched to something he hadn't tried before: the TinyTuya Python library, which can use Tuya's official Internet of Things (IoT) cloud service to generate the keys required to issue commands entirely locally. "The basics worked well enough," Akins writes of the library, "but what I really wanted to do was set the colors of all the bulbs separately.

By sniffing the traffic between the official phone app and the lights, Akins was able to figure out a way to format the messages for per-light control. "Each color is specified with a tuple containing the six parameters [required]," Akins writes of the resulting Python script. "The colors will be repeated if there’s more lights on the string than colors specified in the dictionary."

This isn't Akins' first shot at figuring out how to get more flexibility from off-the-shelf RGB LED lighting: in November last year he published a post documenting experimentation with "a few sets of random LED lights from third-party sellers on Amazon," all of which resulted in at least partial WLED compatibility.

Akins' full write-up is available on his blog, along with the source code for the per-light Python control script.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles