DurgNomis-drol / ha_toyota

Toyota Connected Services integration for Home Assistant.
MIT License
148 stars 29 forks source link

RAV4 PHEV missing petrol range and EV battery information #97

Closed lkucytowski closed 8 months ago

lkucytowski commented 2 years ago

Firstly, I would like to Thank You for making this integration! How can I buy you a coffee?

I just got RAV4 PHEV and I spotted two issues with entities showing wrong or no information.

  1. EV battery entity (sensor.rav4_phev_ev_battery) is showing none instead of the charge percentage.
  2. Range (sensor.rav4_phev_range) is showing EV battery range, I guess we need another sensor showing petrol range.

Here are the screenshoots: CleanShot 2022-01-10 at 18 41 03 IMG_4876 IMG_4877

DurgNomis-drol commented 2 years ago

I don't know how good you are at linux, but if you can try to run the below code and post the output, it would help a lot 😃

import asyncio
import logging
from mytoyota.client import MyT

logging.basicConfig(level=logging.DEBUG)

username = "jane@doe.com"
password = "MyPassword"
locale = "da-dk"

client = MyT(username=username, password=password, locale=locale, region="europe")

async def get_information():
    print("Logging in...")
    await client.login()

    print("Retrieving cars...")
    # Returns cars registered to your account + information about each car.
    cars = await client.get_vehicles()

    for car in cars:

        # Returns live data from car/last time you used it as an object.
        vehicle = await client.get_vehicle_status(car)

        print(vehicle.as_dict())

loop = asyncio.get_event_loop()
loop.run_until_complete(get_information())
loop.close()

Beaware that normally everything should be censored, but because we run with logging=debug, this will show the raw data from toyota. So make sure that you censor it before posting it.

lkucytowski commented 2 years ago

Thanks, my Linux skills are quite good, so more than happy to help you with troubleshooting, here is the result:

DEBUG:mytoyota:Raw sensor data: {}
{'id': XXX, 'alias': 'RAV4 PHEV', 'vin': 'XXX', 'details': {'engine': '2.5 TNGA HEV', 'entitledBy': 'CUSTOMER', 'entitledOn': '2022-01-10T16:52:01.936Z', 'exteriorColour': '2QJ ', 'fuel': 'PETROL', 'grade': 'Limited', 'horsePower': 185, 'hybrid': True, 'imageUrl': 'XXX', 'interiorColour': '20', 'isEntitled': True, 'isNC': False, 'licensePlate': 'XXX', 'modelCode': 'RE', 'modelDescription': 'RAV4 PHEV', 'modelDocumentId': '12345', 'modelName': 'RAV4 PHEV', 'owner': False, 'ownerFlag': False, 'productionYear': '2021', 'source': 'NMSC', 'transmission': 'Continuously Variable Transmission', 'transmissionType': 'CVT', 'vehicleAddedOn': '2022-01-10T16:23:36.541Z'}, 'status': {'energy': {'legacy': True, 'level': 8.0, 'type': 'PETROL', 'range': 1.0, 'range_with_aircon': 0.9, 'chargeinfo': {'status': 'charging', 'remaining_time': 160, 'remaining_amount': 31, 'start_time': '42:35', 'end_time': '42:35'}}, 'hvac': {'legacy': True, 'current_temperature': 27, 'target_temperature': 22.0, 'blower_on': 0, 'front_defogger_on': 0, 'rear_defogger_on': 0, 'last_updated': '2022-01-10T22:26:12Z'}, 'odometer': {'mileage': 114, 'unit': 'km'}, 'parking': {'latitude': XXX, 'longitude': XXX, 'timestamp': 1641927232000}, 'vehicle': {'overallstatus': None, 'lights': None, 'hood': None, 'doors': None, 'windows': None, 'key': None, 'last_updated': None}}, 'servicesEnabled': {'connectedServices': True}, 'statistics': {}}

