Skip to main content

Midea-local python lib

Python build codecov

中文版 / Chinese README

Control your Midea M-Smart appliances via local area network.

This library is part of https://github.com/georgezhao2010/midea_ac_lan code. It was separated to segregate responsibilities.

⭐If this component is helpful for you, please star it, it encourages me a lot.

Getting started

Finding your device

from midealocal.discover import discover

# Without knowing the ip address
discover()
# If you know the ip address
discover(ip_address="203.0.113.11")
# The device type is in hexadecimal as in midealocal/devices/TYPE
type_code = hex(list(discover().values())[0]["type"])[2:]

Getting data from device

from midealocal.discover import discover
from midealocal.devices import device_selector

token = "..."
key = "..."

# Get the first device
d = list(discover().values())[0]
# Select the device
ac = device_selector(
    name="AC",
    device_id=d["device_id"],
    device_type=d["type"],
    ip_address=d["ip_address"],
    port=d["port"],
    token=token,
    key=key,
    device_protocol=d["protocol"],
    model=d["model"],
    subtype=0,
)

# Connect and authenticate
ac.connect()

# Getting the attributes
print(ac.attributes)
# Setting the temperature
ac.set_target_temperature(23.0, None)
# Setting the swing
ac.set_swing(False, False)

command line tool

python3 -m midealocal.cli -h

midea-local.json config file

python3 -m midealocal.cli save writes your cloud username, password and cloud name to midea-local.json in the current directory (use --user to save it to your user config folder instead). Every midealocal.cli command then loads that file automatically, so you don't have to pass --username/--password/--cloud-name again.

{
  "username": "user@example.com",
  "password": "your-cloud-password",
  "cloud_name": "SmartHome"
}

All fields are optional; only include what you need. Run python3 -m midealocal.cli discover -h for the full option list.

midea-devices.json token/key cache

Every device needs a token/key pair, normally fetched from the cloud on each run. discover caches the pair that successfully connects to a device in midea-devices.json, keyed by device_id, and tries that cached pair first on every later run — before contacting the cloud at all. In practice this means only the first discover/setattr run for a given device needs your cloud credentials. If a cached key ever stops working (e.g. the device was re-paired), discover automatically falls back to fetching a fresh key from the cloud and updates the cache. The file is managed automatically; you don't need to create or edit it yourself.

{
  "devices": [
    {
      "device_id": "146235046630006",
      "token": "...",
      "key": "..."
    }
  ]
}

Development

This project uses uv for its development environment. After installing uv:

git clone --recurse-submodules https://github.com/midea-lan/midea-local.git
cd midea-local
./scripts/setup.sh          # Linux / macOS / WSL2  (Windows: scripts\setup.ps1)

This creates a .venv, installs all dependencies, initializes or updates the Lua submodule to the latest main branch, and sets up the prek hooks in both repositories. The setup script also initializes the submodule if you cloned without --recurse-submodules. Run tools with uv run, e.g. uv run python -m pytest ./tests/. See the contributing guide for the full workflow and per-OS uv install instructions.

Contributing Guide

CONTRIBUTING 中文版CONTRIBUTING

Metadata

Release files for midea-local 15.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 midea-local 15.0.0
File Size Uploaded Provenance Actions
midea_local-15.0.0.tar.gz 193.7 kB With provenance Details for midea_local-15.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for midea-local 15.0.0
File Interpreter ABI Platform Actions
midea_local-15.0.0-py3-none-any.whl Python 3 none any Details for midea_local-15.0.0-py3-none-any.whl

Total release size: 442.2 kB

Release files / midea_local-15.0.0.tar.gz

Download URL midea_local-15.0.0.tar.gz
Size 193.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5f3443c7e82feb5c1a1bf0ef90cd5aa4f33a9f2db2c024538b0bb6543a2afd11
BLAKE2b-256 checksum
How to use checksums
3391784f5c8243e30bf3dff951c0a8126e245b794778909404f6d54698db6008
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 Oct 29, 2026.

Transparency log

Release files / midea_local-15.0.0-py3-none-any.whl

Download URL midea_local-15.0.0-py3-none-any.whl
Size 248.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
288097a4d1055aaae5117dcb3cfd6952a5a54de9f3ff2cdbe002765014bca59a
BLAKE2b-256 checksum
How to use checksums
732ecde38336dc7512bd4890952e28dae4e1e6d5ecfb00591307fb8033fb249e
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 Oct 29, 2026.

Transparency log

Security for midea-local 15.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 midea_local-15.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 29, 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.

Release history Release notifications | RSS feed

This release

15.0.0 This release

2 release files Full provenance

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