miio.miioprotocol module

miIO protocol implementation.

This module contains the implementation of routines to send handshakes, send commands and discover devices (MiIOProtocol).

class miio.miioprotocol.MiIOProtocol(ip: str | None = None, token: str | None = None, start_id: int = 0, debug: int = 0, lazy_discover: bool = True, timeout: int = 5)[source]

Bases: object

static discover(addr: str | None = None, timeout: int = 5) Any[source]

Scan for devices in the network. This method is used to discover supported devices by sending a handshake message to the broadcast address on port 54321. If the target IP address is given, the handshake will be send as an unicast packet.


addr (str) – Target IP address

send(command: str, parameters: Any | None = None, retry_count: int = 3, *, extra_parameters: Dict | None = None) Any[source]

Build and send the given command. Note that this will implicitly call send_handshake() to do a handshake, and will re-try in case of errors while incrementing the _id by 100.

  • command (str) – Command to send

  • parameters (dict) – Parameters to send, or an empty list

  • retry_count – How many times to retry in case of failure, how many handshakes to send

  • extra_parameters (dict) – Extra top-level parameters


DeviceException – if an error has occurred during communication.

send_handshake(*, retry_count=3) <Struct>[source]

Send a handshake to the device.

This returns some information, such as device type and serial, as well as device’s timestamp in response.

The handshake must also be done regularly to enable communication with the device.


DeviceException – if the device could not be discovered after retries.

property raw_id