### Install MerossIot from GitHub Source: https://albertogeniola.github.io/MerossIot/_sources/installation.rst.txt Manually install the MerossIot library from its GitHub repository. This involves cloning the repository, installing dependencies, and then installing the library. ```bash git clone https://github.com/albertogeniola/MerossIot.git ``` ```bash cd MerossIot ``` ```bash pip install -r requirements.txt ``` ```bash pip install . ``` -------------------------------- ### Install MerossIot Library Source: https://albertogeniola.github.io/MerossIot/_sources/installation.rst.txt Install the latest MerossIot library using pip. Ensure you have Python 3.7+ installed. ```bash pip install meross-iot --upgrade ``` -------------------------------- ### Meross Cloud Credentials Setup Source: https://albertogeniola.github.io/MerossIot/api-reference/http.html Configuration options for establishing Meross cloud credentials. These parameters influence how the library authenticates and interacts with the Meross cloud service. ```APIDOC ## Meross Cloud Credentials Configuration ### Description Configuration options for establishing Meross cloud credentials. These parameters influence how the library authenticates and interacts with the Meross cloud service. ### Parameters #### Request Body - **creds_env_var_name** (string) - Optional - If set, indicate which env variables stores such credentials - **http_proxy** (string) - Optional - Optional http proxy to use when to performing the request - **ua_header** (string) - Optional - User Agent header to use when issuing the HTTP request - **stats_counter** (object) - Optional - Stats counter object - **app_type** (string) - Optional - App Type header parameter to use - **app_version** (string) - Optional - App Version header parameter to use - **country_code** (string) - Optional - (experimental) The country code you are connecting from - **agree_to_terms** (integer) - Optional - (optional) if 1 means we agree, if 0 or omitted, means we do not agree to terms - **mfa_code** (string) - Optional - (optional) MFA code - **auto_retry_on_bad_domain** (boolean) - Optional - when set, tells the library to retry the login when BadDomain occurs, osing the right domain value returned by the initial operation. ### Returns - **MerossCloudCreds** (object) - A MerossCloudCreds object containing the established credentials. ``` -------------------------------- ### Configure Wi-Fi Credentials via HTTP POST Source: https://albertogeniola.github.io/MerossIot/_sources/meross-protocol.rst.txt Provides the device with base64-encoded Wi-Fi SSID and password to finalize the network connection setup. ```http method: POST host: path: /config headers: "Content-Type: application/json" body: { "header": { "from": "http://10.10.10.1/config", "messageId": "{{MESSAGE_ID}}", "timestamp": {{TIMESTAMP}}, "sign": "{{SIGNATURE}}", "method": "SET", "namespace": "Appliance.Config.Wifi" }, "payload": { "wifi": { "ssid": "{{BASE64_ENCODED_SSID}}", "password": "{{BASE64_ENCODED_PASSWORD}}" } } } ``` -------------------------------- ### Load device registry from file Source: https://albertogeniola.github.io/MerossIot/advanced-topics.html Initializes the manager by loading a previously saved device registry dump. ```python # ... # Init the manager and load the dump, so that we don't need to issue a discovery manager = MerossManager(http_client=http_api_client) await manager.async_init() manager.load_devices_from_dump("test.dump") print("Registry dump loaded.") ``` -------------------------------- ### Get Current Spray Mode Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/diffuserspray.html Retrieves the current spray mode configuration for the specified channel. ```python get_current_spray_mode(channel : int = 0, * args, ** kwargs) → DiffuserSprayMode | None ``` -------------------------------- ### List Meross devices Source: https://albertogeniola.github.io/MerossIot/quick-start.html Initializes the Meross manager and performs device discovery using user credentials. ```python 1import asyncio 2import os 3 4from meross_iot.http_api import MerossHttpClient 5from meross_iot.manager import MerossManager 6 7EMAIL = os.environ.get('MEROSS_EMAIL') or "YOUR_MEROSS_CLOUD_EMAIL" 8PASSWORD = os.environ.get('MEROSS_PASSWORD') or "YOUR_MEROSS_CLOUD_PASSWORD" 9 10 11async def main(): 12 # Setup the HTTP client API from user-password 13 http_api_client = await MerossHttpClient.async_from_user_password(email=EMAIL, password=PASSWORD, api_base_url="https://iot.meross.com") 14 15 # Setup and start the device manager 16 manager = MerossManager(http_client=http_api_client) 17 await manager.async_init() 18 19 # Discover devices. 20 await manager.async_device_discovery() 21 meross_devices = manager.find_devices() 22 23 # Print them 24 print("I've found the following devices:") 25 for dev in meross_devices: 26 print(f"- {dev.name} ({dev.type}): {dev.online_status}") 27 28 # Close the manager and logout from http_api 29 manager.close() 30 await http_api_client.async_logout() 31 32if __name__ == '__main__': 33 if os.name == 'nt': 34 asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) 35 loop = asyncio.get_event_loop() 36 loop.run_until_complete(main()) 37 loop.stop() ``` -------------------------------- ### GET async_get_daily_power_consumption Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/consumption.html Retrieves the daily power consumption data for a specific channel of a Meross device. ```APIDOC ## GET async_get_daily_power_consumption ### Description Returns the power consumption registered by the device for a specified channel. ### Parameters #### Query Parameters - **channel** (int) - Optional - The channel to read data from. Defaults to 0. - **timeout** (float) - Optional - Timeout for the request in seconds. ### Response #### Success Response (200) - **List[dict]** - A list of historical consumption data records. ``` -------------------------------- ### Get Cached Power Metrics Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/electricity.html Retrieves the most recently cached power consumption data for a specific channel. ```python get_last_sample(channel=0, *args, **kwargs) -> PowerInfo | None ``` -------------------------------- ### Run the Meross Sniffer Tool Source: https://albertogeniola.github.io/MerossIot/advanced-topics.html Execute the sniffing utility to begin capturing device communication data. ```bash meross_sniffer ``` -------------------------------- ### GenericSubDevice Class Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/device/generic.html Documentation for the GenericSubDevice class, including its constructor, methods, and properties. ```APIDOC ## Class: GenericSubDevice ### Description Represents a generic sub-device within the Meross IoT ecosystem, managed by a HubDevice. ### Constructor `__init__(_hubdevice_uuid: str, _subdevice_id: str, _manager, **kwargs)` ### Methods #### async `async_get_battery_life` ##### Description Polls the HUB/DEVICE to get its current battery status. ##### Parameters - `_timeout` (float | None) - Optional - Timeout for the operation. - `_*args` - Variable length argument list. - `_**kwargs` - Arbitrary keyword arguments. ##### Returns - `BatteryInfo` - Information about the battery status. #### async `async_update` ##### Description Performs a full device update of the device attributes. ##### Parameters - `_timeout` (float | None) - Optional - Timeout for the operation. - `_*args` - Variable length argument lists. - `_**kwargs` - Arbitrary keyword arguments. ##### Returns - `None` ### Properties #### `internal_id` ##### Description Internal ID used by this library to identify meross devices. It’s basically composed by the Meross ID plus some prefix/suffix. ##### Returns - `str` - The internal device ID. #### `online_status` ##### Description Current device online status. ##### Returns - `OnlineStatus` - The current online status of the device. ``` -------------------------------- ### GET Thermostat State Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/thermostat.html Retrieves the current state of a Meross thermostat device, including temperature settings and operational modes. ```APIDOC ## GET get_thermostat_state ### Description Returns the current state of the thermostat device. ### Parameters #### Path Parameters - **channel** (int) - Optional - The channel index of the thermostat (default: 0). ### Response #### Success Response (200) - **ThermostatState** (object) - An object containing the current temperature, mode, and operational status of the thermostat. ``` -------------------------------- ### ElectricityMixin - async_get_instant_metrics Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/electricity.html Polls the device to gather the instant power consumption for this device. It's recommended to use the cached value from get_last_sample() and only call this method to refresh it if necessary. ```APIDOC ## async_get_instant_metrics() ### Description Polls the device to gather the instant power consumption for this device. Please note that current/voltage combination may not be accurate as power is. So, refer to power attribute rather than calculate it as Voltage * Current. Avoid flooding the device by calling this methods so often. Instead. you should rely on the cached value offered by get_last_sample(): if it’s None or if the sample_timestamp of the offered value is not recent enough, then you should call this method to refresh it. ### Method ASYNC GET ### Endpoint N/A (Method within a class) ### Parameters #### Query Parameters - **channel** (int) - Optional - channel where to read metrics from. Defaults to 0 - **timeout** (float | None) - Optional - Timeout for the request. ### Response #### Success Response (200) - **PowerInfo** (object) - a PowerInfo object describing the current measure data #### Response Example ```json { "power": 15.5, "current": 0.1, "voltage": 220.0, "timestamp": 1678886400 } ``` ``` -------------------------------- ### Control Meross Smart Bulb Color Source: https://albertogeniola.github.io/MerossIot/quick-start.html This example demonstrates how to control the color of Meross MSL120 smart bulbs. It first checks if the bulb supports RGB and then sets a random RGB color. Ensure your Meross cloud credentials are set up. Only online devices are considered. ```python import asyncio import os from random import randint from meross_iot.http_api import MerossHttpClient from meross_iot.manager import MerossManager from meross_iot.model.enums import OnlineStatus EMAIL = os.environ.get('MEROSS_EMAIL') or "YOUR_MEROSS_CLOUD_EMAIL" PASSWORD = os.environ.get('MEROSS_PASSWORD') or "YOUR_MEROSS_CLOUD_PASSWORD" async def main(): # Setup the HTTP client API from user-password http_api_client = await MerossHttpClient.async_from_user_password(email=EMAIL, password=PASSWORD, api_base_url="https://iot.meross.com") # Setup and start the device manager manager = MerossManager(http_client=http_api_client) await manager.async_init() # Retrieve the MSL120 devices that are registered on this account await manager.async_device_discovery() plugs = manager.find_devices(device_type="msl120", online_status=OnlineStatus.ONLINE) if len(plugs) < 1: print("No online msl120 smart bulbs found...") else: # Let's play with RGB colors. Note that not all light devices will support # rgb capabilities. For this reason, we first need to check for rgb before issuing # color commands. dev = plugs[0] # Update device status: this is needed only the very first time we play with this device (or if the # connection goes down) await dev.async_update() if not dev.get_supports_rgb(): print("Unfortunately, this device does not support RGB...") else: # Check the current RGB color current_color = dev.get_rgb_color() print(f"Currently, device {dev.name} is set to color (RGB) = {current_color}") # Randomly chose a new color rgb = randint(0, 255), randint(0, 255), randint(0, 255) print(f"Chosen random color (R,G,B): {rgb}") await dev.async_set_light_color(rgb=rgb) print("Color changed!") # Close the manager and logout from http_api manager.close() await http_api_client.async_logout() if __name__ == '__main__': if os.name == 'nt': asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.stop() ``` -------------------------------- ### POST /config (MQTT Configuration) Source: https://albertogeniola.github.io/MerossIot/meross-protocol.html Configures the MQTT broker host and port, along with user credentials, on the Meross device. ```APIDOC ## POST /config ### Description Instructs the plug to use a specific MQTT broker host and port, providing the necessary user ID and secret key for authentication. ### Method POST ### Endpoint /config ### Request Body - **header** (object) - Required - Contains metadata including from, messageId, timestamp, sign, method (SET), namespace (Appliance.Config.Key), triggerSrc, and uuid. - **payload** (object) - Required - Contains the gateway host, port, key, and userId. ``` -------------------------------- ### LightMixin Capability Queries Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/light.html Methods to check if a specific light device supports certain features. ```APIDOC ## Light Capability Queries ### Methods - **get_supports_luminance(channel=0)**: Returns True if device supports luminance. - **get_supports_rgb(channel=0)**: Returns True if device supports RGB color. - **get_supports_temperature(channel=0)**: Returns True if device supports temperature mode. ### Parameters - **channel** (int) - Optional - Channel to get info from, defaults to 0. ``` -------------------------------- ### BaseDevice Methods and Properties Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/device/base.html Overview of the BaseDevice class interface for interacting with Meross hardware. ```APIDOC ## BaseDevice Class Interface ### Description Represents a generic Meross device. Provides access to device metadata, state, and communication utilities. ### Methods - **async_update()**: Forces a full data update from the device. - **decrypt(encrypted_message_bytes: bytes)**: Decrypts incoming message bytes. - **encrypt(message_data_bytes: bytes)**: Encrypts data into a base64 string. - **is_encryption_key_set()**: Checks if the encryption key is configured. - **lookup_channel(channel_id_or_name)**: Retrieves channel information by ID or name. - **register_push_notification_handler_coroutine(coro)**: Registers a callback for state change notifications. - **set_encryption_key(...)**: Configures the encryption key. - **support_encryption()**: Returns true if the device supports encryption. - **unregister_push_notification_handler_coroutine(coro)**: Removes a registered event handler. ### Properties - **channels**: List of channels exposed by the device. - **default_command_timeout**: The default timeout for command execution. - **firmware_version**: The device firmware version string. - **hardware_version**: The device hardware revision string. - **internal_id**: The library-specific internal identifier. - **name**: The user-defined name of the device. - **online_status**: The current connectivity status. - **type**: The device model type. - **uuid**: The unique Meross identifier. ``` -------------------------------- ### LightMixin Controller Source: https://albertogeniola.github.io/MerossIot/_sources/api-reference/controller/mixins/light.rst.txt Documentation for the LightMixin class members used to interact with Meross smart lights. ```APIDOC ## LightMixin ### Description The LightMixin class provides an interface for controlling smart light devices. It includes methods to manage light state, brightness, color temperature, and RGB color settings. ### Class Reference - **meross_iot.controller.mixins.light.LightMixin** ### Members - **get_light_state()**: Retrieves the current power state of the light. - **set_light_state(on: bool)**: Sets the power state of the light. - **get_brightness()**: Retrieves the current brightness level (0-100). - **set_brightness(brightness: int)**: Sets the brightness level (0-100). - **get_color_temperature()**: Retrieves the current color temperature. - **set_color_temperature(temperature: int)**: Sets the color temperature. - **get_rgb_color()**: Retrieves the current RGB color settings. - **set_rgb_color(r: int, g: int, b: int)**: Sets the RGB color values. ``` -------------------------------- ### SystemRuntimeMixin Source: https://albertogeniola.github.io/MerossIot/_sources/api-reference/controller/mixins/runtime.rst.txt The SystemRuntimeMixin class offers methods related to the runtime system of Meross devices. ```APIDOC ## SystemRuntimeMixin ### Description Provides runtime functionalities for Meross devices. ### Class `meross_iot.controller.mixins.runtime.SystemRuntimeMixin` ### Members This class exposes various members (methods and attributes) that can be used to interact with the device's runtime system. Refer to the source code for a complete list of members. ``` -------------------------------- ### MerossHttpClient Initialization Source: https://albertogeniola.github.io/MerossIot/api-reference/http.html Utility class for dealing with Meross HTTP API. This class simplifies the usage of the Meross HTTP API providing login, logout and device listing API. ```APIDOC ## MerossHttpClient Class ### Description Utility class for dealing with Meross HTTP API. This class simplifies the usage of the Meross HTTP API providing login, logout and device listing API. ### Parameters - **cloud_credentials** (MerossCloudCreds) - Credentials for the Meross cloud. - **http_proxy** (str | None) - Optional HTTP proxy to use. - **ua_header** (str) - User agent header string. - **app_type** (str) - Application type string. - **app_version** (str) - Application version string. - **log_identifier** (str) - Identifier for logging. ``` -------------------------------- ### POST /config (Wi-Fi Configuration) Source: https://albertogeniola.github.io/MerossIot/meross-protocol.html Configures the local Wi-Fi network credentials for the Meross device. ```APIDOC ## POST /config ### Description Sends the local Wi-Fi SSID and password to the device, allowing it to connect to the domestic network after reboot. ### Method POST ### Endpoint /config ### Request Body - **header** (object) - Required - Contains metadata including from, messageId, timestamp, sign, method (SET), and namespace (Appliance.Config.Wifi). - **payload** (object) - Required - Contains the wifi object with base64 encoded ssid and password. ``` -------------------------------- ### Configure MQTT Broker via HTTP POST Source: https://albertogeniola.github.io/MerossIot/_sources/meross-protocol.rst.txt Sends the MQTT broker host, port, user ID, and secret key to the device during the initial pairing phase. ```http method: POST host: path: /config headers: "Content-Type: application/json" body: { "header": { "from": "{{FROM_DEVICE}}", "messageId": "{{MESSAGE_ID}}", "timestamp": {{TIMESTAMP}}, "sign": "{{SIGNATURE}}", "method": "SET", "namespace": "Appliance.Config.Key", "triggerSrc": "Android", "uuid": "{{TARGET_DEVICE_UUID}}" }, "payload": { "key": { "gateway": { "host":"{{MQTT_HOST}}", "port":"{{MQTT_PORT}}" }, "key": "{{KEY}}", "userId": "{{USER_ID}}" } } } ``` -------------------------------- ### List Meross Devices Source: https://albertogeniola.github.io/MerossIot/_sources/quick-start.rst.txt Use MerossManager to discover and list Meross devices connected to your account. Avoid calling async_device_discovery too frequently to prevent API alerts. ```python from meross_iot.manager import MerossManager from meross_iot.model.enums import OnlineStatus import asyncio async def main(): # Setup the MerossManager manager = MerossManager(email="your_email@email.com", password="your_password") await manager.async_init() # Discover devices await manager.async_device_discovery() # Get all the devices devices = manager.find_devices() # Print device info for device in devices: print(f"Device: {device.name} ({device.uuid})") print(f" Online: {device.online_status}") if device.online_status == OnlineStatus.ONLINE: print(f" State: {device.get_last_state()}") # Close the manager await manager.async_dispose() if __name__ == '__main__': asyncio.run(main()) ``` -------------------------------- ### Create Client from Cloud Credentials Source: https://albertogeniola.github.io/MerossIot/api-reference/http.html Build a MerossIot API client using the provided cloud-credentials object. ```APIDOC ## async_from_cloud_creds ### Description Build a MerossIot API client using the provided cloud-credentials object. ### Method classmethod async ### Parameters - **creds** (MerossCloudCreds) - CloudCredentials object to build the client from. - **http_proxy** (str | None) - HTTP proxy to use. When none, no proxy will be used. Defaults to None. - **ua_header** (str) - User agent headers to send alongside the various requests. The default value is auto-generated by the library. - **app_type** (str) - String used to discriminate the app type. The default value is auto-generated by the library. - **app_version** (str) - String used to discriminate the app version. The default value is auto-generated by the library. - **log_identifier** (str) - String used to log the app client usage. The default value is auto-generated by the library. ### Returns - MerossHttpClient: An instance of MerossHttpClient. ``` -------------------------------- ### Dump device registry to file Source: https://albertogeniola.github.io/MerossIot/advanced-topics.html Exports the current device registry to a file to avoid redundant discovery calls. ```python # ... # Init the manager and issue a discovery manager = MerossManager(http_client=http_api_client) await manager.async_init() await manager.async_device_discovery() # Dump the registry information into a test.dump file manager.dump_device_registry("test.dump") ``` -------------------------------- ### Control Smart Bulbs Source: https://albertogeniola.github.io/MerossIot/_sources/quick-start.rst.txt Operate smart bulbs using the LightMixin interface for RGB, luminance, and color temperature settings. ```python from meross_iot.manager import MerossManager from meross_iot.controller.mixins.light import LightMixin import asyncio async def main(): # Setup the MerossManager manager = MerossManager(email="your_email@email.com", password="your_password") await manager.async_init() # Discover devices await manager.async_device_discovery() # Get the first bulb found # You can also use manager.find_devices(device_class=LightMixin) bulb = manager.find_devices(device_class=LightMixin)[0] # Turn on the bulb and set to white await bulb.async_turn_on(rgb=None, brightness=75, color_temp=4000) print(f"Set bulb {bulb.name} to white") await asyncio.sleep(5) # Turn on the bulb and set to a specific RGB color await bulb.async_turn_on(rgb=(255, 0, 0), brightness=50) print(f"Set bulb {bulb.name} to red") await asyncio.sleep(5) # Turn off the bulb await bulb.async_turn_off() print(f"Turned off bulb {bulb.name}") # Close the manager await manager.async_dispose() if __name__ == '__main__': asyncio.run(main()) ``` -------------------------------- ### Create Client from User Credentials Source: https://albertogeniola.github.io/MerossIot/api-reference/http.html Builds a MerossHttpClient using username/password combination. In any case, the login will generate a token, which might expire at any time. ```APIDOC ## async_from_user_password ### Description Builds a MerossHttpClient using username/password combination. In any case, the login will generate a token, which might expire at any time. ### Method classmethod async ### Parameters - **api_base_url** (str) - Https base endpoint to use for API calls. It should be one of “https://iotx-eu.meross.com”, “https://iotx-ap.meross.com” or “https://iotx-us.meross.com”, based on your public IP region. - **email** (str) - Meross account email. - **password** (str) - Meross account password. - **http_proxy** (str) - Optional http proxy to use when issuing the requests. - **ua_header** (str) - User agent header string. - **app_type** (str) - App Type header parameter to use. - **app_version** (str) - App Version header parameter to use. - **log_identifier** (str) - Log identifier to use. - **auto_retry_on_bad_domain** (bool) - When set, it enables auto-retry when BadDomain exception occurs. - **mfa_code** (string) - Multi-factor authentication code (optional). ### Returns - MerossHttpClient: An instance of MerossHttpClient. ``` -------------------------------- ### LightMixin State Queries Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/light.html Methods to retrieve the current state of the light bulb. ```APIDOC ## Light State Queries ### Methods - **get_color_temperature(channel=0)**: Returns current color temperature (0-100). - **get_light_is_on(channel=0)**: Returns True if light is ON, False otherwise. - **get_luminance(channel=0)**: Returns current brightness intensity (0-100). - **get_rgb_color(channel=0)**: Returns current RGB configuration as a tuple (red, green, blue). ### Parameters - **channel** (int) - Optional - Channel to control, defaults to 0. ``` -------------------------------- ### SystemAllMixin Source: https://albertogeniola.github.io/MerossIot/_sources/api-reference/controller/mixins/system.rst.txt The SystemAllMixin class provides comprehensive system-level control and information retrieval for Meross devices. ```APIDOC ## SystemAllMixin API ### Description Provides comprehensive system-level control and information retrieval for Meross devices. ### Class meross_iot.controller.mixins.system.SystemAllMixin ### Members This mixin exposes various methods and properties for interacting with the device's system. Refer to the source code for a complete list of members. ``` -------------------------------- ### Toggle Smart Switches Source: https://albertogeniola.github.io/MerossIot/_sources/quick-start.rst.txt Control smart switches using ToggleMixin or ToggleXMixin. Use async_turn_on() and async_turn_off() methods. ```python from meross_iot.manager import MerossManager from meross_iot.controller.mixins.toggle import ToggleMixin import asyncio async def main(): # Setup the MerossManager manager = MerossManager(email="your_email@email.com", password="your_password") await manager.async_init() # Discover devices await manager.async_device_discovery() # Get the first switch found # You can also use manager.find_devices(device_class=ToggleMixin) switch = manager.find_devices(device_class=ToggleMixin)[0] # Turn on the switch await switch.async_turn_on() print(f"Turned on {switch.name}") await asyncio.sleep(5) # Turn off the switch await switch.async_turn_off() print(f"Turned off {switch.name}") # Close the manager await manager.async_dispose() if __name__ == '__main__': asyncio.run(main()) ``` -------------------------------- ### Meross IoT Library Overview Source: https://albertogeniola.github.io/MerossIot/genindex.html The library is structured around a base device controller and various mixins that provide specific functionality based on the device type. ```APIDOC ## Meross IoT Library Structure ### Description The library uses a mixin-based architecture to extend device functionality. Core classes include `BaseDevice`, `GenericSubDevice`, and `HubDevice`. ### Key Mixins - **LightMixin**: Controls light properties (brightness, RGB, temperature, luminance). - **GarageOpenerMixin**: Manages garage door state. - **ThermostatModeMixin**: Manages thermostat states and temperatures. - **RollerShutterTimerMixin**: Controls roller shutter position and status. - **ToggleMixin / ToggleXMixin**: Provides basic on/off switching capabilities. - **SystemDndMixin**: Manages system Do Not Disturb modes. ``` -------------------------------- ### Base Device and Related Classes Source: https://albertogeniola.github.io/MerossIot/genindex.html Core classes for representing Meross devices and their properties. ```APIDOC ## Base Device and Related Classes ### BaseDevice ### Description Represents a base Meross device. ### Methods - **decrypt()**: Decrypts data. - **encrypt()**: Encrypts data. - **async_update()**: Updates the device state. ### Properties - **firmware_version**: The firmware version of the device. - **default_command_timeout**: The default timeout for commands. - **channels**: Information about the device channels. ### GenericSubDevice ### Description Represents a generic sub-device. ### Methods - **async_get_battery_life()**: Gets the battery life of the sub-device. - **async_update()**: Updates the sub-device state. ### ChannelInfo ### Description Represents information about a device channel. ### ThermostatState ### Description Represents the state of a thermostat. ### Properties - **cool_temperature_celsius**: The cooling temperature in Celsius. - **current_temperature_celsius**: The current temperature in Celsius. - **eco_temperature_celsius**: The eco temperature in Celsius. ### ConsumptionXMixin ### Description Represents power consumption data. ### ElectricityMixin ### Description Represents electricity metrics. ``` -------------------------------- ### SystemRuntimeMixin API Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/runtime.html Methods for interacting with the SystemRuntimeMixin to fetch and access device runtime data. ```APIDOC ## async_update_runtime_info ### Description Polls the device to gather the latest runtime information. Note that the returned value might vary over time as Meross updates their protocol. ### Parameters #### Arguments - **timeout** (float | None) - Optional - Timeout for the request in seconds. ### Response - **dict** - A dictionary object containing the runtime information provided by the Meross device. --- ## cached_system_runtime_info ### Description Returns the latest cached runtime information for the device. ### Response - **dict | None** - The cached runtime information or None if no data has been cached yet. ``` -------------------------------- ### GarageOpenerMixin Methods Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/cover.html API methods for controlling and querying garage door status via the GarageOpenerMixin. ```APIDOC ## async_open ### Description Operates the door by sending the open command. ### Parameters #### Path Parameters - **channel** (int | None) - Optional - The channel to operate, defaults to 0. ### Response - **None** (None) - Returns None upon successful command execution. --- ## async_close ### Description Operates the door by sending the close command. ### Parameters #### Path Parameters - **channel** (int | None) - Optional - The channel to operate, defaults to 0. ### Response - **None** (None) - Returns None upon successful command execution. --- ## get_is_open ### Description Retrieves the current door-open status. ### Parameters #### Path Parameters - **channel** (int | None) - Optional - The channel of which status is needed. ### Response - **bool | None** (bool) - Returns True if the door is open, False if closed. ``` -------------------------------- ### Dump and load device registry Source: https://albertogeniola.github.io/MerossIot/_sources/advanced-topics.rst.txt Persist discovered device information to a file to avoid redundant discovery calls, and reload it later. ```python # ... # Init the manager and issue a discovery manager = MerossManager(http_client=http_api_client) await manager.async_init() await manager.async_device_discovery() # Dump the registry information into a test.dump file manager.dump_device_registry("test.dump") ``` ```python # ... # Init the manager and load the dump, so that we don't need to issue a discovery manager = MerossManager(http_client=http_api_client) await manager.async_init() manager.load_devices_from_dump("test.dump") print("Registry dump loaded.") ``` -------------------------------- ### GarageOpenerMixin Controller Source: https://albertogeniola.github.io/MerossIot/_sources/api-reference/controller/mixins/cover.rst.txt Documentation for the GarageOpenerMixin class members used to control garage door openers. ```APIDOC ## GarageOpenerMixin ### Description The GarageOpenerMixin class provides functionality to interact with and control Meross garage door opener devices. ### Class Members - **open_door()**: Triggers the command to open the garage door. - **close_door()**: Triggers the command to close the garage door. - **get_door_status()**: Retrieves the current state of the garage door (e.g., open, closed, opening, closing). ``` -------------------------------- ### List Devices Source: https://albertogeniola.github.io/MerossIot/api-reference/http.html Asks to the HTTP api to list the Meross device belonging to the given user account. ```APIDOC ## async_list_devices ### Description Asks to the HTTP api to list the Meross device belonging to the given user account. ### Method async ### Returns - List[HttpDeviceInfo]: A list of HttpDeviceInfo. ``` -------------------------------- ### ToggleMixin and ToggleXMixin API Source: https://albertogeniola.github.io/MerossIot/_sources/api-reference/controller/mixins/toggle.rst.txt Documentation for the toggle control mixins used in the meross_iot controller. ```APIDOC ## ToggleMixin ### Description Provides basic toggle functionality for Meross IoT devices. ## ToggleXMixin ### Description Provides extended toggle functionality for Meross IoT devices. ``` -------------------------------- ### Read electricity consumption from MSS310 Source: https://albertogeniola.github.io/MerossIot/quick-start.html Uses ElectricityMixin to retrieve real-time power, voltage, and current metrics from a smart plug. ```python 1import asyncio 2import os 3 4from meross_iot.controller.mixins.electricity import ElectricityMixin 5from meross_iot.http_api import MerossHttpClient 6from meross_iot.manager import MerossManager 7 8EMAIL = os.environ.get('MEROSS_EMAIL') or "YOUR_MEROSS_CLOUD_EMAIL" 9PASSWORD = os.environ.get('MEROSS_PASSWORD') or "YOUR_MEROSS_CLOUD_PASSWORD" 10 11 12async def main(): 13 # Setup the HTTP client API from user-password 14 http_api_client = await MerossHttpClient.async_from_user_password(email=EMAIL, password=PASSWORD, api_base_url="https://iot.meross.com") 15 16 # Setup and start the device manager 17 manager = MerossManager(http_client=http_api_client) 18 await manager.async_init() 19 20 # Retrieve all the devices that implement the electricity mixin 21 await manager.async_device_discovery() 22 devs = manager.find_devices(device_class=ElectricityMixin) 23 24 if len(devs) < 1: 25 print("No electricity-capable device found...") 26 else: 27 dev = devs[0] 28 29 # Update device status: this is needed only the very first time we play with this device (or if the 30 # connection goes down) 31 await dev.async_update() 32 33 # Read the electricity power/voltage/current 34 instant_consumption = await dev.async_get_instant_metrics() 35 print(f"Current consumption data: {instant_consumption}") 36 37 # Close the manager and logout from http_api 38 manager.close() 39 await http_api_client.async_logout() 40 41if __name__ == '__main__': 42 if os.name == 'nt': 43 asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) 44 loop = asyncio.get_event_loop() 45 loop.run_until_complete(main()) 46 loop.stop() ``` -------------------------------- ### SystemRuntimeMixin Class Definition Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/runtime.html The base class for handling runtime information for Meross devices. ```python class meross_iot.controller.mixins.runtime.SystemRuntimeMixin(device_uuid : str, manager , ** kwargs) ``` -------------------------------- ### SystemDndMixin API Source: https://albertogeniola.github.io/MerossIot/_sources/api-reference/controller/mixins/dnd.rst.txt Documentation for the SystemDndMixin class members. ```APIDOC ## SystemDndMixin ### Description The SystemDndMixin class provides methods to interact with the Do Not Disturb (DND) functionality of Meross IoT devices. ### Class Reference - **meross_iot.controller.mixins.dnd.SystemDndMixin** ### Members - This class includes all members defined in the `meross_iot.controller.mixins.dnd.SystemDndMixin` implementation. ``` -------------------------------- ### Retrieve Instant Power Metrics Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/electricity.html Polls the device for current power consumption. Avoid frequent calls to prevent device flooding; prefer cached data when possible. ```python async_get_instant_metrics(channel=0, timeout=None, *args, **kwargs) -> PowerInfo ``` -------------------------------- ### Meross IoT Library Components Source: https://albertogeniola.github.io/MerossIot/api-reference/index.html Overview of the core classes and functional mixins available for interacting with Meross devices. ```APIDOC ## Meross IoT Library Reference ### Core Classes - **MerossHttpClient**: Handles HTTP communication with the Meross cloud. - **MerossManager**: Manages device discovery and state. - **MerossCloudCreds**: Stores and manages cloud authentication credentials. - **BaseDevice**: The base class for all Meross devices. ### Functional Mixins - **ToggleMixin / ToggleXMixin**: Controls basic on/off functionality. - **ElectricityMixin / ConsumptionXMixin**: Provides power usage and electricity monitoring data. - **LightMixin / DiffuserLightMixin**: Manages lighting and LED settings. - **GarageOpenerMixin**: Controls garage door opener states. - **ThermostatModeMixin / ThermostatState**: Manages climate control settings. - **SystemRuntimeMixin / SystemOnlineMixin**: Provides system status and runtime information. - **HubMixn / HubDevice**: Manages hub-based sub-devices. ``` -------------------------------- ### Operate Meross MTS100v3 Thermostat Valve Source: https://albertogeniola.github.io/MerossIot/quick-start.html Demonstrates how to authenticate, discover devices, read temperature data, and set target temperatures for an MTS100v3 valve. ```python 1import asyncio 2import os 3from random import randint 4 5from meross_iot.http_api import MerossHttpClient 6from meross_iot.manager import MerossManager 7 8EMAIL = os.environ.get('MEROSS_EMAIL') or "YOUR_MEROSS_CLOUD_EMAIL" 9PASSWORD = os.environ.get('MEROSS_PASSWORD') or "YOUR_MEROSS_CLOUD_PASSWORD" 10 11 12async def main(): 13 # Setup the HTTP client API from user-password 14 http_api_client = await MerossHttpClient.async_from_user_password(email=EMAIL, password=PASSWORD, api_base_url="https://iot.meross.com") 15 16 # Setup and start the device manager 17 manager = MerossManager(http_client=http_api_client) 18 await manager.async_init() 19 20 # Retrieve all the mts100v3 devices that are registered on this account 21 await manager.async_device_discovery() 22 sensors = manager.find_devices(device_type="mts100v3") 23 24 if len(sensors) < 1: 25 print("No mts100v3 plugs found...") 26 else: 27 dev = sensors[0] 28 29 # Manually force and update to retrieve the latest temperature sensed from 30 # the device (this ensures we get the most recent value rather than a cached one) 31 await dev.async_update() 32 33 # Access read cached data 34 on_off = dev.is_on() 35 36 # Turn on the device if it's not on 37 if not on_off: 38 print(f"Device {dev.name} is off, turning it on...") 39 await dev.async_turn_on() 40 41 temp = await dev.async_get_temperature() 42 print(f"Current ambient temperature = {temp} °C, " 43 f"Target Temperature = {dev.target_temperature}, " 44 f"mode = {dev.mode}," 45 f"heating = {dev.is_heating}") 46 47 # Randomly choose a temperature between min and max 48 new_temp = randint(dev.min_supported_temperature, dev.max_supported_temperature) 49 print(f"Setting target temperature to {new_temp}") 50 await dev.async_set_target_temperature(new_temp) 51 52 # Close the manager and logout from http_api 53 manager.close() 54 await http_api_client.async_logout() 55 56if __name__ == '__main__': 57 if os.name == 'nt': 58 asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) 59 loop = asyncio.get_event_loop() 60 loop.run_until_complete(main()) 61 loop.stop() ``` -------------------------------- ### ToggleXMixin API Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/toggle.html Provides methods for controlling devices that support ToggleX operations, such as smart switches and bulbs. ```APIDOC ## ToggleXMixin ### Description This mixin is implemented by devices that support ToggleX operation, such as smart switches and smart bulbs. ### Class Signature `_class _meross_iot.controller.mixins.toggle.ToggleXMixin(_device_uuid : str_, _manager_ , _** kwargs_)` ### Methods #### async_toggle * **Description**: Toggles the switch status of the specified channel. * **Method**: `async` * **Parameters**: * `channel` (int) - Optional - channel index to toggle. Defaults to 0. * **Returns**: None #### async_turn_off * **Description**: Turns off the specified channel of the device. * **Method**: `async` * **Parameters**: * `channel` (int) - Optional - channel index to turn off. Defaults to 0. * `timeout` (float | None) - Optional - Timeout for the operation. * **Returns**: None #### async_turn_on * **Description**: Turns on the specified channel of the device. * **Method**: `async` * **Parameters**: * `channel` (int) - Optional - channel index to turn on. Defaults to 0. * `timeout` (float | None) - Optional - Timeout for the operation. * **Returns**: None #### is_on * **Description**: Returns the ON/OFF state of the switch channel. * **Method**: Synchronous * **Parameters**: * `channel` (int) - Optional - channel index of interest. Defaults to 0. * **Returns**: bool | None - True if the state is ON, False when it’s OFF. ``` -------------------------------- ### SystemOnlineMixin Source: https://albertogeniola.github.io/MerossIot/_sources/api-reference/controller/mixins/system.rst.txt The SystemOnlineMixin class offers functionalities related to the online status and management of Meross devices. ```APIDOC ## SystemOnlineMixin API ### Description Provides functionalities related to the online status and management of Meross devices. ### Class meross_iot.controller.mixins.system.SystemOnlineMixin ### Members This mixin includes methods for checking and managing the device's online presence. Refer to the source code for a complete list of members. ``` -------------------------------- ### MerossHttpClient Methods Source: https://albertogeniola.github.io/MerossIot/api-reference/http.html This section covers the various methods available in the MerossHttpClient class for managing cloud credentials, devices, and authentication. ```APIDOC ## MerossHttpClient Methods ### Description Provides methods for interacting with the Meross cloud service, including authentication, device management, and credential handling. ### Methods #### `async_from_cloud_creds(cloud_key: str, cloud_iv: str, uuid: str)` - **Description**: Creates an `MerossHttpClient` instance using provided cloud credentials. - **Parameters**: - `cloud_key` (str) - Required - The cloud key for authentication. - `cloud_iv` (str) - Required - The cloud initialization vector. - `uuid` (str) - Required - The unique identifier for the client. #### `async_from_user_password(email: str, password: str)` - **Description**: Creates an `MerossHttpClient` instance using user email and password. - **Parameters**: - `email` (str) - Required - The user's email address. - `password` (str) - Required - The user's password. #### `async_invalidate_credentials()` - **Description**: Invalidates the current cloud credentials. #### `async_list_devices()` - **Description**: Retrieves a list of all associated Meross devices. - **Returns**: A list of device objects. #### `async_list_hub_subdevices(hub_uuid: str)` - **Description**: Retrieves a list of sub-devices connected to a specific Meross hub. - **Parameters**: - `hub_uuid` (str) - Required - The UUID of the Meross hub. - **Returns**: A list of sub-device objects. #### `async_login()` - **Description**: Logs in to the Meross cloud service. #### `async_logout()` - **Description**: Logs out from the Meross cloud service. ### Properties #### `cloud_credentials` - **Description**: Accesses the current cloud credentials. - **Type**: `MerossCloudCredentials` ``` -------------------------------- ### ToggleMixin API Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/toggle.html A mixin class for devices that support basic toggle operations. ```APIDOC ## ToggleMixin ### Description This mixin is implemented by devices that support basic toggle operations. ### Class Signature `_class _meross_iot.controller.mixins.toggle.ToggleMixin(_device_uuid : str_, _manager_ , _** kwargs_)` ``` -------------------------------- ### Credentials and Model Classes Source: https://albertogeniola.github.io/MerossIot/genindex.html Classes for managing Meross cloud credentials and data models. ```APIDOC ## Credentials and Model Classes ### MerossCloudCreds ### Description Represents Meross cloud credentials. ### Class Methods - **from_json()**: Creates credentials from a JSON object. ### Properties - **cloud_credentials**: Accesses the cloud credentials. ``` -------------------------------- ### ThermostatModeMixin and ThermostatState Source: https://albertogeniola.github.io/MerossIot/_sources/api-reference/controller/mixins/thermostat.rst.txt API documentation for the ThermostatModeMixin and ThermostatState classes used to control and monitor Meross thermostat devices. ```APIDOC ## ThermostatModeMixin ### Description Provides methods to manage and interact with the operational modes of a Meross thermostat device. ## ThermostatState ### Description Represents the current state of the thermostat, including temperature settings and operational status. ``` -------------------------------- ### Configure Diffuser Light Mode Source: https://albertogeniola.github.io/MerossIot/api-reference/controller/mixins/diffuserlight.html Sets the light mode, brightness, and color for a specific channel on a diffuser device. ```python async def async_set_light_mode(self, channel: int = 0, onoff: bool | None = None, mode: DiffuserLightMode | None = None, brightness: int | None = None, rgb: Tuple[int, int, int] | None = None, timeout: float | None = None, *args, **kwargs) -> None ```