niceboygithub / AqaraGateway

Aqara Gateway/Hub integration for Home Assistant
470 stars 62 forks source link

A new way to read/write Aqara device resources #242

Open stackia opened 3 months ago

stackia commented 3 months ago

Hi @niceboygithub , recently I found a new way to read/write gateway hubs by utilizing /tmp/miio_agent.socket.

There is a ha_agent process that actually act as an IPC message broker for all other processes (ha_master / ha_basis / ha_driven / ppcs / vidicon / etc.). ha_agent creates an unix seqpacket socket /tmp/miio_agent.socket that anyone can connect without authentication / encryption. So it's possible for us to write our own program to send/receive to/from /tmp/miio_agent.socket.

And luckily it's very easy to find the message format / available commands from the logs of ha_master / ha_driven / ha_lanbox.

I made a small utility (aqara-agent2mqtt) to expose the miio_agent.socket to MQTT. (Because I just have a patched G3, all these work are only tested on G3.)

With auto.control command, we can almost control everything, including IR ("8.0.2092": "{\"mode\":0,\"len\":311,\"ircode\":\"...\"}"), PTZ ("14.88.85": "{\"x\":0,\"y\":0}") and many non-zigbee resources that are previously not available in zigbee/send topic! By listening to auto.report, we can get real-time resources updates too.

We can even read/write/subscribe other unpatched gateways in the same LAN with lanbox.control command! (though LAN subscription works with some caveats)

I'm currently working on updating the HA integration to use these new capabilities.

Because I only have a G3, I probably need some hands to help test if that works on other devices.

niceboygithub commented 3 months ago

I know that.

niceboygithub commented 3 months ago

https://github.com/AlexxIT/openmiio_agent/pull/5

niceboygithub commented 3 months ago

I have more interest in that to trigger an IR learn and get the learned IR code. Do you have any idea how to do it?