Created
January 8, 2023 11:25
-
-
Save tetsuyainfra/31f8663a1a59fd56ef2e53c6a981c52e to your computer and use it in GitHub Desktop.
switchbot Plug mini AdvertisementData
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from pprint import pprint as pp | |
from bleak import BleakScanner | |
from bleak.backends.scanner import AdvertisementData | |
async def main(): | |
print("scanning for 5 seconds, please wait...") | |
devices = await BleakScanner.discover(return_adv=True) | |
for addr, (dev, adv) in devices.items(): | |
print("-" * len(str(addr))) | |
print(f"address: {addr}") | |
print_adv(adv) | |
print() | |
# devs.sort() | |
# for d in devs: | |
# print(d) | |
def print_adv(adv: AdvertisementData): | |
print(adv) | |
for id, data in adv.manufacturer_data.items(): | |
if id != 0x0969 : # == int(2409) | |
continue | |
print("It's might be PLUG MINI!") | |
print("len: ", len(data)) | |
addr = data[0:6].hex(':') | |
seq = data[6] | |
is_plug_on = bool(data[7] & 0x80) | |
delay = data[8] | |
wifi_rssi = data[9] | |
power_msb = data[10] | |
power_lsb = data[11] | |
if power_msb & 0b1000_0000 : | |
power = float('inf') | |
else: | |
print(power_msb) | |
print(power_lsb) | |
power = ((power_msb & 0b1000_0000) * 256 + power_lsb ) / 10.0 | |
print(f"addr: {addr}, seq={seq}, is_plug_on={is_plug_on}") | |
print(f"delay: {delay}, wifi_rssi={wifi_rssi}, power={power}Watt") | |
if __name__ == "__main__": | |
asyncio.run(main()) | |
# Plug Mini BLE open API | |
# https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/plugmini.md |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment