Skip to content

Instantly share code, notes, and snippets.

@InternetUnexplorer
Created April 12, 2025 07:53
Show Gist options
  • Save InternetUnexplorer/e4a5669e14ed9c19307a86a103386481 to your computer and use it in GitHub Desktop.
Save InternetUnexplorer/e4a5669e14ed9c19307a86a103386481 to your computer and use it in GitHub Desktop.
Script to monitor a Govee H5086 smart plug's energy stats over BLE
from bleak import BleakClient
import asyncio
MAC = "XX:XX:XX:XX:XX:XX"
NOTIFY_UUID = "00010203-0405-0607-0809-0a0b0c0d2b10"
WRITE_CHAR_UUID = "00010203-0405-0607-0809-0a0b0c0d2b11"
KEEPALIVE = bytearray.fromhex("aa010000000000000000000000000000000000ab")
def callback(_, data):
if data[0] != 0xEE:
return
volts = int.from_bytes(data[8:10]) / 100
amps = int.from_bytes(data[10:12]) / 100
watts = int.from_bytes(data[12:15]) / 100
print(f"{watts:7.2f}W {amps:5.2f}A {volts:6.2f}V")
async def main():
async with BleakClient(MAC) as client:
await client.start_notify(NOTIFY_UUID, callback)
while True:
await client.write_gatt_char(WRITE_CHAR_UUID, KEEPALIVE, response=False)
await asyncio.sleep(2)
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment