Automatic charging

Vectrix EV Interest Group
Post Reply
memecode
Groupie
Posts: 93
Joined: Tue, 03 Feb 2015, 19:42
Real Name: Matthew Allen
Location: Sydney
Contact:

Automatic charging

Post by memecode »

So I have solar at my place. And I have a script that can read the current output of the solar panels and do something. Like switch on a power point. Lets assume that I can find a device that I can script easily.

What I'd like is the Vectrix to automatically charge as soon as it gets power. Now it does this when charging was interrupted. But not if the previous charge was completed.

Is there are way to trigger charging automatically all the time? Assuming the battery is not at 100%?

Say I get home... bike is at 30% or so... I plug it in to the switched mains outlet (currently off). It sits there doing nothing. But the next morning the python script is watching the solar until it reaches 1500w or more and then switches on the power point, starting the bike charging...

Bonus points if I can figure out it's finished charging and text me or something.

Maybe I should be less of a geek...
memecode
Groupie
Posts: 93
Joined: Tue, 03 Feb 2015, 19:42
Real Name: Matthew Allen
Location: Sydney
Contact:

Re: Automatic charging

Post by memecode »

User avatar
brendon_m
Senior Member
Posts: 757
Joined: Sat, 28 Oct 2017, 11:00
Real Name: Brendon McCarrol

Re: Automatic charging

Post by brendon_m »

The sonoff ones are hacked quite a bit to work with stuff like what you are talking about.
memecode
Groupie
Posts: 93
Joined: Tue, 03 Feb 2015, 19:42
Real Name: Matthew Allen
Location: Sydney
Contact:

Re: Automatic charging

Post by memecode »

So I got a TP-link HS110 today at JbHiFi, they are on sale. And it seems to connect and work quite nicely. And as it turns out there is a python module for talking to the kasa cloud and therefor the device:
https://github.com/python-kasa/python-kasa

Seems I'm not far off having it work. I do have to manually trigger the charge to start and then turn off the HS110. But once that's done the night before all I do it let the script run on my home Ubuntu server and wait for the sunshine.
memecode
Groupie
Posts: 93
Joined: Tue, 03 Feb 2015, 19:42
Real Name: Matthew Allen
Location: Sydney
Contact:

Re: Automatic charging

Post by memecode »

So I finished the script enough to talk to the IOT power plug AND solarweb and keep looping until it gets enough power...

Code: Select all

E:\Code\Py>python solarweb.py
Discovering plugs...
name: vectrix
 emeter_realtime: {'voltage_mv': 236934, 'current_ma': 20, 'power_mw': 0, 'total_wh': 53, 'err_code': 0}
 state_information: {'LED state': True, 'On since': None}
 is_on: False
1006.0 W
Not enough solar yet.
1006.0 W
Not enough solar yet.
902.0 W
Not enough solar yet.
1143.0 W
Not enough solar yet.
1348.0 W
Not enough solar yet.
1462.0 W
Not enough solar yet.
1410.0 W
Not enough solar yet.
1496.0 W
Not enough solar yet.
2724.0 W
Turning on plug...
Done.
It totally worked... I checked it actually did switch on and start charging. I'm a bit shook at how easy this was.
Kudra
Noobie
Posts: 3
Joined: Thu, 19 Nov 2020, 05:13

Re: Automatic charging

Post by Kudra »

memecode wrote: Tue, 01 Dec 2020, 10:27 Apparently I need one of these:
https://www.jbhifi.com.au/products/tp-l ... monitoring
Ooh! Going to grab a couple.
I have some noname Chinese ones from eBay but housemate didn't like the security on them. These look a bit more reliable. Ta!
User avatar
brendon_m
Senior Member
Posts: 757
Joined: Sat, 28 Oct 2017, 11:00
Real Name: Brendon McCarrol

Re: Automatic charging

Post by brendon_m »

Kudra wrote: Wed, 02 Dec 2020, 17:38 I have some noname Chinese ones from eBay but housemate didn't like the security on them. These look a bit more reliable. Ta!
Yeah, that sounds like the sonoff ones :?
I haven't used the tp link ones but I can say the dlink are rubbish (they overheat easily at high current and the app is painful to use)
I'm currently running the kogan ones around my house (including my car) and they seem to work pretty well. I don't know what sort of 3rd party integration they have though, I just use them as glorified timer switches
memecode
Groupie
Posts: 93
Joined: Tue, 03 Feb 2015, 19:42
Real Name: Matthew Allen
Location: Sydney
Contact:

Re: Automatic charging

Post by memecode »

I did some more work on the script this morning:
- Added timeouts for collecting info on the plugs, one of our wifi access points has issues with MDNS packets and if it's not discoverable it should timeout rather than hang indefinitely.
- I wrapped the login to solarweb in a function so that if it fails it can be re-run after a timeout. This patches the script exiting on a log in failure. solarweb is not the most reliable site.
- General refactoring to be more robust.
- Added current time to each reading, apparently 8:30a was the magical moment where solar output > bike's charge requirements.

Because I can also get the power draw from the plug I can tell when the bike has finished charging or at least dropped back to "topping off mode" of 430w. So I should be able to send a notification to my phone saying the bike is ready to go. That's the grand plan...

And by unplugging while it's in the "top off the batteries" phase I leave it in the "will charge when it gets power state" that I need for the script to work.
memecode
Groupie
Posts: 93
Joined: Tue, 03 Feb 2015, 19:42
Real Name: Matthew Allen
Location: Sydney
Contact:

Re: Automatic charging

Post by memecode »

Turns out if you press the start charge button while not plugged in it will automatically start charging when you do plug it in. Which is perfect... I can prepare for auto-charging by turning the tp-link switch off, and then hit the start charge button on the bike and let the software take over the rest.
Post Reply