npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@martyndevries/xiaomi-miio

v1.0.5

Published

Zero-dependency Node.js library for Xiaomi miIO protocol

Readme

xiaomi-miio

NPM Version NPM Downloads Node Version License Build Status CodeQL Coverage Dependencies Semantic Release

Zero-dependency Node.js TypeScript library for communicating with Xiaomi devices via the miIO protocol.

miIO is Xiaomi's local LAN protocol used by many devices (fans, lamps, etc.) for discovery and command/control. It is UDP-based, uses a 32-byte header, and encrypts JSON-RPC payloads with AES-128-CBC.

This library focuses on the protocol and transport layer only:

  • No device-specific logic (that lives in the Homey app in this repo)
  • No external dependencies
  • No filesystem access

Requirements

  • Node.js 22+
  • npm 10+

Install

npm install @martyndevries/xiaomi-miio

Background and references

  • miIO binary protocol notes: https://github.com/OpenMiHome/mihome-binary-protocol
  • miIO protocol notes (archived): https://github.com/OpenMiHome/mihome-binary-protocol/blob/master/doc/PROTOCOL.md
  • Xiaomi developer portal: https://developers.xiaomi.com
  • Xiaomi IoT platform: https://iot.mi.com
  • Similar projects:
    • python-miio: https://github.com/rytilahti/python-miio
    • miio (Node.js): https://www.npmjs.com/package/miio

Run locally

cd xiaomi-miio
npm install
npm run build

The build compiles TypeScript to dist/ and is required before consuming the library from other packages.

Run tests:

npm run test:dev

Tests compile to dist-test/ and run with Node's built-in test runner.

Examples

Bedside Lamp 2 CLI (interactive control of a single device):

npm run example:bedlamp2

This will prompt for the device IP and token, perform a handshake, and then let you send simple commands.

Discovery CLI (scan the local network for miIO devices via UDP broadcast):

npm run example:discovery

This prints each responding device with its IP address, device ID, and stamp. Tokens are optional.

DNS hostname lookup CLI (reverse lookup by IP address):

npm run example:hostname

You will be prompted for the IP address and optional port.

Minimal usage (TypeScript)

This example connects to a known device IP and token, turns it on, and sets the speed level.

import { MiioDevice, MiioProtocol } from '@martyndevries/xiaomi-miio';

const device = new MiioDevice({
  address: '192.168.1.50',
  token: MiioProtocol.tokenFromHex('00112233445566778899aabbccddeeff'),
  model: 'zhimi.fan.sa1',
});

const info = await device.connect();
console.log('Device ID:', info.deviceId);

await device.call('set_power', ['on']);
await device.call('set_speed_level', [50]);

device.destroy();

Discovery usage (TypeScript)

This example broadcasts a discovery packet and prints all devices that respond.

import { discoverMiioDevices } from '@martyndevries/xiaomi-miio';

const devices = await discoverMiioDevices({ timeout: 3000, includeToken: false });
for (const device of devices) {
  console.log(`${device.address} id=${device.deviceId} stamp=${device.stamp}`);
}

Contributing

  • Martyn de Vries (Maintainer)

Contributions are welcome — see CONTRIBUTING.md for how to get started.