Home

Awesome

openmiio_agent

This project allows you to significantly extend the functionality of your gateways on the original firmware, keeping almost all default functionality of the device in the Xiaomi Mi Home ecosystem.

Features

Supported gatewayXiaomi Multimode GatewayXiaomi Multimode Gateway 2Aqara Hub E1
Supported modelsZNDMWG03LM<br>ZNDMWG02LMDMWG03LM<br>ZNDMWG04LMZHWG16LM
Mi Home Zigbeeyesyesyes
Mi Home BLE+Meshyesyesno
HomeKit for Zigbeeyesnoyes
Beeper and Alarmyesnono
Buggy hardwareyesnono
Zigbee rangehighunknownmedium

Comments

Install

This binary embed into Home Assistant custom integration Xiaomi Gateway 3. Integration can automatically:

But you can download binary manually from latest release.

Run

All agruments are optional:

/data/openmiio_agent miio central mqtt cache z3 --zigbee.tcp=8888 --log.level=trace

miIO

mosquitto_sub -t miio/command_ack
mosquitto_pub -t miio/command -m '{"method":"get_common_lib_version","params":[]}'

ZHA and zigbee2mqtt

Support on-demand access to zigbee chip via TCP for ZHA and zigbee2mqtt projects.

By default, the standard gateway software will work with the zigbee chip. At the first connection to the TCP port the standard software will be stopped.

Important: Zigbee devices can't work simultaniously with MiHome and ZHA/zigbee2mqtt.

All of your thanks for supporting the EZSP in zigbee2mqtt can say to @kirovilya.

FeatureZHAzigbee2mqtt
Support EFR32 EZSP (gateway's chip)excellentexperimental
Support EZSPv7 (original chip firmware)excellentexperimental
Support EZSPv8 (custom chip firmware)excellentexperimental
Keep MiHome network settingsyesno

When using ZHA, you can switch from MiHome mode to ZHA mode at any time. You won't need to repair your devices. But may need additional reconfiguration.

When you return from ZHA to MiHome mode, your old MiHome devices will continue to work. But, new ZHA devices will not appear.

zigbee2mqtt will replace the chip settings with its own. You will lose all your paired devices.

When returning from zigbee2mqtt mode to MiHome mode, you need to reset the gateway to factory settings.

Lua

With lua scripts you can:

Important

Code

Place file openmiio_agent.lua next to the binary:

json = require("json")

function miio_request(from, method, req)
    -- prevent beeper for Motion Sensor 5 sec hack
    if from == 4 and method == "local.status" and req:find("dev_query_connect") then
        return nil
    end

    if from <= 0 then
        if method == "cli" then
            req = json.decode(req)
            os.execute("sh -c '" .. req.params[1] .. "'")
            local res = { id = req.id, result = { "ok" } }
            miio_send(from, json.encode(res))
            return nil -- prevent request to local
        end
    end
end

function miio_response(to, method, req, res)
    if to == 4 then
        if method == "_sync.zigbee3_bind" then
            req = json.decode(req)
            res = { id = req.id, result = { code = 0, message = "ok" } }
            return json.encode(res)
        end
    end
end

MQTT

TopicAppModeDescription
gw/IEEE/commandsZ3GatewayHostsubscribecommands to zigbee stack (Silabs format)
gw/IEEE/executedZ3GatewayHostpublishexecuted commands
gw/IEEE/heartbeatZ3GatewayHostpublishzigbee network alive messages (1 min)
gw/IEEE/MessageReceivedZ3GatewayHostpublishraw messages from zigbee stack
miio/commandopenmiio_agentsubscribecommands to gateway (miIO format)
miio/command_ackopenmiio_agentpublishresponse on commands
miio/reportopenmiio_agentpublishupdates from gateway to cloud
miio/report_ackopenmiio_agentpublishresponse from cloud to gateway
central/reportopenmiio_agentpublishupdates from bluetooth to central app
openmiio/logopenmiio_agentpublishopenmiio_agent logs in JSON format
openmiio/reportopenmiio_agentpublishopenmiio_agent alive messages (30 sec)
broker/pingzigbee_agentpublishzigbee_agent alive message
zigbee/recvzigbee_agentsubscribecommands to zigbee stack (Lumi format)
zigbee/sendzigbee_agentpublishresponse from zigbee stack

openmiio/report

{
  "gateway": {
    "model": "lumi.gateway.mgl03",
    "firmware": "1.5.4_0090",
  },
  "miio": {
    "cloud_state": "cloud_connected",
    "cloud_starts": 123,    // online status attempts
    "cloud_uptime": "10s"   // online status duration (from app start)
  },
  "openmiio": {
    "version": "1.1.1",
    "uptime": "10s"         // openmiio run duration
  },
  "serial": {
    "bluetooth_rx": 12345,  // number of bytes read from UART
    "bluetooth_tx": 12345,  // number of bytes write to UART
    "bluetooth_oe": 123,    // number of errors
    "zigbee_rx": 12345,
    "zigbee_tx": 12345,
    "zigbee_oe": 123
  },
  "zigbee": {
    "tcp_remote": "192.168.1.123:12345",
    "tcp_starts": 123,      // TCP connection attempts
    "tcp_uptime": "10s",    // TCP connection duration
    "z3_starts": 123,       // Z3 app run attempts
    "z3_uptime": "10s"      // Z3 app run duration
  }
}