Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mixed units of measurement #56

Closed
homonto opened this issue Sep 13, 2021 · 63 comments · Fixed by #59
Closed

mixed units of measurement #56

homonto opened this issue Sep 13, 2021 · 63 comments · Fixed by #59
Labels

Comments

@homonto
Copy link

homonto commented Sep 13, 2021

Describe the bug
the attributes of the sensors have mixed up units: miles and km - I have RAV4 registered in UK (so Europe)
setup of my toyota is in miles
but the sensors from this integration are mixed up - sometimes km sometimes miles

To Reproduce
check the sensor: sensor.rav4_YOUR-PLATE_current_year_statistics

1: the sensor output is: amount of km in current year but the unit of measurements is "mi" - so wrong

2: some attributes are in miles some in km
example:
Average_fuel_consumed: 5.40 - that is in liters/100km
but another one is in miles:
Max_speed: 135 - that is in miles/h
unit_of_measurement: mi - miles
Average_speed: 26.4 - miles

Expected behaviour
the sensors should be consistent and either all in miles or all in km
I checked with MyToyota web page - all there is correct - in miles
Screenshot 2021-09-13 at 22 27 07
Screenshot 2021-09-13 at 22 31 58

@DurgNomis-drol
Copy link
Owner

Thanks for the feedback.

This a weird bug. I don't manipulate the statistics data, so what you see in the statistic sensor is the raw data from Toyota. But i will take a look at it in the next couple of days and see if I can figure something out, because it shouldn't be mixed like this.

@homonto
Copy link
Author

homonto commented Sep 14, 2021

I was 100% sure you take the data from MyT but again: I checked on their www and it shows EVERYTHING in miles.
So it is possible they have a mess there ;-)

@DurgNomis-drol
Copy link
Owner

I have thought about it and I think i have a solution, but i need to implement it in the python modul, so it is gonna take a couple of days.

And yes, Toyota's API is a bit strange, lets just say that. 😂

@homonto
Copy link
Author

homonto commented Sep 14, 2021

I have thought about it and I think i have a solution, but i need to implement it in the python modul, so it is gonna take a couple of days.

And yes, Toyota's API is a bit strange, lets just say that. 😂

I have all the time :-)
Ping when ready to be tested please - thank you

@DurgNomis-drol
Copy link
Owner

DurgNomis-drol commented Sep 14, 2021

Looking through the code, it seems that both average speed and max speed should also be in km/h, can you double check these for me? So i can be sure want I a can trust from Toyota and want not to trust 😅

@homonto
Copy link
Author

homonto commented Sep 14, 2021

average speed and max speed: both are for sure in mph
I am sure I tried if my car can do > 200km/h that is around 134mph ;-)
see what mytoyota says on both occasions:
on top they say: your max was 84mph
on the chart it shows 135mph
same for average: text is different from the chart
total mess

Screenshot 2021-09-14 at 14 55 15
Screenshot 2021-09-14 at 14 57 06

@DurgNomis-drol
Copy link
Owner

🤣 🤣

@DurgNomis-drol
Copy link
Owner

Do you want average fuel consumed to be in MPG instead of l/100 miles? Are this the norm in England?

@homonto
Copy link
Author

homonto commented Sep 14, 2021

I don't care - I am NOT a Brit although living here
l/100km is ok for me ;-)
mpg is ok for me
as long as all is consistent I think - read: the same units ;-)
of course, if the add-on can have BOTH... am I dreaming? ;-)

@homonto
Copy link
Author

homonto commented Sep 14, 2021

see "where" I am today with the mix:

Screenshot 2021-09-14 at 15 40 46

@DurgNomis-drol
Copy link
Owner

I have now implemented both in the underlying module. I gonna make it default to mpg when the car is using the imperial system (As i believe this is the norm in countries that uses imperial system), with an option to use L/100 miles. How does that sound?

And MPG is of course in UK gallons 😄

@homonto
Copy link
Author

homonto commented Sep 14, 2021

it makes sense completely
yes, use UK gallons please - not US ;-)
this country here (UK) is completely upside down: signs on the roads: miles, petrol stations: litres, consumption: mpg, price per litres ... I am not going to tell you more ;-)

@DurgNomis-drol
Copy link
Owner

Can you please test this branch? #59 And report back over there 😃

@homonto
Copy link
Author

homonto commented Sep 15, 2021

can you help me please? how to install the new branch?

@DurgNomis-drol
Copy link
Owner

DurgNomis-drol commented Sep 15, 2021

https://github.com/DurgNomis-drol/ha_toyota/tree/bugfix

Click this link and press the button called Code, and a dropdown opens up. Choose Download zip.

