wardmundy / php-api-tesla

PHP Application Library for Tesla API
MIT License
7 stars 1 forks source link

Dealing with multiple vehicles #3

Open rmyadsk opened 3 years ago

rmyadsk commented 3 years ago

This is a good collection of scripts - and getting up and running via the readme is very easy. I know this hasn't been updated since 2017 but wonder if someone can clue me in, as I'm having an issue:

I have a Tesla account with two vehicles linked. When running vehicle.php, the vehicle file is populated with the id of the first vehicle, and the vehicleinfo file is populated with details of both vehicles. Running any of the action scripts performs actions on the first vehicle only. Changing the vehicle file to use the id of the second vehicle results in the following:

PHP Notice: Trying to access array offset on value of type null in /root/php-api-tesla/init.php on line 69 NULL

Is there a way to force adoption of the second vehicle, or to configure the scripts to adjust for multiple-vehicle accounts?

rmyadsk commented 3 years ago

To anyone with two vehicles - I think I may have an answer for you. Delete your vehicle and vehicleinfo files (if present) then run change line 22 from:

$pos = strpos($response,'"id":');

to:

$pos = strrpos($response,'"id":');

strrpos finds the last instance of the "id": string, specifying the second vehicle.

Also - it seems NULL may be a generic response for when vehicles may be asleep.