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

node-red-contrib-mi-fan

v1.0.0

Published

Node-RED nodes for controlling Xiaomi Mi Smart Fans via local network

Readme

node-red-contrib-mi-fan

Node-RED nodes for controlling Xiaomi Mi Smart Fans over the local network using the MIoT protocol.

Built on top of the excellent xmihome library.

Installation

Install via the Node-RED Manage Palette menu, or run:

cd ~/.node-red
npm install node-red-contrib-mi-fan

Requirements

  • Node.js >= 18.0.0
  • Node-RED >= 4.0.0
  • A Xiaomi Mi Smart Fan on the same local network
  • The fan's device token (see Getting the Token)

Nodes

Fan Out (mi-fan)

Sends commands to a Xiaomi Mi Smart Fan. Set msg.payload to an object with one or more of the following properties:

| Property | Type | Values | Description | |---|---|---|---| | power | boolean | true / false | Turn the fan on or off | | mode | string | "straight", "natural" | Wind mode | | fanLevel | number | 1–4 | Fan level preset | | fanSpeed | number | 1–100 | Fan speed percentage | | swingMode | boolean | true / false | Oscillation on/off | | swingModeAngle | number | 30, 60, 90, 120, 140 | Oscillation angle in degrees | | childLock | boolean | true / false | Child lock on/off | | buzzer | boolean | true / false | Buzzer on/off | | light | boolean | true / false | LED indicator on/off | | setMove | string | "left", "right" | Nudge the fan head |

Only include the properties you want to change — omitted properties are left untouched. The message is passed through on success, so you can chain multiple nodes together.

Fan In (mi-fan-status)

Queries all current properties from the fan. Send any message to trigger a status request. The node replaces msg.payload with an object containing all readable properties:

power, mode, fanLevel, fanSpeed, swingMode, swingModeAngle, childLock, buzzer, light, powerOffTime

Mi Fan Config (mi-fan-config)

Shared configuration node used by both Fan Out and Fan In. Stores:

  • IP Address — the fan's local IP
  • Token — the device token (encrypted by Node-RED's credential system)
  • Model — the fan model identifier

Getting the Token

Every Xiaomi MiIO device requires a device token for local communication. The config node includes a built-in Scan Network feature that makes this easy:

  1. Open any Fan Out or Fan In node and click the edit button next to the config
  2. Click Scan Network — this discovers all Xiaomi MiIO devices on your local network
  3. Devices are shown in a list; fans are highlighted with a green badge
  4. If the device token was obtained during discovery, click Use to auto-fill the IP and token
  5. If the token is blanked out (this is common), click Get Token to retrieve it from the Xiaomi Cloud
  6. Enter your Mi Home account credentials and select your region (de, us, cn, sg, in, ru, tw)
  7. If your account has two-factor authentication enabled, you will be prompted for the verification code

[!IMPORTANT] Your Mi Home credentials are used once for the cloud request and are never stored. Only the retrieved device token is saved, encrypted by Node-RED's credential system.

Alternative Methods

  • xmihome CLI — Run npx xmihome to discover devices and retrieve tokens from the command line
  • Manual entry — If you already know your fan's IP and token, enter them directly in the config node

Example Flow

Import this flow into Node-RED to get started quickly:

[
    {
        "id": "a1b2c3d4e5f60001",
        "type": "inject",
        "z": "a1b2c3d4e5f60000",
        "name": "Fan On – Natural 50%",
        "props": [{ "p": "payload" }],
        "repeat": "",
        "payload": "{\"power\":true,\"fanSpeed\":50,\"mode\":\"natural\"}",
        "payloadType": "json",
        "x": 190,
        "y": 100,
        "wires": [["a1b2c3d4e5f60002"]]
    },
    {
        "id": "a1b2c3d4e5f60002",
        "type": "mi-fan",
        "z": "a1b2c3d4e5f60000",
        "name": "",
        "fan": "a1b2c3d4e5f60010",
        "x": 430,
        "y": 100,
        "wires": [[]]
    },
    {
        "id": "a1b2c3d4e5f60003",
        "type": "inject",
        "z": "a1b2c3d4e5f60000",
        "name": "Get Status",
        "props": [{ "p": "payload" }],
        "repeat": "",
        "payload": "{}",
        "payloadType": "json",
        "x": 170,
        "y": 220,
        "wires": [["a1b2c3d4e5f60004"]]
    },
    {
        "id": "a1b2c3d4e5f60004",
        "type": "mi-fan-status",
        "z": "a1b2c3d4e5f60000",
        "name": "",
        "fan": "a1b2c3d4e5f60010",
        "x": 370,
        "y": 220,
        "wires": [["a1b2c3d4e5f60005"]]
    },
    {
        "id": "a1b2c3d4e5f60005",
        "type": "debug",
        "z": "a1b2c3d4e5f60000",
        "name": "Fan Status",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "x": 570,
        "y": 220,
        "wires": []
    },
    {
        "id": "a1b2c3d4e5f60010",
        "type": "mi-fan-config",
        "name": "Living Room Fan",
        "ip": "192.168.1.42",
        "model": ""
    }
]

[!TIP] After importing, double-click the Living Room Fan config node to set your fan's actual IP address and token.

Credits

All Xiaomi device communication — local MiIO protocol, cloud authentication, device discovery, and MIoT spec support — is provided by the excellent xmihome library.

Dependencies

  • xmihome — Xiaomi MiIO/MIoT device communication
  • zod — Runtime type validation

License

MIT