This project extends Home Assistant's Xiaomi integration to add MQTT-powered control for the Xiaomi Smart Air Purifier 4 Lite, enabling precise speed control through MQTT topics. This allows seamless integration and enhanced functionality within Home Assistant.
This project should not need to exist. However, the default installation of the Xiaomi add-on and this particular air filter does not support fan speed control. This integration uses the latest miio
tools, which do support it but are currently in an alpha state and not directly usable in Home Assistant. Thus, this very simple and lightweight integration was created.
- Full Speed Control: Adjust fan speed via MQTT topics.
- State Updates: Publish the current state and speed percentage of the air purifier.
- Home Assistant Discovery: Automatically configure the integration in Home Assistant.
- MQTT-Based Communication: Lightweight and efficient control over MQTT.
- Xiaomi Smart Air Purifier 4 Lite
- Home Assistant
- MQTT Broker
- Python 3.10 # Required by miio tools
- Xiaomi device token and IP address (use
miio
tools to extract these)
Create a .env
file or set the following environment variables:
XIAOMI_IP=AIR_PURIFIER_IN
XIAOMI_TOKEN=AIR_PURIFIER_TOKEN
MQTT_HOSTNAME=YOUR_MQTT_BROKER_HOST
MQTT_PORT=1883 # Default MQTT port
MQTT_USERNAME=YOUR_MQTT_USERNAME
MQTT_PASSWORD=YOUR_MQTT_PASSWORD
MQTT_NAME_TOPIC=xiaomi-air-purifier-speed
BASE_MQTT_TOPIC=zhimi-airp-rmb1
A Dockerfile
is provided for containerized deployment. Build and run the container:
docker build -t xiaomi-air-purifier .
docker run -d --env-file .env xiaomi-air-purifier
Here is a simple example of using docker-compose
to run the integration, including .env
file integration:
services:
xiaomi-air-purifier:
build:
context: https://github.com/Keeo/zhimi-airp-rmb1.git
dockerfile: Dockerfile
container_name: xiaomi-air-purifier
environment:
XIAOMI_IP: YOUR_DEVICE_IP
XIAOMI_TOKEN: YOUR_DEVICE_TOKEN
MQTT_HOSTNAME: YOUR_MQTT_BROKER_HOST
MQTT_PORT: 1883 # Default MQTT port
MQTT_USERNAME: YOUR_MQTT_USERNAME
MQTT_PASSWORD: YOUR_MQTT_PASSWORD
MQTT_TOPIC: xiaomi-air-purifier-speed
BASE_MQTT_TOPIC: zhimi-airp-rmb1
restart: unless-stopped
Save the above configuration in a docker-compose.yml
file. Then, deploy the container using:
docker-compose up -d
-
Clone this repository:
git clone https://github.com/your-repo/xiaomi-air-purifier cd xiaomi-air-purifier
-
Install dependencies:
pip install -r requirements.txt
-
Run the script:
python main.py
Topic | Description |
---|---|
zhimi-airp-rmb1/availability |
Availability state (online /offline ). |
zhimi-airp-rmb1/on/state |
Current power state (ON /OFF ). |
zhimi-airp-rmb1/on/set |
Command to turn the device on or off. |
zhimi-airp-rmb1/speed/percentage_state |
Current fan speed percentage (1-13). |
zhimi-airp-rmb1/speed/percentage_set |
Command to set the fan speed (1-13). |
This integration supports Home Assistant's MQTT Discovery. Once the script is running, the device will automatically appear in Home Assistant.
The integration exposes the air purifier as a fan entity with percentage-based speed control.
- Device Connection Issues: Ensure the IP and token are correct.
- MQTT Connection Issues: Check your broker's hostname, port, username, and password.
- Logs: Review logs for errors (uses
loguru
for detailed logging).
Contributions are welcome! Feel free to submit issues or pull requests.
This project is licensed under the MIT License. See the LICENSE file for details.
This project uses the following libraries: