widewing/ha-toyota-na

Retrieve battery / charging status

Closed this issue ยท 42 comments

Any way to retrieve battery level and charging status for the Prius Prime and RAV4 Prime PHEVs? Would be very useful for automations in HomeAssistant to make sure the car is plugged in.

Can you take a look at the output of

python -m toyota_na.app get_vehicle_status <vin>
python -m toyota_na.app get_vehicle_health_report <vin>
python -m toyota_na.app get_vehicle_health_status <vin>

if they contain the battery status? could you share the info here and mask the sensitive data

Doesnt seem to report battery level or charging status on any of those - closest I see is fugage value from get_vehicle_status and fuelLevel coming back on get_vehicle_health_status

python -m toyota_na.app get_vehicle_status <vin>

    "fugage": {
      "value": 97.0,
      "unit": "%"
    },
    "rage": {
      "value": 433.0,
      "unit": "Mile"
    },
    "odo": {
      "value": 9119.0,
      "unit": "Mile"
    }
  },

python -m get_vehicle_health_status <vin>

{
  "mileage": "9119",
  "mileageUnit": "mile",
  "fuelLevel": "98",
  "fuelUnit": "%",
  "smartKeyBatLastUpdTime": "",
  "quantityOfEngOilStatus": "3",
  "quantityOfEngOilDesc": "Quantity of engine oil is at the required level.",
  "quantityOfEngOilIcon": [
    {
      "deviceName": "ipad",
      "deviceUrl": "https://tmsappqstorage01.blob.core.windows.net/ipad/LEX_BRRI_VHR_vehicle_status_green.png"
    },
    {
      "deviceName": "web",
      "deviceUrl": "https://tmsappqstorage01.blob.core.windows.net/web/LEX_BRRI_VHR_vehicle_status_green.png"
    },
    {
      "deviceName": "mobile-1",
      "deviceUrl": "https://tmsappqstorage01.blob.core.windows.net/mobile1/LEX_BRRI_VHR_vehicle_status_green.png"
    },
    {
      "deviceName": "mobile-2",
      "deviceUrl": "https://tmsappqstorage01.blob.core.windows.net/mobile2/LEX_BRRI_VHR_vehicle_status_green.png"
    },
    {
      "deviceName": "mobile-3",
      "deviceUrl": "https://tmsappqstorage01.blob.core.windows.net/mobile3/LEX_BRRI_VHR_vehicle_status_green.png"
    }
  ],
  "quantityOfEngOilLastUpdTime": "",
  "warning": [],
  "vin": "<REMOVED>",
  "wnglastUpdTime": "2021-10-07T15:11:29.0000000Z"
}```

Does the Toyota app show you the status anywhere? If not it's likely not going to be in the API. But I can look at the APK dump when I have some time.

Yeah it's in there -
Screenshot_20220124-150330_Toyota
Screenshot_20220124-150338_Toyota

I found several APIs for electric vehicles. We can probably add this info to the integration once we figure out how to detect if a car is an phev or not.

The response for my vehicle returns the following in the vehicle overview portion of the response:

"evVehicle": false,

It also returns other values along the similar lines, in the features section:

"evBattery": 0,
"evChargeStation": 0,
"evRemoteServices": 0,
"evVehicleStatus": 0,

"evChargeStationsCapable": false,

I also see the following:

"chargeManagement": false,
"nextCharge": false,
"weeklyCharge": false

The values above are for my Toyota RAV4, a 17CYPLUS that is NOT an Electric Vehicle.

@larryventura Can you post the full response from get_vehicle_status on your Electric model, sans any personally identifiable information of course.

I'm wondering if these got moved to another endpoint for newer PHEVs - nothing seen for me

python3 -m toyota_na.app get_vehicle_status <REDACTED>

WARNING 2022-02-07 10:58:17,617 - No device ID loaded; new ID generated:  <REDACTED>
INFO 2022-02-07 10:58:17,909 - Response status: {'messages': [{'responseCode': 'ONE-GLOBAL-RS-10000', 'description': 'Request Completed Successfully', 'detailedDescription': 'Request Completed Successfully'}]}
{
  "vehicleStatus": [
    {
      "category": "Driver Side",
      "displayOrder": 1,
      "sections": [
        {
          "section": "Door",
          "values": [
            {
              "value": "Closed",
              "status": 0
            },
            {
              "value": "Locked",
              "status": 0
            }
          ]
        },
        {
          "section": "Rear Door",
          "values": [
            {
              "value": "Closed",
              "status": 0
            },
            {
              "value": "Locked",
              "status": 0
            }
          ]
        },
        {
          "section": "Rear Window",
          "values": [
            {
              "value": "Closed",
              "status": 0
            }
          ]
        },
        {
          "section": "Window",
          "values": [
            {
              "value": "Closed",
              "status": 0
            }
          ]
        }
      ]
    },
    {
      "category": "Passenger Side",
      "displayOrder": 2,
      "sections": [
        {
          "section": "Door",
          "values": [
            {
              "value": "Closed",
              "status": 0
            },
            {
              "value": "Locked",
              "status": 0
            }
          ]
        },
        {
          "section": "Rear Door",
          "values": [
            {
              "value": "Closed",
              "status": 0
            },
            {
              "value": "Locked",
              "status": 0
            }
          ]
        },
        {
          "section": "Rear Window",
          "values": [
            {
              "value": "Closed",
              "status": 0
            }
          ]
        },
        {
          "section": "Window",
          "values": [
            {
              "value": "Closed",
              "status": 0
            }
          ]
        }
      ]
    },
    {
      "category": "Other",
      "displayOrder": 3,
      "sections": [
        {
          "section": "Hatch",
          "values": [
            {
              "value": "Closed",
              "status": 0
            },
            {
              "value": "Locked",
              "status": 0
            }
          ]
        },
        {
          "section": "Hood",
          "values": [
            {
              "value": "Closed",
              "status": 0
            }
          ]
        },
        {
          "section": "Moonroof",
          "values": [
            {
              "value": "Closed",
              "status": 0
            }
          ]
        }
      ]
    },
    {
      "category": "Trip Details",
      "displayOrder": 4,
      "sections": [
        {
          "section": "Trip A",
          "values": [
            {
              "value": "8457.0 miles",
              "status": 0
            }
          ]
        },
        {
          "section": "Trip B",
          "values": [
            {
              "value": "9359.1 miles",
              "status": 0
            }
          ]
        }
      ]
    }
  ],
  "telemetry": {
    "fugage": {
      "value": 84.0,
      "unit": "%"
    },
    "rage": {
      "value": 369.0,
      "unit": "Mile"
    },
    "odo": {
      "value": 9359.0,
      "unit": "Mile"
    }
  },
  "occurrenceDate": "2022-02-07T14:40:21Z",
  "cautionOverallCount": 0,
  "latitude": <REDACTED>,
  "longitude": <REDACTED>,
  "locationAcquisitionDatetime": "2022-02-07T14:27:09Z"
}

I have a 2021 Toyota RAV4 Prime PHEV and I would like to see battery charge status as well. How can I help you with this?

I just opened a PR to add support for EV details for toyota-na over at toyotha/toyota-na#28 ๐Ÿ˜„

Bah, it's gone due to DMCA :(

I found an (mod edit: snip) but it looks like it's from before your PR supporting EV details. Do you happen to still have a copy of the code?

Maybe someone could repost the project without the API key that got it killed.

I don't have a copy that's new enough myself, unfortunately. I'm going to edit your comment as well to remove the link. Don't want to risk this repo getting a DMCA.

Okay, here's a proof of concept to get charge details.

Add this to app.py: subparsers.add_parser("get_electric_status").add_argument("vin")

Add this to client.py:

async def get_electric_status(self, vin):
    return await self.api_get(
        "v2/electric/status", {"VIN": vin}
    )

Call python -m toyota_na.app get_electric_status <vin>

Get a response like this:

{
  "returnCode": "000000",
  "positionInfo": {
    "acquisitionDatetime": "2023-07-05T16:05:50Z",
    "longitude": snip,
    "latitude": snip
  },
  "vehicleInfo": {
    "acquisitionDatetime": "2023-07-05T16:28:10Z",
    "remoteHvacInfo": {
      "remoteHvacMode": 0,
      "remoteHvacProhibitionSignal": 1,
      "temperaturelevel": 30,
      "settingTemperature": 69.0,
      "blowerStatus": 0,
      "frontDefoggerStatus": 0,
      "rearDefoggerStatus": 0,
      "frontSeatHeaterStatus": null,
      "rearSeatHeaterStatus": null,
      "steeringHeaterStatus": null,
      "latestAcStartTime": null,
      "temperatureDisplayFlag": null
    },
    "chargeInfo": {
      "plugStatus": 40,
      "plugInHistory": 32,
      "remainingChargeTime": 330,
      "evTravelableDistance": 50.0,
      "evTravelableDistanceSubtractionRate": 4,
      "evDistanceAC": 29.0,
      "evDistance": 31.0,
      "evDistanceUnit": "mi",
      "chargeRemainingAmount": 76,
      "chargeType": 15,
      "chargeWeek": 0,
      "chargeStartTime": "42:35",
      "chargeEndTime": "42:35",
      "connectorStatus": 4,
      "batteryPowerSupplyPossibleTime": 16383,
      "gasolinePowerSupplyPossibleTime": 1023,
      "fuelGage": 100,
      "fuelGageStatus": 1,
      "gasolineTravelableDistance": 473,
      "gasolineTravelableDistanceUnit": 2
    },
    "timerChargeInfo": null,
    "maxNoOfChargeSchedules": null,
    "solarPowerGenerationInfo": {
      "solarInfoAvailable": null,
      "solarCumulativeEvTravelableDistance": null,
      "solarCumulativePowerGeneration": null,
      "monthlySolarCumulativePowerGeneration": null
    },
    "odometerInformation": null,
    "driveMonitorDisplayRange": null
  }
}

I think evDistance is what most people are interested in here (i.e., 31 miles of charge). This is for a RAV4 Prime while being charged via the level 1 charger.

I've got this fully working now, with charge level and range showing up in Home Assistant ๐Ÿ˜

I'm not sure how to share it effectively though, since it requires a bit of work on the defunct toyota_na library.

I've got this fully working now, with charge level and range showing up in Home Assistant ๐Ÿ˜

I'm not sure how to share it effectively though, since it requires a bit of work on the defunct toyota_na library.

Any updates, or could you share this privately?

I've got this fully working now, with charge level and range showing up in Home Assistant ๐Ÿ˜

I'm not sure how to share it effectively though, since it requires a bit of work on the defunct toyota_na library.

Anyway you could share this privately? I sent you an email directly from your profile page.

You'll need to find a copy of the toyota-na library version 2.1.1. Apply the attached patch.
toyota-na.patch.txt

My connected services subscription expired shortly after my last post and I decided I'm tired of giving money to Toyota and deleted this integration. I don't recall what, if any, changes are necessary for ha-toyota-na. If I find any more information I'll post it.

Had hoped it'd work without connected services. Thanks for the heads up, also not one to give Toyota money for DLC.

I apologize for what may be a silly question... I have a copy of toyota-na from where I was experimenting after the OTP snafu, but I cannot figure out where on the HA installation I need to put it to make it available to the ha-toyota-na integration.

I'm completely stumped as to where HA is storing the toyota-na depedency for this integration. My /config/deps folder is empty, I tried searching using find, no luck. Any pointers on how you got this working in HA, @danepowell ? Many thanks.

I apologize for what may be a silly question... I have a copy of toyota-na from where I was experimenting after the OTP snafu, but I cannot figure out where on the HA installation I need to put it to make it available to the ha-toyota-na integration.

I'm completely stumped as to where HA is storing the toyota-na depedency for this integration. My /config/deps folder is empty, I tried searching using find, no luck. Any pointers on how you got this working in HA, @danepowell ? Many thanks.

I`m in the same page!

I was able to get this working on my instance.

image

I'm running the docker version of HA and the dependency is stored in /usr/local/lib/python3.12/site-packages/toyota_na/.

I started with the changes referenced in the patch posted by @danepowell , but made a few tweaks.

I changed client/py to make it work properly with non-electric vehicles as well. Without the if statement it was choking on my Sienna which sends a nearly empty JSON response when querying that API endpoint.

    async def get_electric_status(self, vin):
        electric_status = await self.api_get(
            "v2/electric/status", {"VIN": vin}
        )
        if "vehicleInfo" in electric_status:
            return electric_status

I made some changes in vehicle\base_vehicle.py to add range with and without AC, as well as the battery SOC.

    ChargeDistance = auto()
    ChargeDistanceAC = auto()
    ChargeLevel = auto()

I also needed to update vehicle/vehicle_generations/seventeen_cy_plus.py to parse the information properly.

        # electric_status
        electric_status = await self._client.get_electric_status(self.vin)
        if electric_status is not None:
            self._parse_electric_status(electric_status)
    def _parse_electric_status(self, electric_status: dict) -> None:
        self._features[VehicleFeatures.ChargeDistance] = ToyotaNumeric(electric_status["vehicleInfo"]["chargeInfo"]["evDistance"], electric_status["vehicleInfo"]["chargeInfo"]["evDistanceUnit"])
        self._features[VehicleFeatures.ChargeDistanceAC] = ToyotaNumeric(electric_status["vehicleInfo"]["chargeInfo"]["evDistanceAC"], electric_status["vehicleInfo"]["chargeInfo"]["evDistanceUnit"])
        self._features[VehicleFeatures.ChargeLevel] = ToyotaNumeric(electric_status["vehicleInfo"]["chargeInfo"]["chargeRemainingAmount"], "%")

