miio.gateway.gateway module

Xiaomi Gateway implementation using Miio protecol.

exception miio.gateway.gateway.GatewayException[source]

Bases: DeviceException

Exception for the Xioami Gateway communication.


Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class miio.gateway.gateway.Gateway(ip: Optional[str] = None, token: Optional[str] = None, start_id: int = 0, debug: int = 0, lazy_discover: bool = True, *, model: Optional[str] = None, push_server=None)[source]

Bases: Device

Main class representing the Xiaomi Gateway.

Use the given property getters to access specific functionalities such as alarm (for alarm controls) or light (for lights).

Commands whose functionality or parameters are unknown, feel free to implement! * toggle_device * toggle_plug * remove_all_bind * list_bind [0] * bind_page * bind * remove_bind

  • self.get_prop(“used_for_public”) # Return the ‘used_for_public’ status, return value: [0] or [1], probably this has to do with developer mode.

  • self.set_prop(“used_for_public”, state) # Set the ‘used_for_public’ state, value: 0 or 1, probably this has to do with developer mode.

  • welcome

  • set_curtain_level

  • get_corridor_on_time

  • set_corridor_light [“off”]

  • get_corridor_light -> “on”

  • set_default_sound

  • set_doorbell_push, get_doorbell_push [“off”]

  • set_doorbell_volume [100], get_doorbell_volume

  • set_gateway_volume, get_gateway_volume

  • set_clock_volume

  • set_clock

  • get_sys_data

  • update_neighbor_token [{“did”:x, “token”:x, “ip”:x}]

## property getters * ctrl_device_prop * get_device_prop_exp [[sid, list, of, properties]]

## scene * get_lumi_bind [“scene”, <page number>] for rooms/devices

buttons() List[ButtonDescriptor]

Return a list of button-like, clickable actions of the device.


Alarm clock.

async close()[source]

Cleanup all subscribed events and registered callbacks.

configure_wifi(ssid, password, uid=0, extra_params=None)

Configure the wifi settings.


Discovers SubDevices and returns a list of the discovered devices.


Enable root telnet acces to the operating system, use login “admin” or “app”, no password.

gateway_push_callback(action: str, params: str)[source]

Callback from the push server regarding the gateway itself.


Return the developer API key.

classmethod get_device_group()

Get SubDevices from a dict containing at least “mac”, “did”, “parent_id” and “model”.

This dict can be obtained with the micloud package: https://github.com/squachen/micloud


Get illumination.

In lux?


Get the value of a property for given sid.


Get the value of a bunch of properties for given sid.

get_properties(properties, *, property_getter='get_prop', max_properties=None)

Request properties in slices based on given max_properties.

This is necessary as some devices have limitation on how many properties can be queried at once.

If max_properties is None, all properties are requested at once.

  • properties (list) – List of properties to query from the device.

  • max_properties (int) – Number of properties that can be requested at once.


List of property values.

info(*, skip_cache=False) DeviceInfo

Get (and cache) miIO protocol information from the device.

This includes information about connected wlan network, and hardware and software versions.


bool (skip_cache) – Skip the cache

match_type_id(type_id, sid)[source]

Match the type_id to obtain the model_info.

match_zigbee_model(zigbee_model, sid)[source]

Match the zigbee_model to obtain the model_info.

push_callback(source_device: str, action: str, params: str)[source]

Callback from the push server.

raw_command(command, parameters)

Send a raw command to the device. This is mostly useful when trying out commands which are not implemented by a given device instance.

  • command (str) – Command to send

  • parameters (dict) – Parameters to send

register_callback(id: str, callback: Callable[[str, str], None])[source]

Register a external callback function for updates of this subdevice.

remove_callback(id: str)[source]

Remove a external callback using its id.

send(command: str, parameters: Optional[Any] = None, retry_count: Optional[int] = None, *, extra_parameters=None) Any

Send a command to the device.

Basic format of the request: {“id”: 1234, “method”: command, “parameters”: parameters}

extra_parameters allows passing elements to the top-level of the request. This is necessary for some devices, such as gateway devices, which expect the sub-device identifier to be on the top-level.

  • command (str) – Command to send

  • parameters (dict) – Parameters to send

  • retry_count (int) – How many times to retry on error

  • extra_parameters (dict) – Extra top-level parameters

  • model (str) – Force model to avoid autodetection


Send initial handshake to the device.

sensors() Dict[str, SensorDescriptor]

Return sensors.


Set the developer API key.

set_prop(property, value)[source]

Set the device property.

settings() Dict[str, SettingDescriptor]

Return list of settings.

setup_device(dev_info, model_info)[source]

Setup a device using the SubDeviceInfo and model_info.

status() DeviceStatus

Return device status.

switches() Dict[str, SwitchDescriptor]

Return toggleable switches.


Get current timezone.

update(url: str, md5: str)

Start an OTA update.

update_progress() int

Return current update progress [0-100].


Return current update state.

property alarm: Alarm

Return alarm control interface.

property device_id: int

Return device id (did), if available.

property devices

Return a dict of the already discovered devices.

property light: Light

Return light control interface.

property mac

Return the mac address of the gateway.

property model: str

Return device model.

property radio: Radio

Return radio control interface.

property raw_id: int

Return the last used protocol sequence id.

retry_count = 3
property subdevice_model_map

Return the subdevice model map.

supported_models = ['lumi.gateway.v3', 'lumi.gateway.mieu01', 'lumi.gateway.mgl03', 'lumi.gateway.aqhm01', 'lumi.acpartner.v1', 'lumi.acpartner.v2', 'lumi.acpartner.v3']
timeout = 5
token: Optional[str]
property zigbee: Zigbee

Return zigbee control interface.