Skip to main content

kettle

Control your Xiaomi Smart Kettle 2 Pro from the Terminal: boil, heat to a temperature, keep warm for up to 24 hours, check the state or stop it. Everything runs over your own Wi-Fi, directly to the kettle - no Xiaomi Home app and no cloud connection when you use it.

$ kettle warm 80 --keep 2
warm to 80 C and keep warm at 80 C for 2 h: water at 41 C, idle, no fault (0).
Start heating? [y/N] y
status: water at 41 C, heating to 80 C, no fault (0).

Written for the EU model (BHR9107EU, xiaomi.kettle.v20, 1.7 L, 1800 W), tested on firmware 2.2.7_0016. It has no dependencies except Python itself. This is the standalone tool and a documented protocol reference (SPEC.md) made just for fun... or not. Setting a kettle right from the Terminal while working is pretty neat, actually :)


Features

Command What it does
kettle setup Guided first-time setup: asks for the token, finds the kettle, checks and saves it.
kettle boil Heats to boiling (99 °C, the kettle's boil mode), then stops.
kettle warm <40-99> Heats to that temperature in °C, then stops.
kettle cancel (or stop) Stops heating / keep-warm.
kettle status State, current temperature, target, fault, keep-warm settings.
kettle shell Interactive session with the same commands.
kettle info Model, firmware and MAC from the kettle.
kettle find Finds the kettle on the network again if its IP changed.

Call options

Go right after kettle, before the command.

  • --ip <address> - Kettle IP address (default: the one saved by kettle setup).
  • --token <32 hex> - Kettle token (default: the saved one).
  • --force-model - Send commands even to a model other than xiaomi.kettle.v20. The property IDs may differ there, so only use it if you know they match.
  • -h, --help - Show the help and exit.
  • -v, --version - Show the version and exit.

Command options

Go after the command, e.g. kettle warm 70 --dry-run. kettle <command> --help shows the ones it accepts.

  • -k, --keep [[<40-99>] <1-24>] - For boil and warm: after heating, keep the water warm at that temperature for that many hours (fractions like 1.5 and h:mm like 1:30 work). Both parts are optional: the temperature defaults to the heating target (99 °C for boil), the time to 1 hour, and a single value is the time.
  • -y, --yes - For boil, warm and shell: skip the heating confirmation.
  • -v, --verbose - For boil, warm and shell: show the set_properties request before heating. After the command, -v is --verbose; before it, -v is still --version.
  • -f, --force-on - For boil and warm: also write on=true (2,7). Normally not needed: the request alone starts heating. Use it only if kettle reports that the kettle stayed idle although the water is colder than the target.
  • --dry-run - For boil, warm, cancel, shell and provision: print the requests, send nothing.
  • --timeout <seconds> - Seconds to wait for a reply from the kettle (default: 3).
  • --debug - Print the raw packets and requests.

--yes, --verbose, --dry-run, --timeout and --debug can also be given to kettle shell, then they apply to every command typed in it.

Safety. Heating commands refuse to start unless the kettle is a xiaomi.kettle.v20, idle, on its base and reporting no fault, and a status read that fails or is unclear never starts anything. They ask y/N (add --verbose to see exactly what they will send) (without a terminal, --yes is required). This model has no water-level reading, so a low-water condition only shows up as a fault code. Heat water remotely only when you know the kettle has water in it.


Installation

kettle is available from a variety of sources. pip or brew is recommended, because they have a convenient way to manage updates automatically.

  1. pip (Recommended for everyone with a Python environment)
    • You can check if you have Python installed by running python --version in the Terminal or cmd.
    • For Mac and Linux users, there is a high chance that you already have Python installed on your system.
    • For Windows users, you can download Python from the official website. The tool is built and tested for macOS and Linux; it should work on Windows too, but that is untested.
    • After confirmation, install kettle through the PyPI package manager, typing pip install kettle-x2p-cli in the Terminal. For Mac users, you may need to use pip3 instead of pip. The package is called kettle-x2p-cli; the command it installs is kettle.
    • Verify the installation with kettle --version.
    • You are perfect, you can use the app with kettle from any folder in your system.
  2. brew (Recommended for Mac and Linux users)
    • Type brew tap manefunction/tap in your Terminal to add my custom tap (app source) to your brew sources, if you haven't already.
    • Type brew install kettle to install the application itself.
    • Verify the installation with kettle --version.
    • You are perfect, you can use the app with kettle from any folder in your system.
  3. Python package (manual installation, for advanced users)
    • Clone the repository or download the source code from GitHub.
    • Go to the folder with the code in your Terminal.
    • Run pip install . to install kettle to your system.
    • Run kettle --version to verify the install.
  4. Ready-to-use Windows binary (for Windows users without Python)
    • Download kettle.exe from the GitHub Releases page.
    • Since it isn't code-signed, Windows SmartScreen may warn about an unrecognized publisher the first time you run it — click "More info" → "Run anyway" to proceed.
    • Open Command Prompt or PowerShell, cd to the folder with kettle.exe, and run .\kettle.exe --version to verify it works.
    • You are perfect, you can use the app with .\kettle.exe. The binary is built automatically for each release; CI only checks that it starts and reports the right version, so the Windows build is less tested than macOS and Linux.

Updates arrive with pip install --upgrade kettle-x2p-cli or brew upgrade. Your saved kettle settings live outside the install (~/.config/kettle/), so upgrading or reinstalling never loses them. (pip may ask you to use a virtual environment or pipx on newer systems; pipx install kettle-x2p-cli is a good fit for a command line tool.)


First-time setup

Run kettle setup and follow the instructions on the screen. It takes about five minutes the first time and is never needed again unless you re-pair the kettle.

  1. Add the kettle to the Xiaomi Home app (iOS / Android) so it joins your 2.4 GHz Wi-Fi.
  2. Get the kettle's token with the free, open-source Xiaomi Cloud Tokens Extractor. The setup screen shows the exact commands for Windows, macOS and Linux. It asks for your Xiaomi login and lists your devices with their tokens; copy the 32-character token of Xiaomi Smart Kettle 2 Pro (xiaomi.kettle.v20).
  3. Paste the token into kettle setup (the input is hidden). It scans your network, tries the token on every Xiaomi device it finds, and the one that answers is your kettle.
  4. It checks the model and saves everything to ~/.config/kettle/config.json (readable by you only).

Then try kettle status. Reserve the kettle's address in your router (DHCP reservation) so it never moves; if it does, kettle find locates it again.

For scripts, skip the prompts: kettle --token <token> --ip <ip> setup. Note that a token typed on the command line is visible in your shell history, so the interactive prompt is the safer way.

Why the Xiaomi app and cloud are needed once

The kettle talks to the local network with a secret 16-byte token, and only Xiaomi's cloud keeps it for you. On firmware 2.2.7 the kettle changes that token when it joins your Wi-Fi, so the token it shows while in setup mode stops working afterwards. I tried the alternatives (including the app's own extra provisioning parameters, kettle provision --app-params); none gave a usable token without the cloud. After the one-time extraction, all control is local. If you re-pair or reset the kettle, the token changes and you run kettle setup again.