Looks like the Petrol range is not there :( The one pulled by the script is EV range:

ev_range

BTW When I start charging the car, I can see that the sensor.rav4_phev_ev_battery entity is aware of it showing charging instead of none, but the other data is missing.

rav4_phev_ev_battery

DurgNomis-drol commented 2 years ago

Can you please post the entire output from the script 😃

lkucytowski commented 2 years ago

Here it is:

DEBUG:asyncio:Using selector: EpollSelector
Logging in...
DEBUG:mytoyota:Performing first login
DEBUG:mytoyota:Getting new token...
DEBUG:httpx._client:HTTP Request: POST https://ssoms.toyota-europe.com/authenticate "HTTP/1.1 200 OK"
DEBUG:mytoyota:Extracting token from result
DEBUG:mytoyota:Token is the correct format
DEBUG:mytoyota:Saving token and uuid
Retrieving cars...
DEBUG:mytoyota:Getting list of vehicles associated with the account
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '4*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=4*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:httpx._client:HTTP Request: GET https://cpb2cs.toyota-europe.com/vehicle/user/XXX/vehicles?services=uio&legacy=true "HTTP/1.1 200 OK"
DEBUG:mytoyota:Getting status for vehicle - JTMXXX********...
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '4*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=4*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '4*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=4*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '4*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=4*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '4*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=4*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:httpx._client:HTTP Request: GET https://myt-agg.toyota-europe.com/cma/api/vehicle/XXX/addtionalInfo "HTTP/1.1 200 OK"
DEBUG:httpx._client:HTTP Request: GET https://myt-agg.toyota-europe.com/cma/api/users/XXX/vehicles/XXX/vehicleStatus "HTTP/1.1 200 OK"
DEBUG:httpx._client:HTTP Request: GET https://myt-agg.toyota-europe.com/cma/api/vehicles/XXX/remoteControl/status "HTTP/1.1 200 OK"
DEBUG:httpx._client:HTTP Request: GET https://cpb2cs.toyota-europe.com/vehicle/user/XXX/vehicle/XXX?legacy=true&services=fud,connected "HTTP/1.1 200 OK"
DEBUG:mytoyota:Presenting information as an object...
DEBUG:mytoyota:Using legacy odometer data: [{'type': 'mileage', 'value': 121, 'unit': 'km'}, {'type': 'Fuel', 'value': 8.0}]
DEBUG:mytoyota:Raw sensor data: {}
{'id': XXX, 'alias': 'RAV4 PHEV', 'vin': 'XXX', 'details': {'engine': '2.5 TNGA HEV', 'entitledBy': 'CUSTOMER', 'entitledOn': '2022-01-10T16:52:01.936Z', 'exteriorColour': '2QJ ', 'fuel': 'PETROL', 'grade': 'Limited', 'horsePower': 185, 'hybrid': True, 'imageUrl': 'XXX', 'interiorColour': '20', 'isEntitled': True, 'isNC': False, 'licensePlate': 'XXX', 'modelCode': 'RE', 'modelDescription': 'RAV4 PHEV', 'modelDocumentId': '12345', 'modelName': 'RAV4 PHEV', 'owner': False, 'ownerFlag': False, 'productionYear': '2021', 'source': 'NMSC', 'transmission': 'Continuously Variable Transmission', 'transmissionType': 'CVT', 'vehicleAddedOn': '2022-01-10T16:23:36.541Z'}, 'status': {'energy': {'legacy': True, 'level': 8.0, 'type': 'PETROL', 'range': 65.3, 'range_with_aircon': 58.77, 'chargeinfo': {'status': 'none', 'remaining_time': 65535, 'remaining_amount': 91, 'start_time': '42:35', 'end_time': '42:35'}}, 'hvac': {'legacy': True, 'current_temperature': 23, 'target_temperature': 20.0, 'blower_on': 0, 'front_defogger_on': 0, 'rear_defogger_on': 0, 'last_updated': '2022-01-12T07:33:12Z'}, 'odometer': {'mileage': 121, 'unit': 'km'}, 'parking': {'latitude': XXX, 'longitude': XXX, 'timestamp': 1641974630000}, 'vehicle': {'overallstatus': None, 'lights': None, 'hood': None, 'doors': None, 'windows': None, 'key': None, 'last_updated': None}}, 'servicesEnabled': {'connectedServices': True}, 'statistics': {}}
DurgNomis-drol commented 2 years ago

Awesome thanks!

The missing attributes for ev_battery sensor is because of an error on my part. I will fix this in the coming days. Right now the ev_battery sensor does not show how much is left in the battery, but what the status are on the charging. This I can see is misleading and should be changed to something else.

I need some more info for trouble shooting the EV battery info. Can you please run the below code 😃

import asyncio
import logging
from mytoyota.client import MyT

logging.basicConfig(level=logging.DEBUG)

username = "jane@doe.com"
password = "MyPassword"
locale = "da-dk"

client = MyT(username=username, password=password, locale=locale, region="europe")

async def get_information():
    print("Logging in...")
    await client.login()

    print("Retrieving cars...")
    # Returns cars registered to your account + information about each car.
    cars = await client.get_vehicles()

    for car in cars:
        vehicle = await client.get_vehicle_status(car)

        odometer = await client.api.get_odometer_endpoint(vehicle.vin)
        status = await client.api.get_vehicle_status_endpoint(vehicle.vin)
        legacy_status = await client.api.get_vehicle_status_legacy_endpoint(vehicle.vin)

        print(odometer)
        print(status)
        print(legacy_status)

loop = asyncio.get_event_loop()
loop.run_until_complete(get_information())
loop.close()
lkucytowski commented 2 years ago

Here it is:

DEBUG:asyncio:Using selector: EpollSelector
Logging in...
DEBUG:mytoyota:Performing first login
DEBUG:mytoyota:Getting new token...
DEBUG:httpx._client:HTTP Request: POST https://ssoms.toyota-europe.com/authenticate "HTTP/1.1 200 OK"
DEBUG:mytoyota:Extracting token from result
DEBUG:mytoyota:Token is the correct format
DEBUG:mytoyota:Saving token and uuid
Retrieving cars...
DEBUG:mytoyota:Getting list of vehicles associated with the account
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '1*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=1*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:httpx._client:HTTP Request: GET https://cpb2cs.toyota-europe.com/vehicle/user/XXX/vehicles?services=uio&legacy=true "HTTP/1.1 200 OK"
DEBUG:mytoyota:Getting status for vehicle - JTMGBRFV9********...
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '1*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=1*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '1*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=1*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '1*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=1*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '1*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=1*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:httpx._client:HTTP Request: GET https://myt-agg.toyota-europe.com/cma/api/vehicle/XXX/addtionalInfo "HTTP/1.1 200 OK"
DEBUG:httpx._client:HTTP Request: GET https://myt-agg.toyota-europe.com/cma/api/users/XXX/vehicles/XXX/vehicleStatus "HTTP/1.1 200 OK"
DEBUG:httpx._client:HTTP Request: GET https://myt-agg.toyota-europe.com/cma/api/vehicles/XXX/remoteControl/status "HTTP/1.1 200 OK"
DEBUG:httpx._client:HTTP Request: GET https://cpb2cs.toyota-europe.com/vehicle/user/XXX/vehicle/XXX?legacy=true&services=fud,connected "HTTP/1.1 200 OK"
DEBUG:mytoyota:Presenting information as an object...
DEBUG:mytoyota:Using legacy odometer data: [{'type': 'mileage', 'value': 130, 'unit': 'km'}, {'type': 'Fuel', 'value': 8.0}]
DEBUG:mytoyota:Raw sensor data: {}
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '1*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=1*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:httpx._client:HTTP Request: GET https://myt-agg.toyota-europe.com/cma/api/vehicle/XXX/addtionalInfo "HTTP/1.1 200 OK"
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '1*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=1*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:httpx._client:HTTP Request: GET https://myt-agg.toyota-europe.com/cma/api/users/XXX/vehicles/XXX/vehicleStatus "HTTP/1.1 200 OK"
DEBUG:mytoyota:Checking if token has expired...
DEBUG:mytoyota:Constructing additional headers...
DEBUG:mytoyota:Additional headers: {'X-TME-LC': 'da-dk', 'X-TME-LOCALE': 'da-dk', 'X-TME-TOKEN': '1*****************************************************************************************************************', 'Cookie': 'iPlanetDirectoryPro=1*****************************************************************************************************************', 'uuid': '7***********************************'}
DEBUG:mytoyota:Creating client...
DEBUG:mytoyota:Base headers: {'Content-Type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Sec-Fetch-Dest': 'empty', 'X-TME-BRAND': 'TOYOTA'} - Timeout: 15
DEBUG:mytoyota:Body: None - Parameters: None
DEBUG:httpx._client:HTTP Request: GET https://myt-agg.toyota-europe.com/cma/api/vehicles/XXX/remoteControl/status "HTTP/1.1 200 OK"
[{'type': 'mileage', 'value': 130, 'unit': 'km'}, {'type': 'Fuel', 'value': 8.0}]
{'event': {'lat': 'XXX', 'lon': 'XXX', 'timestamp': '1642005997000'}, 'tripStatus': '0'}
{'VehicleInfo': {'RemoteHvacInfo': {'InsideTemperature': 21, 'RemoteHvacMode': 0, 'RemoteHvacProhibitionSignal': 1, 'Temperaturelevel': 28, 'BlowerStatus': 0, 'FrontDefoggerStatus': 0, 'RearDefoggerStatus': 0, 'LatestAcStartTime': '2022-01-12T07:33:12Z', 'TemperatureDisplayFlag': 1, 'SettingTemperature': 21.0}, 'ChargeInfo': {'PlugStatus': 12, 'PlugInHistory': 33, 'RemainingChargeTime': 65535, 'EvTravelableDistance': 45.9, 'EvTravelableDistanceSubtractionRate': 10, 'ChargeRemainingAmount': 75, 'SettingChangeAcceptanceStatus': 0, 'ChargeWeek': 0, 'ChargeStartTime': '42:35', 'ChargeEndTime': '42:35', 'ConnectorStatus': 2, 'BatteryPowerSupplyPossibleTime': 16383, 'ChargingStatus': 'none', 'EvDistanceWithAirCoInKm': 41.31, 'GasolineTravelableDistance': 128, 'ChargeType': 15, 'GasolineTravelableDistanceUnit': 1, 'EvDistanceInKm': 45.9}, 'AcquisitionDatetime': '2022-01-12T16:48:39Z'}, 'ReturnCode': '000000'}
DurgNomis-drol commented 2 years ago

I have just merged a PR that fixes the use of wrong attributes for ev_battery sensor.

I have also opened a PR proposing we change the name to EV battery status to avoid confusion. If you have a better name please leave a comment over there https://github.com/DurgNomis-drol/ha_toyota/pull/98.

Will look into making it possible to show both charge percent and range for petrol correctly soon. 😃

CM000n commented 8 months ago

We recently released version 2.0.0 of the Custom Component with major changes and support for the new Mytoyota API. As we unfortunately cannot provide support for Custom Component versions < v2.0.0, I hereby close your issue. If the issue still applies to the current version, you are of course free to open a new issue. 😊