Local Control and Filter DRM in a Xiaomi Air Purifier


The Xiaomi Mi Air Purifier 3H can be controlled over the local network.

To obtain the secret required for that local control, I first had to log into Xiaomi’s cloud.

Its replaceable air filter also contains an NFC tag which records whether Xiaomi thinks the filter should still be usable.

This was another product which was physically in my home but not entirely mine in software.

The wrong purifier protocol

In September 2022 I set out to automate my Xiaomi Mi Air Purifier 3H units locally. The purifier identifies itself as zhimi.airpurifier.mb3. Older Xiaomi purifier integrations used the company’s miIO interface, but the 3/3H generation had moved to MIoT properties and services.

That distinction was easy to miss because both were hidden behind the same product family and much of the older documentation still looked applicable. Using the ordinary purifier commands produced errors. The correct python-miio target was airpurifiermiot:

miiocli airpurifiermiot --ip ADDRESS --token TOKEN status
miiocli airpurifiermiot --ip ADDRESS --token TOKEN set_mode favorite
miiocli airpurifiermiot --ip ADDRESS --token TOKEN set_favorite_level 7

Once the protocol and model were correct, local operations covered power, mode, fan level, PM2.5, temperature, humidity, LEDs, child lock, buzzer and filter state.

The awkward part was TOKEN.

Cloud-assisted local control

Each purifier had a 32-character hex token used to authenticate local packets. The practical way to recover it was Piotr Machowski’s Xiaomi cloud-token extractor.

I created a Python virtual environment, installed python-miio, logged into my Xiaomi account and let token_extractor.py probe servers across regions (cn, de, us, ru, tw, sg, in, i2) until it found the devices on the European de server. It returned their local addresses, MAC addresses, models and tokens.

After that bootstrap, the purifier could be controlled directly on the LAN. But the architecture was familiar from Tuya: “local control” was a capability unlocked by asking a remote account service for a device secret.

Provisioning could change tokens. Discovery did not naturally cross every subnet or VLAN arrangement. The credentials had to be stored as encrypted secrets rather than casual config values.

The appliance did not need Xiaomi’s servers for each fan-speed change. My ability to establish that relationship still depended on them.

When the sensor is thirty minutes old

The public MIoT v2 schema (urn:miot-spec-v2:device:air-purifier:0000A007:zhimi-mb3) made the purifier’s properties inspectable, but exposing a property did not guarantee useful update behavior.

One python-miio issue documented the PM2.5 value changing only roughly every thirty minutes. The workaround was to keep poking the purifier’s aqi_realtime_update_duration property (siid: 13, piid: 9):

miiocli airpurifiermiot --ip ADDRESS --token TOKEN \
  raw_command set_properties \
  "[{'did': 'aqi_realtime_update_duration', 'siid': 13, 'piid': 9, 'value': 5}]"

I wrapped that in a NixOS systemd oneshot service triggered every five seconds (OnUnitActiveSec = "5s"), reading the token from an agenix secret.

The sensor, the local protocol and the schema all work. The number returned by a reasonable polling loop is still stale unless the client knows an undocumented behavioral precondition.

The filter has an opinion

The cylindrical HEPA H13 filter (M8R-FLH) is a consumable, so replacing it periodically is reasonable. What is less obviously necessary is the NXP NTAG213 NFC tag attached to the bottom of it.

The purifier reads the tag’s 7-byte UID and a password-protected usage counter in page 0x08. Unethical Info’s writeup—building on Flaming’s Tech’s reverse engineering—showed that the 4-byte password is derived by hashing the UID with SHA-1 and indexing four bytes from the digest using the last byte of the UID.

In March 2024 I generated the passwords for two filters and sent three raw ISO 14443-3A frames with NFC Tools:

1B<password>,3008,A20800000000

1B authenticates (PWD_AUTH), 3008 reads page 0x08 and A20800000000 writes four zero bytes back to the counter. The purifier immediately reported the filters as having full life remaining again.

That did not settle the more important question: whether a reused or aftermarket filter actually filtered air as well as an original. Resetting a counter proves that the counter is software, not that the filter material is good.

A match in a tent

I bought both aftermarket and original filters and tried to compare them.

The improvised test used a match as a particle source inside a tent. The idea was to create a small, repeatable dirty-air volume and observe how the purifier behaved with each filter.

The result was inconclusive. Consumer PM2.5 sensing, airflow, smoke distribution, starting conditions and the tent itself introduced too many uncontrolled variables for me to defend a ranking.

For the next replacement, I went back to an original filter.

That outcome may look anticlimactic after reverse-engineering the NFC password derivation. It was the honest one. Defeating the tag prevented the purifier from making the purchasing decision for me. It did not supply evidence that the cheaper filter was equivalent.

Two different ownership problems

The purifier contained two different kinds of software restriction.

The first was access control around local networking. The hardware supported LAN control, but establishing it required a token recovered through Xiaomi’s cloud account system.

The second was control over a physical consumable. The filter’s condition was represented partly by actual material and partly by a writable authenticated counter.

In both cases, reverse engineering restored a choice rather than producing a predetermined answer.

With the token, I could choose how to automate the purifier. With the NFC reset, I could choose whether a filter remained in service. I still needed to decide what was safe and useful.

Open access to a device does not remove judgment. It makes the judgment mine.