Usage

kettle status                  # what is it doing?
kettle boil                    # asks for confirmation, then heats to boiling
kettle warm 70                 # 70 °C, then stop (green tea)
kettle warm 85 --keep 1.5      # 85 °C and keep it there for 1.5 hours
kettle warm 85 --keep 1:30     # the same, written as hours:minutes
kettle warm 85 -k 60 2         # 85 °C, then keep it at 60 °C for 2 hours
kettle warm 60 --keep          # 60 °C and keep 60 °C for the default hour
kettle boil -k 60 2            # boil, then keep at 60 °C for 2 hours
kettle boil -k 3               # boil and keep 99 °C for 3 hours
kettle boil --keep             # boil and keep 99 °C for an hour
kettle stop                    # stop everything (same as cancel)
kettle warm 70 --dry-run       # show what would be sent
kettle shell                   # keep a session open

In kettle shell you type the same commands without the kettle prefix (boil, warm 70, status, stop, quit). Keep-warm time is limited by the kettle to 1-24 hours, and the target temperature to 40-99 °C; anything else is rejected before it is sent.

Output is coloured in a terminal and plain when piped or redirected. Set NO_COLOR=1 to turn the colours off, or FORCE_COLOR=1 to keep them in a pipe.

Troubleshooting

  • "no reply from ...": the kettle is offline, the IP changed (kettle find), or the token is out of date (the kettle silently ignores requests it cannot decrypt). Run kettle setup again if you re-paired it.
  • Setup does not find the kettle: your computer and the kettle must be on the same network (no guest network or VLAN between them). You can enter the IP by hand; it is in your router's client list.
  • "kettle fault: something wrong (N)": check the water level and that the kettle sits on its base. Fault codes are not documented by Xiaomi; no fault (0) means none.

How it works

The kettle speaks Xiaomi's miio protocol over UDP port 54321: a hello handshake that returns the device id and a timestamp, then JSON-RPC calls encrypted with AES-128-CBC keyed from the token. Its functions are described by a MIoT spec (service/property numbers); the ones used here are listed in SPEC.md. The client is a few hundred lines of standard-library Python, including its own AES, and handles re-handshakes and timestamp drift by itself.


Development

python3 -m venv .venv && .venv/bin/pip install -e .
.venv/bin/python -m unittest discover -s tests -v

The tests run against a fake kettle on the loopback interface that speaks the real wire format; nothing touches a real device. The release workflow checks that the tag matches src/kettle/__init__.py, builds the package and publishes it to PyPI and creates the GitHub release; the Homebrew formula is bumped automatically.


Credits

This is an unofficial project and is not affiliated with Xiaomi.

Repository info

This repo follows the Conventional Commits specification.

GitHub release (latest by date) GitHub All Releases PyPI version PyPI downloads GitHub Sponsors

Metadata

Release files for kettle-x2p-cli 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kettle-x2p-cli 1.4.0
File Size Uploaded Provenance Actions
kettle_x2p_cli-1.4.0.tar.gz 45.2 kB With provenance Details for kettle_x2p_cli-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kettle-x2p-cli 1.4.0
File Interpreter ABI Platform Actions
kettle_x2p_cli-1.4.0-py3-none-any.whl Python 3 none any Details for kettle_x2p_cli-1.4.0-py3-none-any.whl

Total release size: 74.7 kB

Release files / kettle_x2p_cli-1.4.0.tar.gz

Download URL kettle_x2p_cli-1.4.0.tar.gz
Size 45.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6764c24f9c0b6fd78296f2ed853f723ea6dca8b7600d2549063a2d52a81d3ea8
BLAKE2b-256 checksum
How to use checksums
feac61dccc40100332b1657924d953a51c00654a3c763b6ca1ee49fa3017d8a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Release files / kettle_x2p_cli-1.4.0-py3-none-any.whl

Download URL kettle_x2p_cli-1.4.0-py3-none-any.whl
Size 29.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79c680c5d493ff8dd5ea33467ef05596e2d9d0dc3eea030c80cf20b8b23205e9
BLAKE2b-256 checksum
How to use checksums
e37a3dfb7940b043eb5e401dfbbe446a5fcd2939e0139b200c6c7a0544cf809f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Security for kettle-x2p-cli 1.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kettle_x2p_cli-1.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page