Extract the zip's content and copy the the folder toyota in the folder custom_components into your custom_components folder. It is gonna ask you to overwrite the other toyota folder installed through HACS. After that you just restart Home-assistant as you would normally when you have installed a custom component. 😃 For more info see this part of the readme.

@homonto
Copy link
Author

homonto commented Sep 15, 2021

no change at all - I downloaded, removed old folder, copied new etc
see the results please
maybe I did something wrong?
still some things in miles (ODO), some in km (current year)
Screenshot 2021-09-15 at 11 29 26
Screenshot 2021-09-15 at 11 30 22

@DurgNomis-drol
Copy link
Owner

Can you try again, I believe I just fixed bug you were encountering 😃

@homonto
Copy link
Author

homonto commented Sep 15, 2021

you mean: repeat again the download?

@DurgNomis-drol
Copy link
Owner

Yes

@homonto
Copy link
Author

homonto commented Sep 15, 2021

done
believe me: same same
do you need another screenshot? ;-)
this time with blue

Screenshot 2021-09-15 at 12 09 04

@DurgNomis-drol
Copy link
Owner

Are you sure you you are downloading this branch and not the master? Because it works on my end when i am testing it 🤔

@homonto
Copy link
Author

homonto commented Sep 15, 2021

Screenshot 2021-09-15 at 12 17 41
Screenshot 2021-09-15 at 12 18 17

@DurgNomis-drol
Copy link
Owner

It is the rights files. I not sure why i does not work

@homonto
Copy link
Author

homonto commented Sep 15, 2021

do we have to wait for new pull from MyT?

@DurgNomis-drol
Copy link
Owner

DurgNomis-drol commented Sep 15, 2021

No, as all the conversion is done in underlying module on the fly. And after you restart when you have installed the new version, it will pull data again (And this time converting it).

Can you please try to download from this again. I just pushed an update that will enable better debugging.

You need to enable the debugging by adding this to your configuration,yaml:

logger:
  default: info
  logs:
     custom_components.toyota: debug
     mytoyota: debug

After this please post the logs only relevant to this integration from the log file 😃

@homonto
Copy link
Author

homonto commented Sep 15, 2021

this time green, ok? ;-)
Screenshot 2021-09-15 at 12 52 29

@homonto
Copy link
Author

homonto commented Sep 15, 2021

see below (now orange) but I doubt some data is ok: 84 mpg (UK) = 3.36 l/100km - it should be around 5.4-5.6l/100km (as per simple calculation how many litres I fuelled / by km done, also the previous version of your add-on showed 5.4)
https://www.calculateme.com/gas-mileage/liters-per-100-km-to-british-mpg
you can see my all data also on this picture where I note each fuelling:
Screenshot 2021-09-15 at 13 46 51

Screenshot 2021-09-15 at 13 35 41
Screenshot 2021-09-15 at 13 36 47

toyota.log

@DurgNomis-drol
Copy link
Owner

It defaults to MPG and not L/100 miles. You can change this by going to Settings -> Integrations and then press Configure under the integration.

@homonto
Copy link
Author

homonto commented Sep 15, 2021

that is ok, let it be MPG but 5.5l/100km is for sure NOT 84mpg but around 52mpg
let me check it again

@DurgNomis-drol
Copy link
Owner

Yeah something is wrong with that conversion.

Can you confirm it is the only thing not showing correctly?

@homonto
Copy link
Author

homonto commented Sep 15, 2021

no, not only

  1. when I use config L/100km it shows correctly the consumption (from 4.9l/100km weekly to 5.4l/100km yearly - I consider this ok as in the summer consumption is lower). but, everything else is in miles - I think (loudly) that the addon should either use everything in miles/gallons or everything in litters/km - for sure not mixed up - what do you think?

Screenshot 2021-09-15 at 14 06 57
Screenshot 2021-09-15 at 14 07 18

  1. when I use config MPG then all is in miles - that is OK I think, but MPG is out of the sky (too high)
    Screenshot 2021-09-15 at 14 10 26

@DurgNomis-drol
Copy link
Owner

DurgNomis-drol commented Sep 15, 2021

First of all, i not trying to mix them. I am trying to correct this issue.

Secondly, everything is shown correctly for you vehicle except the average consumption attribute. The car denotes want you are gonna see. My car reports in km and therefor this integration show my data in km/L. Your car reports mi and therefor this integration show your data in miles/gallons(UK), you also have the option to show it in miles/liters.

To shorten this, it works correctly when in L/100 miles. For you it is NOT in L/100 km.

WHY the average consumption is wrong when using MPG I don't know right now.

@homonto
Copy link
Author

homonto commented Sep 15, 2021

