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-keep 80 120
warm to 80 C and keep warm 120 min: water at 41 C, idle, no fault.
About to send set_properties:
  (2,4) = 80
  ...
Start heating? [y/N] y
status: heating, 41 C, 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).
kettle warm-to <40-99> Heats to that temperature in °C, then stops.
kettle warm-keep <40-99> <60-1440> Heats to that temperature and keeps it warm for that many minutes (1-24 h).
kettle cancel 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.

Useful flags go before the command: --dry-run (print the requests, send nothing), --yes (skip the heating confirmation), --debug (raw packets), --ip, --token.

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 print exactly what they will send and ask y/N (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.

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-to 70              # 70 °C, then stop (green tea)
kettle warm-keep 85 90         # 85 °C and keep it there for 90 minutes
kettle cancel                  # stop everything
kettle --dry-run warm-to 70    # 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-to 70, status, quit). Keep-warm time is limited by the kettle to 60-1440 minutes, and the target temperature to 40-99 °C; anything else is rejected before it is sent.

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 reports fault ...": check the water level and that the kettle sits on its base. Fault codes are not documented by Xiaomi; 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.0.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.0.0
File Size Uploaded Provenance Actions
kettle_x2p_cli-1.0.0.tar.gz 31.5 kB With provenance Details for kettle_x2p_cli-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 53.3 kB

Release files / kettle_x2p_cli-1.0.0.tar.gz

Download URL kettle_x2p_cli-1.0.0.tar.gz
Size 31.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0c731ee950b5c968a6b629e9f3aa0f7a9f0ccd9139394e981552c15b83ac1f93
BLAKE2b-256 checksum
How to use checksums
c25b511279dab0524f9ce3d0dd9d6ece3ff9168b1e29b4428946d7b306df95c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 16, 2026.

Transparency log

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

Download URL kettle_x2p_cli-1.0.0-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e77fb87526799407eadba9cea4d6499d39892ab8b8f9829df3a47134b793f41
BLAKE2b-256 checksum
How to use checksums
bcd006c1363c1556651ca0c1ecb64ae7042af06dafdab49909c6393555beb4c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 16, 2026.

Transparency log

Security for kettle-x2p-cli 1.0.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.0.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 Oct 16, 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