Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TesSense on Raspberry Pi #9

Open
bbsanders opened this issue Mar 8, 2024 · 7 comments
Open

TesSense on Raspberry Pi #9

bbsanders opened this issue Mar 8, 2024 · 7 comments

Comments

@bbsanders
Copy link

Does TesSense run on a Raspberry with Python 3.12.2? I'm getting the following errors. (I amended the first print statement to print the Python version as well as the TZ.)

US/Central 3.12.2 (main, Mar 5 2024, 10:50:29) [GCC 8.3.0]

Initating connection to Sense...
Traceback (most recent call last):
File "/home/pi/Downloads/TesSense.py", line 454, in
asyncio.run(main())
File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/asyncio/base_events.py", line 685, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/home/pi/Downloads/TesSense.py", line 450, in main
await asyncio.gather(*tasks)
File "/home/pi/Downloads/TesSense.py", line 154, in TesSense
mycar = tesla.vehicle_list()[1]
~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range


(program exited with code: 1)
Press return to continue

@israndy
Copy link
Owner

israndy commented Mar 8, 2024 via email

@bsf29
Copy link

bsf29 commented Mar 8, 2024

I'm running on RaspPi 4b with Python 3.11. It the problem is what was pointed out.... you only have 1 tesla and you are referencing a 2nd car. I reproduced the error using mycar = tesla.vehicle_list()[2]

I have 2 Tesla so I have 2 copies of the code specifying which car is to be charged: mycar = tesla.vehicle_list()[0] and mycar = tesla.vehicle_list()[1]. I'm not that good at Python to figure out how to specify the car on the command line. I have defined 2 PlugInstance() so Sense can track the power for each car. My Generac Solar system includes a PWRCell battery so I have made other modifications to minimize battery usage and only use excess solar production.

@bbsanders
Copy link
Author

Thanks to you both. I changed the mycar statement and the program is running to the point where it's trying to change the Tesla's charging amps, but it's getting a "403 Client Error", which I assume is due to the compatibility problem with the current Tesla API.


Initating connection to Sense...
Starting connection to ... [ 32.9 , -96.763 ]
last seen just now at 40% SoC
11:47 Tesla
Level: 40 %, Limit 80 %, 4.7 MPH 249 Volts 1.32 kWh added,
5 of a possible 32 Amps, 21.58 Hours remaining

Charging at 5 amps, with 1927 watts surplus
Increasing charging to 12 amps
403 Client Error: Tesla Vehicle Command Protocol required, please refer to the documentation here: https://developer.tesla.com/docs/fleet-api#2023-10-09-rest-api-vehicle-commands-endpoint-deprecation-warning for url: https://owner-api.teslamotors.com/api/1/vehicles/3744432960343986/command/set_charging_amps }
Fri 11:47 AM H: Failed to change
66.4 F, Fri 11:47 AM Wait two minutes...

Hopefully, Tesla will cooperate and fix the problem with the API. This is a great app - perfect for someone with a Tesla, and Sense, and Solar panels, and a electricity provider who pays a paltry amount for excess energy. Thanks again!

@bsf29
Copy link

bsf29 commented Mar 9, 2024

I think this is the issue that you need to modify your teslapy's endpoints.json file. Sorry but I don't remember where I found the discussion and the following fix.
Depending how you setup your environment and the version of Python you are using it will be similar to: venv/lib/python3.11/site-packages/teslapy/endpoints.json
Find "VEHICLE_DATA" section and modify the URI line (should be around line #39)
"VEHICLE_DATA": {
"TYPE": "GET",
"URI": "api/1/vehicles/{vehicle_id}/vehicle_data",
"AUTH": true
},

Change it to the following:
"URI": "api/1/vehicles/{vehicle_id}/vehicle_data?endpoints=location_data%3Bcharge_state%3Bclimate_state%3Bvehicle_state%3Bvehicle_config%3Bgui_settings",

This is all one line. Take care that you maintain the indent, quotes, and comma at the end of the line.
I don't know if the teslapy owners are going to add this fix to their code at some point.

@bbsanders
Copy link
Author

Thanks. I made that change, but I'm getting the same error.

403 Client Error: Tesla Vehicle Command Protocol required, please refer to the documentation here: https://developer.tesla.com/docs/fleet-api#2023-10-09-rest-api-vehicle-commands-endpoint-deprecation-warning for url: https://owner-api.teslamotors.com/api/1/vehicles/3744432960343986/command/set_charging_amps }
Sat 01:33 PM H: Failed to change

It looks like it wants me to use the new Tesla Vehicle Command Protocol. According to their developer page, "All vehicles* will require Tesla Vehicle Command protocol. The REST API will be fully deprecated" as of January 2024. Some vehicles are excluded from the change, though it doesn't look like mine is one of them. I have a Model 3 2023 with Version: v11.1 (2024.2.7).

@bsf29
Copy link

bsf29 commented Mar 10, 2024

Sorry, I don't remember what else I may have tweaked. I don't think our 2018 and 2020 M3 are excluded from the new API's. I had problems with TesSense, TeslaMate, and one of my iPhone apps not working with the API changes in Dec/Jan. You could try deleting your cache.json and force TesSense to get a new token and see if that corrects the issue. I did rebuild my RaspPi in early January so I could clean up some old junk and move to a larger/faster drive. I think that's when I also found the TeslaPy fix I provided. Needing that mod seems to imply that our M3's are using the new API's. Here's the modules I have installed. Some are outdated but everything is working and I didn't see a need to upgrade.
pip_list.txt

@bbsanders
Copy link
Author

Tried deleting cache.json, but no joy. I also tried modifying the def vehicle_list(self) section of init.py as suggested by DeLN0 on tdorssers/TeslaPy#156, but no success. Were there any other changes to the endpoints.json file you can remember, specifically to the set_charging_amps section? That seems to be the command generating the error I'm getting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants