ponewheel / android-ponewheel

pOneWheel Android app
MIT License
71 stars 25 forks source link

[Feature Request] Turn off charging when batt hits 95% #4

Open ebabel opened 6 years ago

ebabel commented 6 years ago

via Kasa (TP-Link) or ?

ebabel commented 6 years ago

Jay Fornow on on Facebook says: It's a simple formula.

The amount of minutes to set in timer = (Y - Z) x 22.5 seconds /60 seconds

Y=Desired Percentage Z=Current Battery Percentage.

For example: If I want to stop charging the battery at 96% and current charge is 40%.

(96-40)x 22.5/60= 21 minutes

ebabel commented 6 years ago

Looks like we can connect to Kasa via IFTTT.com, too bad Kasa can't just take an intent

kwatkins commented 6 years ago

Oh wow, interesting... yeah we can add intents/broadcasts/a service?/tasker integration etc for the stats, not sure what we can do past that. For what it's worth, I have a raspberry pi running home assistant for controlling/automating my house and created a sensor, a script, that uses ble tools to pull the % directly. Then I can create actions based on that, like turning off the charging. image

onewheel_stats.py

#!/usr/bin/env python3
import argparse,subprocess

text = 'This program returns stats from an Onewheel BLE device'
parser = argparse.ArgumentParser(description = text)
parser.add_argument("address",help="mac address of device")
parser.add_argument("--battery", help="get battery level",action="store_true")
args = parser.parse_args()

if __name__ == "__main__":
    if args.battery:
        p = subprocess.Popen("/usr/bin/gatttool -b {0} --char-read --handle=0x0021".format(args.address), stdout=subprocess.PIPE, shell=True)
        (output, err) = p.communicate()
        p_status = p.wait()

        p_out = output.decode('ascii').split()
        if len(p_out) > 0:
            r = '{0}{1}'.format(p_out[2],p_out[3])
            print(int(r,16))
        else:
            print(-1)
kwatkins commented 6 years ago

Hmm also the protocol used for the smart plug been reversed engineered https://github.com/softScheck/tplink-smartplug/blob/master/tddp-client/tddp-client.py - so there is the possibility of adding a shared preference option of "if battery level gets to 100% tell smart plug at 192.168.86.20 to turn off". That being said, connecting into IFTTT would open it up to their services and broader triggers etc. Might be a bit of work to getting the OW app added as a "service", a workflow that would work would be creating a custom notification of battery % and use the IFTTT "android device" service & "Notification received from a specific app" -> "Filter by notification keyword".