fine, let it be - I will stay with l/100km
just a question: which number do you get from MyToyota for consumption: 5.4l/100km or 84mpg? I am talking RAW data from MyToyota

@DurgNomis-drol
Copy link
Owner

I don't get anything for my car model, there for your help is need to implement this.

But if you are willing to run a script we can test the mytoyota package as all the conversion is done there.

@homonto
Copy link
Author

homonto commented Sep 15, 2021

I am willing to help and contribute ;-)
Provided you will tell me what to do

@DurgNomis-drol
Copy link
Owner

Create a file called test.py Open the file a paste the below inside and fill in username and password

import json
import asyncio
from mytoyota.client import MyT

username = "jane@doe.com"
password = "MyPassword"

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


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

    print("Retrieving cars...")
    cars = await client.get_vehicles()

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

        statistics = await  client.get_driving_statistics(vehicle.vin)

        print(json.dumps(statistics, indent=3))

        statistics_imp = await  client.get_driving_statistics(vehicle.vin, unit="imperial")

        print(json.dumps(statistics_imp, indent=3))

        statistics_mpg = await  client.get_driving_statistics(vehicle.vin, unit="imperial_mpg")

        print(json.dumps(statistics_mpg, indent=3))


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

Run the file like this in a terminal python3 test.py and post the out put here. Remember to censor the output for private information. 😃

@homonto
Copy link
Author

homonto commented Sep 15, 2021

that was fast:
➜ tmp python3 test.py
Traceback (most recent call last):
File "/config/tmp/test.py", line 3, in
from mytoyota.client import MyT
ModuleNotFoundError: No module named 'mytoyota'

@DurgNomis-drol
Copy link
Owner

You need to install the mytoyota module through pip like this pip3 install mytoyota==0.6.0

@homonto
Copy link
Author

homonto commented Sep 15, 2021

no private data in the output I think:

python3_test.py.log

@DurgNomis-drol
Copy link
Owner

I have found the problem i believe. I will need you to test it when i made a fix 😃

@homonto
Copy link
Author

homonto commented Sep 15, 2021

I am just around the corner ;-)

@DurgNomis-drol
Copy link
Owner

Please update the module like this pip3 install mytoyota==0.6.1 and then run the script again and post it 😃

If it errors out when updating, wait a few minutes and try again.

@homonto
Copy link
Author

homonto commented Sep 15, 2021

python3_test.py.log

@DurgNomis-drol
Copy link
Owner

I forgot, you all so have to change imperial_mpg to imperial_liters in test.py

@DurgNomis-drol
Copy link
Owner

Can i get you to do it again doing the following?

I forgot, you all so have to change imperial_mpg to imperial_liters in test.py

@homonto
Copy link
Author

homonto commented Sep 15, 2021

here you are:
python3_test.py.log

@DurgNomis-drol
Copy link
Owner

It should be working now. I have pushed an update to https://github.com/DurgNomis-drol/ha_toyota/tree/bugfix and it should now be working, please report back

@homonto
Copy link
Author

homonto commented Sep 15, 2021

Hmm, now is total mix - I tried to put all findings on 2 pictures: 1st when set l/100km and 2nd when mpg
have a look - the second one is with less errors, the first one with more errors
Screenshot 2021-09-15 at 16 24 41
Screenshot 2021-09-15 at 16 19 49

@homonto
Copy link
Author

homonto commented Sep 15, 2021

on 2nd: set to mpg - there is only 1 problem: consumption is in l/100km (all of them) - all distances are in miles - OK
on the 1st one: total mix of problems

@DurgNomis-drol
Copy link
Owner

DurgNomis-drol commented Sep 15, 2021

I just pushed a fix that should fix it

BUT you need to understand that it is not L/100 KM but L/100 MILES instead.

@homonto
Copy link
Author

homonto commented Sep 15, 2021

there is NO such measure in use as L/100 MILES
I have not heard about it at all
commonly used is mpg: miles per UK gallon
or - especially for "imported people" like me from mainland Europe: litres/100km

@DurgNomis-drol
Copy link
Owner

Use MPG then, there's is no sense in having L/100km if all the other measurements are in miles. This is not discussion. I have worked hard to implement this feature for you and I don't have any use for it personally.

Please test if the latest commit fixed your issue so I can meget this PR og fix the problem.

@homonto
Copy link
Author

homonto commented Sep 15, 2021

I am very grateful for your work ;-) thank you.
I just installed it and configured to use MPG - it makes sense to have all in the same units
I believe all is ok now - thank you again
Screenshot 2021-09-15 at 18 02 42

@DurgNomis-drol
Copy link
Owner

Thanks for testing. I will merge the PR and release a new version very soon to HACS.

Tip: If you still want L/100 km, you can make a template sensor that converts the value. 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants