albertogeniola / MerossIot

Async Python library for controlling Meross devices
https://albertogeniola.github.io/MerossIot/
MIT License
478 stars 88 forks source link

mss310 current on/off status #259

Closed ghost closed 1 year ago

ghost commented 1 year ago

I have written a monitoring task to switch on/off mss310 devices based on a number of conditions.

On startup of the task I would like to get the initial state (on/off) of the switches but can only query the online-status and not the switch status?

Ketchu13 commented 1 year ago

https://github.com/albertogeniola/MerossIot/blob/d24f197309d3537e9c810a5f5ade4033a545bae5/utilities/meross_sniffer.py#L213-L236

Hello, For example, you can use the response_all dictionary to retrieve the on/off values for each channel.

    ...
    "digest": {
        "togglex": [
            {
                "channel": 0,
                "onoff": 1,
                "lmTime": 1662868286
            },
            {
                "channel": 1,
                "onoff": 0,
                "lmTime": 1669506095
            },
            {
                "channel": 2,
                "onoff": 0,
                "lmTime": 1668543897
            },
            ...
        ],
        "triggerx": [],
        "timerx": []
    }
    ...
albertogeniola commented 1 year ago

Hi! To gather information about the switch status on a MSS310, you can simply use the is_on() method. That's documented here.

Just be advised: before querying for internal device state, you should always invoke the async_update() to fetch initial info.

In other words, something like this should do the trick:


async def main():
    # Initate the manager, login, etc...
    # manager = ....

    # Gather the device you'd like to fetch info from
    # await manager.async_device_discovery()
    # dev = manager.find_devices(uuid="YOURUUUIDHERE")

    # Fetch the device data
    await dev.async_update()
    # Check if that's on or off
    is_on = dev.is_on(channel=0) # MSS310 only has 1 channel
ghost commented 1 year ago

@ketchu13: thanks, that worked for me