1. Confirm Hardware and Network Settings
Before connecting Xiaomi2mqtt to Aquara hardware devices, ensure all hardware devices are properly configured. This includes:
- The Aqara gateway is powered on and connected to your local network via Wi-Fi.
- The Aqara devices you intend to connect (such as sensors and switches) are added to the Aqara gateway and operational.
2. Install and Configure MQTT Server
Xiaomi2mqtt is a bridging service that forwards data from Xiaomi/Aqara devices to an MQTT server. Therefore, an MQTT server must be running. If not installed, you can use popular MQTT servers such as Mosquitto or RabbitMQ. For example, installing Mosquitto can be done with the following commands:
bashsudo apt-get install mosquitto sudo systemctl enable mosquitto.service sudo systemctl start mosquitto.service
3. Install Xiaomi2mqtt
Next, install Xiaomi2mqtt. This is typically done via npm; ensure Node.js and npm are installed on your system. Then run the following command:
bashnpm install -g xiaomi2mqtt
4. Configure Xiaomi2mqtt
After installation, configure Xiaomi2mqtt to connect to your Aqara gateway and MQTT server. This usually involves editing the xiaomi2mqtt configuration file or providing necessary information via command-line arguments when starting the service.
A basic configuration example is:
bashxiaomi2mqtt --gateway.key=YOUR_GATEWAY_KEY --mqtt.url=mqtt://localhost
YOUR_GATEWAY_KEYis your Aqara gateway's developer key, which can be obtained from the Aqara gateway app.mqtt://localhostis the address of the MQTT server.
5. Start Xiaomi2mqtt
After configuration, start the Xiaomi2mqtt service by running the following command:
bashxiaomi2mqtt
6. Verify Connection
After starting the service, Xiaomi2mqtt will begin listening for messages from the Aqara gateway and publish them to the MQTT server. You can use MQTT client tools like MQTT.fx or subscribe to specific topics from another terminal to verify successful data reception:
bashmosquitto_sub -h localhost -t 'xiaomi/#' -v
This will subscribe to all messages published by Xiaomi2mqtt and display them.
Summary
By following these steps, you can successfully connect Xiaomi2mqtt to Aquara hardware devices and ensure data flows to the MQTT server. This provides a foundation for further home automation integrations. If you encounter any issues during implementation, check network settings, key configurations, and log outputs of related services.