Finally, I needed to patch const.py in ha-toyota-na to add the sensors to the HA integration.

    {
        "state_class": SensorStateClass.MEASUREMENT,
        "icon": "mdi:gauge",
        "feature": VehicleFeatures.ChargeDistance,
        "name": "EV Range",
        "unit": "MI_OR_KM",
    },
    {
        "state_class": SensorStateClass.MEASUREMENT,
        "icon": "mdi:gauge",
        "feature": VehicleFeatures.ChargeDistanceAC,
        "name": "EV Range AC",
        "unit": "MI_OR_KM",
    },
    {
        "state_class": SensorStateClass.MEASUREMENT,
        "icon": "mdi:gauge",
        "feature": VehicleFeatures.ChargeLevel,
        "name": "EV Battery Level",
        "unit": PERCENTAGE,
    },

I think that covers all of the changes I needed to make to get this working. I'd be happy to take another look if it seems I missed something.

Yeah, I eventually forked the projects and made similar changes to get charge range and plug status:
Screenshot 2024-07-02 at 9 51 10โ€ฏAM
It's a shame we can't publish these publicly without risking a takedown.

Yeah, I eventually forked the projects and made similar changes to get charge range and plug status: Screenshot 2024-07-02 at 9 51 10โ€ฏAM It's a shame we can't publish these publicly without risking a takedown.

