bimmerconnected / ha_custom_component

Home Assistant Custom Component of BMW Connected Drive
34 stars 13 forks source link

Charging time remaining incorrect value #12

Closed rhoddan closed 2 years ago

rhoddan commented 2 years ago

ECD29324-EE31-4ED5-9C8B-7EBBDEC52EDD

The charging time remaining seems to be incorrect. I guess max 45 minutes left

askthomas commented 2 years ago

it in minutes, but hows in hours

13.73 hours should be 137.3 minutes

rikroe commented 2 years ago

Just fixed AM/PM parsing coming of the charging end times, please try again with the newest custom component/library.

rhoddan commented 2 years ago

20211127.1 Still mismatch between BMW App and HA regarding end charging time remaining...

IMG_0155 IMG_0156

rikroe commented 2 years ago

I was thinking of maybe removing charging_time_remaining completely and just replacing it with charging_end_time. That could be easier to debug and produce less state changes in Home Assistant. If needed you still could calculate the remaining time using a simple sensor in HA.

rikroe commented 2 years ago

Please check the new sensor charging_end_time in the latest custom component. If you want to see the value returned by the BMW API, please also activate the charging_end_time_mybmw sensor from device settings in HA.

rhoddan commented 2 years ago

not sure if/how I need to activate the charging_end_time_mybmw?

IMG_0158 2021-12-05 22:39:23 ERROR (SyncWorker_2) [bimmer_connected.account] 401 Client Error: Unauthorized for url: https://cocoapi.bmwgroup.com/eadrax-vcs/v1/vehicles?apptimezone=60.0&appDateTime=1638736763.002946&tireGuardMode=ENABLED Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/bimmer_connected/account.py", line 300, in send_request response.raise_for_status() File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 953, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://cocoapi.bmwgroup.com/eadrax-vcs/v1/vehicles?apptimezone=60.0&appDateTime=1638736763.002946&tireGuardMode=ENABLED 2021-12-05 22:39:23 ERROR (SyncWorker_2) [custom_components.bmw_connected_drive] Could not connect to the BMW Connected Drive portal. The vehicle state could not be updated 2021-12-05 22:39:23 ERROR (SyncWorker_2) [custom_components.bmw_connected_drive] 401 Client Error: Unauthorized for url: https://cocoapi.bmwgroup.com/eadrax-vcs/v1/vehicles?apptimezone=60.0&appDateTime=1638736763.002946&tireGuardMode=ENABLED Traceback (most recent call last): File "/config/custom_components/bmw_connected_drive/init.py", line 321, in update self.account.update_vehicle_states() File "/usr/local/lib/python3.9/site-packages/bimmer_connected/account.py", line 412, in update_vehicle_states self._get_vehicles() File "/usr/local/lib/python3.9/site-packages/bimmer_connected/account.py", line 376, in _get_vehicles response = self.send_request( File "/usr/local/lib/python3.9/site-packages/bimmer_connected/account.py", line 303, in send_request raise ex File "/usr/local/lib/python3.9/site-packages/bimmer_connected/account.py", line 300, in send_request response.raise_for_status() File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 953, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://cocoapi.bmwgroup.com/eadrax-vcs/v1/vehicles?apptimezone=60.0&appDateTime=1638736763.002946&tireGuardMode=ENABLED

rikroe commented 2 years ago

Sorry, you were not able to. Check your entities list with the new custom component: https://github.com/bimmerconnected/ha_custom_component/releases/tag/20211207.1

rhoddan commented 2 years ago

IMG_0824 Skärmavbild 2021-12-09 kl  20 32 33

Why does it differ between HA (03:06AM) (updated via bmw_connected_drive.update_state service) and my My BMW App (23:20)? It's also 12h & 24h time format

rikroe commented 2 years ago

This is driving me nuts. I really think we're using the wrong endpoint here...

rikroe commented 2 years ago

Can you please do me a favor and edit /usr/local/lib/python3.9/site-packages/bimmer_connected/account.py L384 to the following:

                    "appDateTime": int(datetime.datetime.now().timestamp()*1000),

and test again?

The BMW API will always return 12h format, so we have to parse it.

If your charging_end_time sensor (not the _original one) shows Invalid timestamp (like in your screenshot above), can you please check the entity itself & if there are any logs why this is not working?

rhoddan commented 2 years ago

Can you please do me a favor and edit /usr/local/lib/python3.9/site-packages/bimmer_connected/account.py L384 to the following:

                    "appDateTime": int(datetime.datetime.now().timestamp()*1000),

and test again?

The BMW API will always return 12h format, so we have to parse it.

If your charging_end_time sensor (not the _original one) shows Invalid timestamp (like in your screenshot above), can you please check the entity itself & if there are any logs why this is not working? Skärmavbild 2021-12-10 kl  00 02 36

I'm running Home Assistant "Supervised" and not sure how to edit that file? The only files I can edit is as the attached.

rikroe commented 2 years ago

Can you please edit manifest.json and change the line with requirements to:

  "requirements": ["bimmer_connected==0.8.7.0b1"],

That should bring you up to the latest and just merged master branch.

EDIT: Updated to a pre-release version, as the git+ link doesn't seem to work.

rhoddan commented 2 years ago

Can you please edit manifest.json and change the line with requirements to:

  "requirements": ["bimmer_connected==0.8.7.0b1"],

Skärmavbild 2021-12-10 kl  23 28 07

That should bring you up to the latest and just merged master branch.

EDIT: Updated to a pre-release version, as the git+ link doesn't seem to work.

Thanks for all help and time. I edited the manifest.json (see attached) and then restarted HA I also tried to redownload but no new version available. Probably I'm missing a step?

rikroe commented 2 years ago

There is no new component available, so you should not see any upgrade notice in HA.

Please check with pip3 freeze if your are on the beta mentioned above and then have a look at the charging_end_time sensors and their values.

rikroe commented 2 years ago

Just looked through the PRs for HA 2021.12. It can be that charging_end_time only works (i.e. displays a timestamp in the UI) if you are already on 2021.12 (it was developed on the 2021.12 beta).

So if charging_end_time_original is close to the app (ignore 12h/24h), the new sensor should work with the new HA release.

rhoddan commented 2 years ago

Thanks for info. I will wait for 2021.12 and see if it works

rhoddan commented 2 years ago

Hi again, The released 2021.12 BMW version seems to work great! The only issue I can see is still the difference of remaining charge time IMG_0164 IMG_0165

Thanks for a fantastic work!

rikroe commented 2 years ago

This should finally be fixed with Home Assistant 2021.12.4.

Please uninstall the custom component again to be able to get updates with Home Assistant.

If new errors come up, please open new issues with the home-assistant/core or the bimmerconnected/bimmer_connected repositories.

rhoddan commented 2 years ago

Thanks - seems to work fine in 2021.12.4