Skip to main content

xiaomi-vacuum-sdk

Sponsor

Async Python SDK for Xiaomi MIoT robot vacuums: local control over the encrypted MIoT UDP protocol, and rendering of the cloud map blob to PNG.

Built as a focused replacement for python-miio + vacuum-map-parser-xiaomi covering exactly the surface a vacuum integration needs — no legacy miIO protocol, no CLI, no device discovery. Reference models are the Xiaomi Robot Vacuum X20 Max (xiaomi.vacuum.d109gl) and S20+ (xiaomi.vacuum.b108gl); the API is model-agnostic and takes MIoT property/action addresses as input.

Install

pip install xiaomi-vacuum-sdk

Requires Python >= 3.13. Runtime dependencies: cryptography, pillow.

Local control

from xiaomi_vacuum_sdk import ActionAddress, MiotClient, PropertyAddress

client = MiotClient(host="192.168.1.50", token="ffffffffffffffffffffffffffffffff")
try:
    info = await client.info()
    print(info.model, info.firmware_version)

    state = await client.get_properties(
        {
            "status": PropertyAddress(siid=2, piid=1),
            "battery_level": PropertyAddress(siid=3, piid=1),
        }
    )
    print(state)

    await client.call_action(ActionAddress(siid=2, aiid=1))
    await client.set_property(PropertyAddress(siid=7, piid=4), 1)
finally:
    await client.close()

All calls are async-native (asyncio UDP transport, no threads). Errors form a typed hierarchy rooted at MiotError:

  • MiotConnectionError — network failure or response timeout.
  • MiotDeviceError — the device answered with a non-zero error code (code, message attributes).
  • MiotAckTimeoutError — the device accepted the command but never sent the ack (Xiaomi vacuums do this routinely while busy); a distinct type so callers can choose optimistic handling.

Map rendering

from xiaomi_vacuum_sdk import MapRenderer, RenderOptions

renderer = MapRenderer(RenderOptions())
png = renderer.render(blob, model="xiaomi.vacuum.d109gl", device_id="412345678")

blob is the encrypted map exactly as downloaded from the Xiaomi cloud (get_file_url object storage). The renderer absorbs the format quirks — model-derived AES key, optional {"data": "<base64>"} envelope, zlib inflate — and returns finished PNG bytes. Rendering is CPU-bound and sync; wrap it in an executor inside async applications.

RenderOptions controls palette, room colors, drawn layers, scale and element sizes; every field has a sensible default.

When the caller also needs the map behind the image — to place overlays, or to translate a click on the PNG back into device coordinates — use render_map, which parses the blob once and hands back the geometry it drew from:

rendered = renderer.render_map(blob, model="xiaomi.vacuum.d109gl", device_id="412345678")

rendered.png          # the same bytes render() returns
rendered.map_data     # the parsed MapData: grid size, origin, resolution, features
rendered.coordinates  # the CoordinateSystem that projection used

x, y = rendered.coordinates.to_image(rendered.map_data.vacuum)
device_point = rendered.coordinates.to_device(x, y)  # a MapPoint, in millimeters

CoordinateSystem.to_device is the exact inverse of to_image, so consumers never have to reimplement the scale, border and Y-flip the renderer applied.

Dreame-built models

Dreame-built vacuums sold under the Xiaomi brand (e.g. the X20+, xiaomi.vacuum.c102gl) store a different map format in the cloud: a url-safe base64 zlib frame (pixel grid plus a JSON trailer), optionally in a saved-map envelope. Decode it with DreameMapDecoder, then draw it with the same renderer:

from xiaomi_vacuum_sdk import DreameMapDecoder, MapRenderer

map_data = DreameMapDecoder().decode(blob)
rendered = MapRenderer().render_map_data(map_data)

map_data.segments  # (MapSegment(id=1, name="Living room", room_type=0), ...)

The segment ids are the ones the vacuum's room-clean command takes. Every segment is listed; name is empty for one the user never named (the app shows those as "Room N"). Encrypted Dreame frames (a ,<key> suffix) are not supported yet and raise MapDecryptError.

Support

This SDK is built and maintained on personal time, on hardware bought for the purpose. If it is useful to you, consider sponsoring the work — it keeps the devices, the testing and the releases coming.

License

MIT.

Metadata

Release files for xiaomi-vacuum-sdk 0.1.2

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

Source distribution (sdist)

Source distribution for xiaomi-vacuum-sdk 0.1.2
File Size Uploaded Provenance Actions
xiaomi_vacuum_sdk-0.1.2.tar.gz 88.7 kB Without provenance Details for xiaomi_vacuum_sdk-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xiaomi-vacuum-sdk 0.1.2
File Interpreter ABI Platform Actions
xiaomi_vacuum_sdk-0.1.2-py3-none-any.whl Python 3 none any Details for xiaomi_vacuum_sdk-0.1.2-py3-none-any.whl

Total release size: 124.1 kB

Release files / xiaomi_vacuum_sdk-0.1.2.tar.gz

Download URL xiaomi_vacuum_sdk-0.1.2.tar.gz
Size 88.7 kB
Tags Source
SHA-256 checksum
How to use checksums
638e95a0d149fd8f0a482b86e7f5dd3f049b840a94e7dc6f97a076a1d7174708
BLAKE2b-256 checksum
How to use checksums
ece04341a9eb06b9e3071b746f2a499796ba15c677044dee09db03f01974b9fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / xiaomi_vacuum_sdk-0.1.2-py3-none-any.whl

Download URL xiaomi_vacuum_sdk-0.1.2-py3-none-any.whl
Size 35.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
614f2a3796c30fd149bc111213e2bdc8ef47fccdc7be5dd23486cd688684859c
BLAKE2b-256 checksum
How to use checksums
a3fe6952d3afee3807490e8a76be5b0c922790763c5199d723a15443f91d5ba7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for xiaomi-vacuum-sdk 0.1.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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