{"id":9109,"library":"micloud","title":"Mi Cloud Connect Library","description":"The `micloud` library provides a Python interface to connect to Xiaomi's cloud services, allowing programmatic interaction with Xiaomi IoT devices registered to an account. It is currently at version 0.6 and has an irregular release cadence based on feature additions and bug fixes.","status":"active","version":"0.6","language":"en","source_language":"en","source_url":"https://github.com/squachen/micloud","tags":["xiaomi","iot","cloud","smart-home"],"install":[{"cmd":"pip install micloud","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"HTTP client for API communication.","package":"requests","optional":false}],"imports":[{"symbol":"MiCloud","correct":"from micloud import MiCloud"},{"symbol":"MiCloudAccessDenied","correct":"from micloud.exceptions import MiCloudAccessDenied"}],"quickstart":{"code":"import os\nfrom micloud import MiCloud\n\n# It's highly recommended to specify your server region explicitly.\n# Common regions: 'de' (Germany, default), 'cn' (China), 'us' (USA), 'ru' (Russia).\n# Replace with the region your Xiaomi account is registered in.\nMI_CLOUD_SERVER = os.environ.get('MI_CLOUD_SERVER', 'de') \nMI_CLOUD_USERNAME = os.environ.get('MI_CLOUD_USERNAME', 'your_email@example.com')\nMI_CLOUD_PASSWORD = os.environ.get('MI_CLOUD_PASSWORD', 'your_password')\n\ntry:\n    micloud = MiCloud(MI_CLOUD_USERNAME, MI_CLOUD_PASSWORD, server=MI_CLOUD_SERVER)\n    micloud.login()\n    print(f\"Successfully logged in to Xiaomi Cloud (server: {MI_CLOUD_SERVER}).\")\n    \n    devices = micloud.get_devices()\n    if devices:\n        print(f\"Found {len(devices)} devices:\")\n        for device in devices:\n            print(f\"  - Name: {device.get('name', 'N/A')}, Model: {device.get('model', 'N/A')}, ID: {device.get('did', 'N/A')}\")\n    else:\n        print(\"No devices found associated with this account and server.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please check your credentials, server region, and network connection.\")\n","lang":"python","description":"This quickstart logs into the Xiaomi Cloud using environment variables for credentials and then retrieves a list of connected devices. It's crucial to specify the correct `server` region matching your Xiaomi account."},"warnings":[{"fix":"Update your error handling to catch `micloud.exceptions.MiCloudAccessDenied` specifically when dealing with login failures.","message":"As of v0.4, failed login attempts due to invalid credentials now raise a specific `MiCloudAccessDenied` exception. Code that previously caught generic exceptions for authentication failures might need an update.","severity":"breaking","affected_versions":">=0.4"},{"fix":"Pass the correct server region to the `MiCloud` constructor: `MiCloud(username, password, server='cn')`. Common server codes include 'cn' (China), 'us' (USA), 'ru' (Russia), 'de' (Germany).","message":"The `MiCloud` constructor defaults the `server` parameter to 'de' (Germany). If your Xiaomi account is registered to a different region (e.g., US, CN, RU), you must explicitly specify it, or you may encounter 'no devices found' or login issues.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `micloud` version 0.5 or newer to ensure correct encryption handling: `pip install --upgrade micloud`.","message":"Versions prior to 0.5 may experience issues with ARC4 encryption, potentially leading to connection failures or incorrect data for some devices or specific API calls.","severity":"gotcha","affected_versions":"<0.5"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the package using pip: `pip install micloud`","cause":"The `micloud` package is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'micloud'"},{"fix":"Double-check your Xiaomi account credentials for typos or ensure the account exists and is active. You might also try logging in via the official Xiaomi Home app or website to confirm.","cause":"The provided username (email/phone) or password for your Xiaomi account is incorrect.","error":"micloud.exceptions.MiCloudAccessDenied: Invalid credentials"},{"fix":"When initializing `MiCloud`, explicitly set the `server` parameter to your account's region (e.g., 'cn', 'us', 'ru', 'de'): `micloud = MiCloud(username, password, server='cn')`","cause":"This often indicates that the specified server region does not match the region your Xiaomi account is registered in. The default server is 'de'.","error":"micloud.exceptions.MiCloudException: Unexpected response from server: HTTP 403 (or 'No devices found' when devices are expected)"}]}