midea-local
v0.1.1
Published
Local control of Midea smart air conditioners
Maintainers
Readme
midea-local
This is a straight port. I put zero real effort into this.
All credits, fame, and glory belong to Tucker Kern and the original Python project midea-msmart. That's where the actual reverse-engineering, protocol analysis, and hard work happened. I just ran it through a transpiler-shaped meat grinder. Go star the original repo.
What is this?
A Bun/TypeScript port of msmart-ng — a library for local network control of Midea (and associated brands) smart air conditioners. No cloud dependency at runtime, everything talks directly to the device over your LAN.
How it works
- Discovery — Sends UDP broadcast packets on ports 6445/20086. Devices respond with encrypted payloads containing their ID, serial number, and protocol version (V2 or V3).
- Authentication — V3 devices require a token/key pair fetched once from Midea's cloud API (NetHomePlus). After that, communication is fully local.
- Control — Commands are framed in Midea's proprietary binary protocol (
0xAAheader for V2,0x8370wrapper for V3), sent over TCP to port 6444.
Zero npm dependencies. Uses node:crypto, node:net, and node:dgram.
Usage
bun add midea-local # or just clone this repoToggle a device on/off
import { Discover } from "midea-local";
import { AirConditioner } from "midea-local";
// Find the device
const device = await Discover.discoverSingle("192.168.1.100");
// Authenticate (only needed once for V3 devices)
await Discover.connect(device, {
account: "[email protected]",
password: "yourpassword",
});
// Read current state
await device.refresh();
console.log(`Power: ${device.powerState ? "ON" : "OFF"}`);
console.log(`Temperature: ${device.indoorTemperature}°C`);
// Toggle power
device.powerState = !device.powerState;
await device.apply();Discover all devices on the network
const devices = await Discover.discover({
account: "[email protected]",
password: "yourpassword",
});
for (const device of devices) {
console.log(`${device.name} @ ${device.ip} (${device.sn})`);
}Run the example
bun run examples/toggle.ts <ip> <account> <password>Supported devices
- AC (
0xAC) — Residential air conditioners (AirConditioner) - CC (
0xCC) — Commercial air conditioners (CommercialAirConditioner)
License
Same as the original — MIT.
