thomasloven / pyplejd

MIT License
3 stars 5 forks source link

Can this be used without Home Assistant #3

Open lark-cig opened 11 months ago

lark-cig commented 11 months ago

Are there any example of how to use this library without Home Assistant?

LogFlames commented 10 months ago

@lark-cig I'm not part of this project, but wanted to do the same thing. After spending some time reading a lot of this code, and the code in https://github.com/thomasloven/hass_plejd I've managed to get a minimal working example

import pyplejd
import asyncio
import bleak

async def test():
    cred = {"username": "[mail]", "password": "[passwd]"}
    sit = await pyplejd.get_sites(**cred)
    man = pyplejd.PlejdManager({**cred, "siteId": sit[0].siteId})
    await man.init()
    dev = man.devices
    sce = man.scenes

    dvs = await bleak.BleakScanner().discover(timeout = 2.0, return_adv = True)
    for d,a in dvs.values():
        man.mesh.see_device(d, a.rssi)

    await man.mesh.connect()

    for d in dev:
        print(d)
        if d.address == 16:
            await d.turn_off()

    for s in sce:
        print(s)

asyncio.run(test())

I think it should be able to discover the BLE devices once, and then keep the connections alive using pings. I haven't read that part of the code, but it is there.

Then it should be quick to send instructions to the devices.

lark-cig commented 9 months ago

@LogFlames Thanks a lot. I guess that mail and passwd is something you extract from the iPhone backup?

Another question is if there are any known API to the Plejd Gateway? I haven't found anything.

LogFlames commented 9 months ago

@lark-cig the email and password is for the Plejd account. (The same you use to login to the app) I wasn't able to get the backup working, but this worked without it.

I don't have the gateway so sadly cannot answer that, I setup home assistant instead and control the lights remotely that way.