jesserockz / python-juicenet

MIT License
12 stars 10 forks source link

Allow setting max current #10

Open mbbush opened 3 years ago

mbbush commented 3 years ago

The api supports a command to set the maximum charging current.

At the moment, I manually adjust the max current using the juicebox app, based on data from my home power meter, to allow the car to use as much excess solar power as I would otherwise be feeding back into the grid. I'd like to automate that.

I can take a stab at implementing this myself (and then subsequently getting the functionality into homeassistant), if you'd be willing to accept the PR.

mbbush commented 3 years ago

At least in my experimentation with the api, when I issue the "set_limit" command with an "amperage" parameter, and then poll the "get_state" command to see the result, it updates the "charging.amps_limit" as I would expect, but then a few seconds later reverts to what it was before, without ever affecting the rate of charge.

What did work, though, was sending a "set_info" command, with a "amps_wire_rating" of the value I want. This also included "timeZoneId" as a required parameter (yes, with a different casing convention), so I just re-POSTed the value I got from a "get_info" command.

So I think the way I'll implement this (unless someone advises otherwise), is to add two more api endpoints, "get_info" and "set_info". I'll call "get_info" when initializing the Charger, and store the result on the Charger object, so that I can pass the same timeZoneId in when setting the max current. Then I'll add a public method for setting the max current that accepts an integer amperage, and issues the "set_info" call using that value.