Aqara Local MCP
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Aqara Local MCP Which Aqara devices are currently on, and show me recent motion events"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Aqara Local MCP
An MCP server that talks to Aqara hubs over your local network using the LANLink protocol, so an AI assistant (Claude Desktop, Claude Code, or any MCP client) can read your Aqara devices, follow live events and, if you allow it, send commands.
Based on Aqara LANLink by Dan Gibson (absent42). The hard part, reverse engineering the LANLink protocol (encrypted tunnel, key exchange, message format, discovery) and building the device catalogue, is his work, published under the MIT license as a Home Assistant integration. This project takes that protocol code and catalogue out of Home Assistant and serves them as an MCP server. If you find this useful, go star the original project. NOTICE.md lists exactly what was copied and what was changed.
Not affiliated with or endorsed by Aqara. The protocol was reverse engineered: a hub firmware update may break it without warning.
Contents
Related MCP server: Home Assistant MCP Server
How it works
MCP client (Claude...)
| stdio, or HTTP + bearer token
v
aqara-local-mcp -----------------------------> Aqara cloud
| login, device list, (once at startup,
| initial values, push subscribe then on demand)
|
| LANLink: encrypted TCP session (ECDH + AES-128)
v
Aqara hub (M3...) <---- Zigbee / Thread / Wi-Fi ----> your devicesLogin. The server logs in to your Aqara account once and caches the session token (file mode 600). LANLink needs this token for the hub to accept the session.
Inventory. It downloads your device list (names, rooms, models, parent hub) from the Aqara cloud.
Local session. It opens an encrypted LANLink session with each hub you configured. Hubs in a cluster (for example two M3) relay each other's devices.
Initial values and push. It reads the current values of every device through the same cloud call the Aqara app uses. That call also arms the hub's push subscription. The hub forgets subscriptions when a connection drops, so they are armed again on every reconnect.
Live events. From then on, every change (motion, door, power, temperature, a light turning on...) arrives locally as a push report from the hub and updates the in-memory state.
Commands. Writes are sent locally to the hub, which forwards them to the device. They are disabled unless you turn them on.
Step | Where |
Account login (then cached) | Aqara cloud |
Device list (names, rooms, models) | Aqara cloud |
Initial values and push subscription | Aqara cloud |
Live events | Local (LANLink) |
Commands | Local (LANLink) |
Why not read everything locally? On current M3 firmware, direct LANLink reads of Zigbee sub-devices time out. Push reports and writes work locally, so the cloud is only used to bootstrap.
Finding the hub. The LANLink port changes every time the hub reboots. The server finds it by mDNS (_aqara-setup._tcp). If the hub is on another VLAN and mDNS does not cross over, it scans the hub's TCP ports and keeps the one that accepts a LANLink handshake. The last known port is cached, so restarts are instant.
Names. Device values are addressed by numeric paths such as 2.132.32920. The catalogue inherited from Aqara LANLink (about 380 models) turns them into readable names (On off, Current power), units, allowed values and whether they are writable.
Requirements
Python 3.11 or newer (Linux, macOS or Windows).
An Aqara hub with LAN control enabled. Tested with two Hub M3 (firmware 4.5.90_0011). Other
lumi1.hubs may work but are not tested.The Aqara account that owns the hub, and its region.
Network access from the machine running the server to the hub (any TCP port; the hub uses a random high port).
Enable LAN control on the hub
In the Aqara Home app: open the hub, then its settings, and turn on LAN control (on the M3 you may also see Hub cluster if you have several hubs). Give the hub a fixed IP address in your router.
Installation
git clone https://github.com/marc3k18/Aqara-Local-MCP.git
cd Aqara-Local-MCP
python3 -m venv .venv
.venv/bin/pip install .Create your configuration:
cp .env.example .env
chmod 600 .envEdit .env (see Configuration), then check that everything connects:
set -a; . ./.env; set +a
.venv/bin/aqara-local-mcp --check--check logs in, connects to the hubs and prints a status like this:
{
"hubs": [
{"name": "Hub M3", "host": "192.168.1.20", "port": 43280, "connected": true, "lan_topology": 11}
],
"devices": 181,
"seed": "running",
"writes": "disabled (read-only)"
}Finding your hub's DID
The DID is lumi1. followed by the hub's MAC address in lowercase without separators, for example MAC 54:EF:44:12:34:56 gives lumi1.54ef44123456. The MAC is in your router or in the Aqara Home app (hub settings, network information). Once the server runs, aqara_list_devices with only_lan=false also shows every hub with its DID.
Configuration
All settings are environment variables. .env.example has every one with comments.
Variable | Default | Purpose |
| Aqara account (required) | |
|
|
|
| Comma separated | |
|
| Allow commands |
|
| Also allow locks, valves, hubs, cameras, garage doors, curtains |
| Only these DIDs can be written (empty: all) | |
|
| Scan the hub's ports when mDNS cannot find it |
|
| Session cache, known ports, audit log |
|
| One JSON line per write |
|
|
|
|
| Listen address in HTTP mode |
| Bearer token, required in HTTP mode | |
| Allowed client IPs or networks (empty: any) | |
| Accepted |
Example:
AQARA_EMAIL=you@example.com
AQARA_PASSWORD=...
AQARA_REGION=US
AQARA_HUBS=lumi1.54ef44123456=192.168.1.20,lumi1.54ef44abcdef=192.168.1.21Connecting an MCP client
Claude Desktop (stdio)
Add this to claude_desktop_config.json:
{
"mcpServers": {
"aqara-local": {
"command": "/path/to/Aqara-Local-MCP/.venv/bin/aqara-local-mcp",
"env": {
"AQARA_EMAIL": "you@example.com",
"AQARA_PASSWORD": "...",
"AQARA_REGION": "US",
"AQARA_HUBS": "lumi1.54ef44123456=192.168.1.20"
}
}
}
}Claude Code (stdio)
claude mcp add aqara-local \
-e AQARA_EMAIL=you@example.com -e AQARA_PASSWORD=... \
-e AQARA_REGION=US -e AQARA_HUBS=lumi1.54ef44123456=192.168.1.20 \
-- /path/to/Aqara-Local-MCP/.venv/bin/aqara-local-mcpHTTP (server, gateway or several clients)
.venv/bin/aqara-local-mcp --generate-token # put it in MCP_HTTP_TOKEN
.venv/bin/aqara-local-mcp --transport httpClients connect to http://<host>:<port>/mcp with the header Authorization: Bearer <token>. To accept connections from other machines, set MCP_HTTP_HOST to the server's IP, restrict MCP_ALLOWED_IPS, and put a reverse proxy in front for TLS (Caddy, nginx, Cloudflare Access, an MCP gateway...). A hardened systemd unit is in deploy/aqara-local-mcp.service.
In HTTP mode the server connects to the hubs at startup and keeps collecting events between requests. In stdio mode it does the same for as long as the client keeps it running.
Tools
Tool | What it does |
| Hubs (connected, LANLink port, seconds since last report), startup progress, write mode |
| Devices with name, room, model, DID, online state, parent hub. Filter by name or room. |
| One device's values with names, units, writable flag, source ( |
| Latest changes pushed by the hubs, newest first, optionally for one device |
| Writes one value (by path, trait code such as |
| Reloads the device list from the account |
Example prompts: "Is anyone in the bathroom?", "What changed in the last ten minutes?", "How much power is the network rack plug drawing?", "Turn off the kitchen ceiling light" (needs writes enabled).
Security
Secure by default. Details in SECURITY.md.
stdio by default: no network port at all.
HTTP is locked down: a bearer token is mandatory (the server will not start without one), it listens on
127.0.0.1by default, an IP allow list is available, andHost/Originheaders are checked against DNS rebinding.Read-only by default:
AQARA_ALLOW_WRITE=trueto allow commands.Sensitive devices need a second switch: locks, water valves, hubs, cameras, security stations, garage doors and curtains also require
AQARA_ALLOW_SENSITIVE=true.Optional allow list:
AQARA_WRITE_ALLOWLISTlimits writes to specific DIDs.Audit log: every write is recorded (time, device, value, hub).
Secrets stay secret: the password, the Aqara token and the HTTP token are masked in logs; state files are created with mode 600.
Tip: create a secondary Aqara account, share your home with it, and use that account here.
Troubleshooting
Symptom | What to check |
| LAN control enabled in the app? Right IP and DID? Can the server reach the hub (firewall between VLANs)? Leave |
| Wrong account or region, or the hub belongs to another account. Delete |
Login fails with | Try another |
Values are old or | Push subscriptions are armed in the background at startup; check |
A device is missing | Matter devices, groups and third party devices are not LANLink devices and are not listed. Devices behind a hub you did not configure are listed but cannot be written. |
Write refused | Read the message: writes disabled, sensitive device, not in the allow list, or read-only value. |
Run with AQARA_LOG_LEVEL=DEBUG to see every frame (secrets stay masked).
Limitations
Tested only with Hub M3. Other LANLink hubs are untested.
Cameras (video, PTZ), scenes and automations are not exposed.
Values of devices missing from the catalogue are shown with their raw path (
show_unknown=true), and are never writable by name.The cloud is still needed at startup (login, device list, initial values).
Development
.venv/bin/pip install -e . pytest
.venv/bin/python -m pytest -qThe catalogue is generated from the Aqara LANLink models:
python3 scripts/build_catalogue.py \
<Aqara-LANLink>/custom_components/aqara_lanlink/device/models \
src/aqara_local_mcp/data/catalogue.json <commit>Project layout:
src/aqara_local_mcp/
lanlink/ LANLink protocol, from Aqara LANLink (absent42)
data/ catalogue.json, from Aqara LANLink device models
config.py environment settings
service.py login, hub sessions, state, events, writes
server.py MCP tools and transports
security.py HTTP bearer token, IP allow list, log masking
tests/ offline tests
deploy/ systemd unit exampleCredits and license
Dan Gibson (absent42) for Aqara LANLink: the LANLink protocol implementation and the device catalogue used here.
Available Tools
6 toolsaqara_get_deviceA
Current values of one device, with names, units and whether each one is writable.
device: name or DID. refresh: read fresh values from the Aqara cloud (also re-arms push). show_unknown: include traits missing from the catalogue (raw paths).
Inputs: device (required), refresh, show_unknown. Returns: result
aqara_list_devicesA
List Aqara devices (name, room, model, DID, online, parent hub).
search: part of the name (case-insensitive). room: part of the room name. only_lan: True keeps the devices reachable through the connected hubs.
Inputs: room, search, only_lan. Returns: result
aqara_recent_eventsB
Latest changes pushed by the hubs over the LAN (newest first).
device: name or DID to filter. include_unknown: also show raw paths missing from the catalogue (radio quality, hub diagnostics...).
Inputs: limit, device, include_unknown. Returns: result
aqara_refresh_inventoryA
Reload the device list (names, rooms, online state) from the Aqara account.
Inputs: no named parameters. Returns: result
aqara_set_valueA
Write one value to a device through the hub, over the LAN.
device: name or DID. trait: path (e.g. 2.132.32920), trait code (OnOff) or name. value: the raw value as a string ("1" on, "0" off, a number, or an enum code). Refused unless the operator enabled writes. Ask the user before calling this.
Inputs: trait (required), value (required), device (required). Returns: result
aqara_statusB
Connection status: hubs, LANLink ports, last report, seed progress, write mode.
Inputs: no named parameters. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool targets a distinct operation: status, list, get, set, events, refresh. The only mild overlap is between aqara_list_devices (local filtered listing) and aqara_refresh_inventory (cloud reload), and between aqara_status's 'seed progress' and inventory reloading, but descriptions clarify these boundaries.
All tools share the aqara_ prefix and snake_case, mostly following verb_noun (list_devices, get_device, set_value, refresh_inventory). Minor deviations: aqara_status is a bare noun and aqara_recent_events uses an adjective, but the pattern remains predictable.
Six tools is well-scoped for a local smart-home hub bridge, covering status, discovery, read, write, events and refresh without redundant entries. Each tool earns its place.
The core lifecycle (inspect connection, list devices, read values, write values, stream events, reload inventory) is covered, enabling full read/write workflows. Gaps are minor: no explicit room/scene listing or device metadata operations, but agents can work around these via existing tools.
Maintenance
Related MCP Connectors
Connect AI assistants to your PCs, browsers, and paired devices via one secure personal hub.
- DNS-DATA RemoteDeprecatedcom.dns-data
Connect AI assistants to authorized Windows and macOS devices for files, commands, and management.
Connect AI assistants to explicitly paired computers, servers, and VMs for permitted remote actions.
Connect AI assistants to your approved computer for files, commands, browser and desktop tasks.
Related MCP Servers
- AlicenseBqualityNot gradedmaintenanceEnables AI assistants to discover and control IoT devices on local networks and via Bluetooth LE.71MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to control Home Assistant via natural language, including device control, automation management, and system monitoring.MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to inspect and operate UniFi Network and Protect devices on a local console, with configurable read-only, action, or full-control permission tiers.3MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI assistants to interact with Home Assistant through natural language, including device control, state queries, service execution, and management of automations, scripts, dashboards, and backups.MIT