What about making it public for just a few hours so I can download it ๐Ÿ˜‚

Yeah, I eventually forked the projects and made similar changes to get charge range and plug status: Screenshot 2024-07-02 at 9 51 10โ€ฏAM It's a shame we can't publish these publicly without risking a takedown.

can you share how your able to gain access to the depedency folder. My hass is install on VM (proxmox) and i can't find the depedency.

I didn't install it in the dependency folder (couldn't figure it out), instead installed it via HACS from a private repo.

... That is an bumper.

Anyone know where python dependencies are in a home assistant yellow installation? I couldn't find them :/

This worked great for me, got all the status. Just followed what was posted by PenitentTangent2401. For those not knowing how to get to the files, you need to install the Terminal & SSH add on, the advanced one, and disable protection. Then when you go to the Terminal you can issue the docker commands, so you will want to get into the container with something like "docker exec -it sh". Then you can get to the file location, update the python. Then outside of that, in the custom_components folder you will update your HA component, restart, and enjoy

what about if we're not running HA on docker but haos.

Same thing, inside haos is running docker inside it, in your HA instance just go to add ons, look for terminal & ssh, there will be 2, pick the advanced one, and then follow the steps above... to get your docker containerid once inside the non protected terminal type "docker ps" and you will see a list of containers, one will be the full HA container, it will have the version you are running on it, get that id and use it

thank for the tip. Alright i got in but haha don't know how to edit the files..

I did load nano package into SSH config and was able to use nano outside of the container.

You dont need sudo and use vi. So type "vi client.py", etc... you will need to read on how to use vi, it's not the most straight forward text editor if you don't know it

You dont need sudo and use vi. So type "vi client.py", etc... you will need to read on how to use vi, it's not the most straight forward text editor if you don't know it

Thank you SO MUCH.....Work like charm. Now need to dig around to see how to get the state charging, the cord plugin status and gas tank level.
image

Nice! I have the same one, 2024 RAV4 Prime! I wanted to look into adding a refresh service and getting the date last refresh for the slow to update locks and windows, same as in the Toyota app.

I wish a version of the main library could be put back in git without the API key or in a way that doesn't get it flagged so we could contribute

This is my card right now, I did groups for the windows and locks to create a single flag if anything was open

Screenshot_20240907_141110_Home Assistant

https://github.com/WJDDesigns/Ultra-Vehicle-Card

Here mine, first is small button card, double click to expand to detail card. Currently showing all four door (red) not lock, passenger door open and two front window is open (yellow).

image

image

Nice, I didn't see kw, parked status, or gallons on fuel? Are those just not mapped in the current HA component?

For kw and gal, i used a odb2 dongle to get the measurements when it s all top off. After that i just revise calculated back base on totoya component value. It all estimated.

As for GPS, i have a android ai box with home assistant app installed and a 4g sim inside. So i get the GPS off that device.

I modified this package to work so EV status comes back without having to do all the container and package updates. Those inside the containers all go ahead and break everything every time you update. I am adding a few more fields I see and then will make a PR. I didn't bring over anything bad, I did the same as the auth patch, so just monkey patching

I added support in #75

The latest version v2.4.0 adds electric vehicle status