Closed frsteinb closed 3 years ago
I would also find this useful.
This endpoint should become available with 2021.36 software, and that's pretty much everything I know about this.
Hi, I have 2021.36 on my model 3 since last Friday. I also can change the charge amps in the Telsa app. How can I assist?
Thank you very much for your assistance!
If you are able to setup TeslaPy, including the authentication steps and execute a command like the one from the README.md file for your vehicle:
python cli.py -e elon@tesla.com -w -a ACTUATE_TRUNK -k which_trunk=front
then you could start trying to adjust the amps by a similar command. When it does not return an error code, then you could check from the Tesla App (or in the car) whether it really succeeded and modified the charging amps. You could try (assuming amps are not currently set to exactly 10 A):
python cli.py -e elon@tesla.com -w -a CHARGING_AMPS -k amps=10
python cli.py -e elon@tesla.com -w -a CHARGING_AMPS -k charging_amps=10
python cli.py -e elon@tesla.com -w -a CHARGING_AMPS -k chargingamps=10
python cli.py -e elon@tesla.com -w -a CHARGING_AMPS -k current=10
...
If you use the Android app, it might be possible to use a SSL proxy to capture the API calls made by the app.
According to https://tesla-api.timdorr.com/miscellaneous/endpoints the command is set_charging_amps
"CHARGING_AMPS": { "TYPE": "POST", "URI": "api/1/vehicles/{vehicle_id}/command/set_charging_amps", "AUTH": true
That's correct. The same can also be found in teslapy/endpoints.json, already. :-) What we are looking for is the name of the parameter that has be passed to the POST request to that given URI.
Ok, I can test it, from a python program, what do I call in Python code, as opposed to what you have above with using cli.py?
if you have a vehicle object, it's just this:
vehicle.command('CHARGING_AMPS', amps=10)
but again, the question is what the right parameter name should be instead of amps
here.
vehicles[0].command('CHARGING_AMPS', amps=10)
Traceback (most recent call last):
File "C:/Users/dmaunder/Programming/Python/powermeter/tesla-test.py", line 32, in
Try set_charging_amps instead of CHARGING_AMPS.
Same.
vehicles[0].command('SET_CHARGING_AMPS', amps=10)
ValueError: Unknown endpoint name SET_CHARGING_AMPS
Same here, but my Model 3 does not yet have the firmware 2021.36. I thought that would be the reason for the unknown endpoint.
So, it might be more promising to follow Tim's advice above to use an Android App and an SSL proxy as a sniffer.
ValueError: Unknown endpoint name CHARGING_AMPS means that this endpoint is not found in endpoints.json. You are probably using the version is on pypi. If you checkout the latest commit (882c8ef) from git, then it should work.
Ack. My message above was based on an old TeslaPy version. With the current version and my pre 2021.36 vehicle, I get:
File "/usr/local/lib/python3.8/dist-packages/TeslaPy-2.0.0-py3.8.egg/teslapy/__init__.py", line 524, in command File "/usr/local/lib/python3.8/dist-packages/TeslaPy-2.0.0-py3.8.egg/teslapy/__init__.py", line 394, in api File "/usr/local/lib/python3.8/dist-packages/TeslaPy-2.0.0-py3.8.egg/teslapy/__init__.py", line 277, in api File "/usr/local/lib/python3.8/dist-packages/TeslaPy-2.0.0-py3.8.egg/teslapy/__init__.py", line 119, in request File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 404 Client Error: `` for url: https://owner-api.teslamotors.com/api/1/vehicles/15183525502xxxxxx/command/set_charging_amps
No luck yet with the SSL Proxy. In the app you see the current AMPS and have arrows up and down to change.
ValueError: Unknown endpoint name CHARGING_AMPS means that this endpoint is not found in endpoints.json. You are probably using the version is on pypi. If you checkout the latest commit (882c8ef) from git, then it should work.
My vehicle is on 2021.36. Sorry do be a dummy, but how do I get/install the latest version from github? I running on Windows for dev and then raspberry pi for production
Ignore last, got them installed, and got it all working.
print 'Current charge rate requested ' + str(vehicles[0].get_vehicle_data()['charge_state']['charge_current_request']) + 'A, actual rate is ' + str(vehicles[0].get_vehicle_data()['charge_state']['charger_actual_current']) + 'A'
print 'Setting rate to 24A'
vehicles[0].command('CHARGING_AMPS', charging_amps=24)
time.sleep(5)
print 'Current charge rate requested ' + str(vehicles[0].get_vehicle_data()['charge_state']['charge_current_request']) + 'A, actual rate is ' + str(vehicles[0].get_vehicle_data()['charge_state']['charger_actual_current']) + 'A'
gives output
Current charge rate requested 20A, actual rate is 20A Setting rate to 24A Current charge rate requested 24A, actual rate is 24A
And you see the charge rate change in the app.
Added to the table, see commit b217a4e. @dmaunder can you investigate SCHEDULED_CHARGING and SCHEDULED_DEPARTURE as well?
Thanks, dmaunder! Thanks, Tim!
@dmaunder can you investigate SCHEDULED_CHARGING and SCHEDULED_DEPARTURE as well?
Ill have a look on Thursday if I get time
Through trial and error, I found the payload to pass in the POST for set_scheduled_charging is:
payload = { 'enable': 'True', 'time': <time> }
where <time>
is the number of minutes so if you want 6:00AM local time, then <time>
would be 360.
Thanks @themonomers, what about SCHEDULED_DEPARTURE?
Thanks @themonomers, what about SCHEDULED_DEPARTURE?
No luck yet. Still working on it; I have it half-working.
Thanks @themonomers, what about SCHEDULED_DEPARTURE?
No luck yet. Still working on it; I have it half-working.
Here's where I am on set_scheduled_departure. The payload currently looks like this:
payload = { 'enable': 'True', 'departure_time': <time>, 'preconditioning_enabled': 'False', 'preconditioning_times': 'weekdays' 'off_peak_charging_enabled': 'True', 'off_peak_charging_times': 'weekdays', 'off_peak_hours_end_time': (6 * 60) }
What works: enable
, departure_time
, preconditioning_enabled
, and off_peak_charging_enabled
. These 4 attributes correctly modify the settings and reflect the same in the mobile app. The other ones I can't seem to figure out. I've tried varied names for the attributes and even tried some nested structures.
Additionally, perhaps it's a defect or my lack of understanding but in the mobile app there's no "enable" toggle for departure mode like there is for scheduled charging mode. When you toggle the enable for the scheduled charging in the mobile app, when it's plugged in it will show a message like "Charging will start at 5:00 AM" in the charging section but not for departure mode UNLESS you also toggle on Off-peak Charge. Only if you toggle Off-peak Charge in the mobile app will it show a message in the charging section about the departure time. When using the API, I can't get it to do that because I'm not passing the correct attribute for off_peak_hours_end_time
and it defaults to 12:00 AM, despite having toggled the value for off_peak_charging_enabled
. If I manually update the off_peak_hours_end_time
from the mobile app, it will correctly show the message in the charging section.
Thanks @themonomers, what about SCHEDULED_DEPARTURE?
Ok I finally figured it out. Here's the payload to POST:
payload = { 'enable': 'True', 'departure_time': <time_1>, 'preconditioning_enabled': <'True' or 'False'>, 'preconditioning_weekdays_only': <'True' or 'False'>, 'off_peak_charging_enabled': <'True' or 'False'>, 'off_peak_charging_weekdays_only': <'True' or 'False'>, 'end_off_peak_time': <time_2> }
where <time_1>
and <time_2>
are in minutes. This was quite tricky as some of the attributes in the POST don't match their output names.
Excellent job, thanks!
CHARGING_AMPS can be set to less than 5, by calling the API twice.
The first call sets it to 5, then the second call will set to the desired value less than 5.
This is useful for fine control matching solar production.
This is not possible from the Telsa App, only the API call.
I have submitted PR #42.
You can even go to 0 if you want to quickly stop charging when your house needs power.
I thought I had read elsewhere previously that the car didn’t like it at less than 5A
From: purcell-lab @.> Sent: Wednesday, 27 October 2021 10:11 AM To: tdorssers/TeslaPy @.> Cc: @.; Mention @.> Subject: Re: [tdorssers/TeslaPy] Add CHARGING_AMPS incl. yet unknown parameter name to README.md "Commands" table (#36)
CHARGING_AMPS can be set to less than 5, by calling the API twice.
The first call sets it to 5, then the second call will set to the desired value less than 5.
This is useful for fine control matching solar production.
This is not possible from the Telsa App, only the API call.
I have submitted PR #42https://github.com/tdorssers/TeslaPy/pull/42.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/tdorssers/TeslaPy/issues/36#issuecomment-952397563, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AASYAA7QV7IWQAE5QBLPKZDUI4YRVANCNFSM5FREA25A. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Very interesting! My MS2018 was able to charge less than 5A at 3 phases using the "set twice" trick. After setting it to 0A the charging was interrupted (Tesla App sent me a push message) and I was unable to restart it by increase CHARGING_AMPS. Even START_CHARGE failed because the charging session was apparently still in progress. Only after a STOP_CHARGE/START_CHARGE + CHARGING_AMPS > 0 cycle the charging actually resumed. So use with care!
The new command CHARGING_AMPS obviously has to have a parameter to set the intended current. Does anybody know the name of this parameter and its value range (maybe, e.g. simply 5..16 for Model 3)? When it is known, it should be added to the according table in the Commands section of the README.md file.