albertogeniola / MerossIot

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

How to retrieve the "wifi signal strength" percentage ? #270

Closed MichelRabozee closed 1 year ago

MichelRabozee commented 1 year ago

Hello,

I encounter the need to retrieve the wi-fi signal strength (signal_strength), but I do not find how it is possible with MerossIot library. I am sure the value is available (it is displayed in the official Meross app).

Can you help ?

albertogeniola commented 1 year ago

Hi! I've just released a new version (0.4.5.2) that should add the necessary support for what you asked. It turns out Meross has "moved" that info to a dedicated namespace, called "System.Runtime". You can find the API documentation here.

Basically, you need to invoke the newly added async_update_runtime_info(). That will return a dictionary containing various (depends on the specific device) extra attributes. Among them there should be the "signal" attribute, which reports - in percentage - the wifi signal strength of the Meross device. Please note: I am not 100% this attribute is always available within the runtime_info provided, so be sure to check if the "signal" key is present within the dictionary before accessing it. Also, there might be devices that do not support that namespace. Most of the classic devices should be fine, but sub-devices depending on a HUB might not expose that functionality at all.

Can you please test it and let me know if that works as intended?

MichelRabozee commented 1 year ago

Hello !

Excellent, that seems to do the trick !

Code like this:

        meross_devices = manager.find_devices()

        # Print them
        print("I've found the following devices:")
        for dev in meross_devices:
            try:
                print(f"- {dev.name} ({dev.type}): {dev.online_status}")
                runtimeInfo = await dev.async_update_runtime_info()
                print(runtimeInfo)
            except Exception:
                print(f"- {dev.name} ({dev.type}): Plug is offline")

Gives:

I've found the following devices:
- Mares (mss620r): OnlineStatus.ONLINE
{'signal': 100}
- Test Consommation (mss310): OnlineStatus.ONLINE
{'signal': 81}
- Data Rack (mss310): OnlineStatus.ONLINE
{'signal': 86}
- Chaudière (mss310): OnlineStatus.ONLINE
{'signal': 89}
- Pompe des mares (mss310): OnlineStatus.ONLINE
{'signal': 65}
- Pompe de la citerne (mss310): OnlineStatus.ONLINE
{'signal': 37}
- Surgélateur (mss310): OnlineStatus.ONLINE
{'signal': 50}

Thank you very much,

Have an Happy 2023 !

albertogeniola commented 1 year ago

Glad it helped :)