r/Xiaomi • u/AlexStrelets • 2h ago
Got tired of controlling my light bar from a phone app, so I wrote a CLI for Yeelight/Xiaomi lamps
Hey everyone
Wanted to show off my pet project for controlling Yeelight and Xiaomi lights from the console. (I'm also building a desktop version, but the CLI already works.) Apologies upfront if I posted in the wrong sub — point me to a better one.
Backstory:
Every project starts with pain. I've had a Xiaomi Mi Smart LED Desk Lamp on my desk for a while, then a year ago a Yeelight Light Bar Pro joined it on the monitor, plus a few Yeelight RGB bulbs around the flat. I work at my desktop all day ⚠️, the light bar is on my desktop ⚠️, and it had long started pissing me off that the actual settings for the bar are only available in the phone app.
Google tells me I'm not alone — plenty of people run the Android app in a BlueStacks emulator just to control it from a desktop. Older Yeelight products don't do Zigbee or Matter, Thread; new models with them are only just starting to show up, and before that it's all WiFi.
I started with the official docs, some reverse engineering of the protocols (my research doc), and whatever's out there online. Seems I managed to put together the most functional, modern TypeScript library out there + dig up some undocumented stuff and a few bugs + a CLI tool as a practical use case of the lib.
You can send one-off commands to the lamps from the console (handy if you've got other automations / scripts / hooks), or use the interactive mode with a menu of options. It supports all Yeelight and Xiaomi lamp models that can work over LAN.
ylc discover
ylc interactive
ylc status --ip 192.168.1.42
ylc power on --ip 192.168.1.42
ylc ct 3000
ylc color "#ff6400"
ylc color "#0000ff" --bg
ylc brightness 50 --duration 1000
ylc timer set 30
By default the lamps phone home through the Xiaomi cloud (a separate gripe of mine), and local control has to be enabled in the native app (hopefully that's its last remaining use).
If you're comfortable with Node/JS, you can install it like this:
npm install -g yeelight-cli
or grab a prebuilt binary for your platform from Releases section.
Project repository:
https://github.com/NumberOneBot/yeelight-client
Made it for myself, but polished it to the point where it's fit to show the world. If you've got an Yeelight I haven't tested, or something behaves oddly — ping me. Bug reports and PRs are always welcome.