G-Two / subarulink

A python package for interacting with Subaru STARLINK remote vehicle services.
Apache License 2.0
84 stars 14 forks source link

VehicleStatus.json Multiple Vehicles #7

Closed stboch closed 3 years ago

stboch commented 4 years ago

@G-Two Looking into what/if using mysubaru.com/vehicleStatus.json for some data like perhaps regular checks of the Car's Location without having to force mysubaru to do a locate.

Can you let me know what it looks like for you? There doesn't seem to be any specific Matching ID used for the vehicle but I might be missing something only having 1 car.

{"success":true,"data":{"vhsId":1677992786,"odometerValue":4520,"odometerValueKilometers":7272,"eventDate":"2020-07-11T22:13:38.000+0000","eventDateStr":"2020-07-11T22:13+0000","latitude":39.XXXXXX,"longitude":-76.XXXXXX,"positionHeadingDegree":"337","distanceToEmptyFuelMiles":89.48,"distanceToEmptyFuelKilometers":144,"avgFuelConsumptionMpg":24.8,"avgFuelConsumptionLitersPer100Kilometers":9.5,"vehicleStateType":"IGNITION_OFF","distanceToEmptyFuelMiles10s":90,"distanceToEmptyFuelKilometers10s":140}}

G-Two commented 4 years ago

@stboch, here is what I receive with mysubaru.com/vehicleStatus.json:

{"success":true,"data":{"vhsId":1677293040,"odometerValue":3533,"odometerValueKilometers":5685,"eventDate":"2020-07-11T20:23:01.000+0000","eventDateStr":"2020-07-11T20:23+0000","latitude":90.0,"longitude":180.0,"tirePressureFrontLeft":"2600","tirePressureFrontRight":"2600","tirePressureRearLeft":"2500","tirePressureRearRight":"2400","tirePressureFrontLeftPsi":"37.71","tirePressureFrontRightPsi":"37.71","tirePressureRearLeftPsi":"36.26","tirePressureRearRightPsi":"34.81","distanceToEmptyFuelMiles":509.52,"distanceToEmptyFuelKilometers":820,"avgFuelConsumptionMpg":102.2,"avgFuelConsumptionLitersPer100Kilometers":2.3,"evStateOfChargePercent":76,"evDistanceToEmptyMiles":509.52,"evDistanceToEmptyKilometers":820,"vehicleStateType":"IGNITION_OFF","distanceToEmptyFuelMiles10s":510,"distanceToEmptyFuelKilometers10s":820}}

The eventDate returned corresponds with the last time I turned my car off.

When I switch cars from the browser interface, the following API call is issued: https://www.mysubaru.com/vehicle/switchVehicle/<SUBARU_ID>.json?_=<TIMESTAMP>

If I call vehiclesStatus.json after that, I do get information for the other car (dated since its Starlink subscription ended in Feb): {"success":true,"data":{"vhsId":248771385,"odometerValue":14079,"odometerValueKilometers":22657,"eventDate":"2020-02-21T10:11:59.000+0000","eventDateStr":"2020-02-21T10:11+0000"}}

As with the mobile API, the "current" vehicle state appears to be maintained on the server side and the client application needs to issue an API call to change it.

One advantage of vehicleStatus.json is that it seems to return the last known sane values for items like range, tire pressure, and fuel consumption. The mobile API currently used by subarulink seems to return bogus values unless the vehicle was recently turned off. There's some logic to account for that, but it would be better to be able to trust the values returned by Subaru. Are you able to reuse the mobile API session cookie for the web API calls?

One issue I am experiencing with vehicleStatus.json, is that I never get a valid lat/lon position returned. Even if I use the official mobile app to issue a locate command prior to requesting vehicleStatus.json, the value I receive is always a 90.0/180.0.

stboch commented 4 years ago

Yeah about 5 months ago I noticed what your seeing now. Wrong lat/long also then at one point truncated to an int like someone forgot to make it a double instead of an int.

Went back into the web GUI to make sure everything looks right for the POI stuff and noticed that it was pulling last know location in the send trip part that's when I noticed vehicle status was updated, hasn't tried with the session from the mobile but I am optimistic it will work since it think it's part of the same stack that provides refresh and select vehicle.

stboch commented 3 years ago

@G-Two I just noticed that the SelectVechile.json is providing vehicleGeoPosition Not sure that I saw that in the past, I know yours didn't return the correct location in vehicleStatus.json let me know if this one returned data...

Also tested Assigned Authorize User letting two accounts share access to a car, and everything works great just like I would have two cars, This was a 2019 Accent and my 2020 Outback

G-Two commented 3 years ago

@stboch I still get 180.0/90.0 with selectVehicle.json. I wonder if it is just an issue with the PHEV Crosstrek. If this provides a reliable location for all other Subarus then it might be worth using it.

G-Two commented 3 years ago

Now using a mixture of locate/execute.json and vehicleStatus.json to provide data. As of 0.3.9, last known good coordinates are kept if bogus coordinates are received, and a flag is set to notify the application.