Renault ZOE, My Renault and My ZE Online

The PR is merged.

It looks like you know what you’re talking about :slight_smile: Would there be a way to explain to an amateur how I go about (whilst following the instructions from pyze form @jamesremuscat
jamesremuscat a) getting my 2 API keys, b) and then configure pyze?

I tried to understand the instructions provided on the original blog post at the bottom of the github, but this is way beyond my level


Would like to extract data from my Zoe like you do :stuck_out_tongue:

I’m more a power user than a master of the work/code done. It’s @epenet the dev of this integration.
Why do you want your keys ? The Home Assistant module is doing it for you. Or perhaps you want to do it out of HA ?

Alright, let me re-formulate my question in this case: I have tested the custome component from @epenet with 2 different versions of homeassistant (v0.89.2 and v0.99.3). Each time I’m getting this error message and I wonder if I have simply not configured it correctly or if I’m supposed to do anything particular related to the pyze module:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/home/hass/homeassistant/custom_components/renaultze/sensor.py", line 68, in async_setup_platform
    g = Gigya(api_key=g_key,root_url=g_url)
  File "/srv/homeassistant/lib/python3.6/site-packages/pyze/api/gigya.py", line 23, in __init__
    self.set_api_key(api_key)
  File "/srv/homeassistant/lib/python3.6/site-packages/pyze/api/gigya.py", line 26, in set_api_key
    self._credentials.store('gigya-api-key', api_key, None)
  File "/srv/homeassistant/lib/python3.6/site-packages/pyze/api/credentials.py", line 70, in store
    self._write()
  File "/srv/homeassistant/lib/python3.6/site-packages/pyze/api/credentials.py", line 75, in _write
    os.makedirs(dirname)
  File "/srv/homeassistant/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/.credentials'

One thing to note, I have installed homeassistant within a virtual environment and the pyze module wasn’t installed automatically. That’s why I installed pyze manually (with pip install pyze).

As it’s a “permission denied” error, I have checked if my hass user owns all files (yes). No idea where this error comes from. Any help would be appreciated


P.S.: I could theoretically be that my car hasn’t yet been officially “migrated” to the new management platform (and thus the new API). Would that explain the errors???

I don’t think it’s an install error. According to my knowledge you even don’t need to install pyze. HA should install it dynamically the first time you launch with the custom.

First can you try to connect using the new official app? If it doesn’t work you won’t be able to get your car information they this custom component.

Hi markus,

I think the issue is due to the way the pyze module caches the credentials.
You need to give hass user access to the following path:
os.path.expanduser('~/.credentials/pyze.json')

Hi @epenet and @oncleben31!

To answer your questions: Yes, I can connect to the my renault app and it gives me some (basic) car information. I cannot however initiate charges, etc. which leads me to the idea that I’m still in a pre-migration mode and therefore not officially “empowered” by Renault to use this app. This could - in my humble opinion - be the reason why my credentials are somehow not correctly allocated.

So there’s 2 questions left to me.

  1. as pointed out by @ oncleben31: why does my homeassistant not load the pyze module automatically? (This might be one potential source for errors)
  2. regarding the access rights, both my homeassistant directory as well as the home directory for user “hass” (who is the owner of homeassistant) are mapped correctly to hass:hass. Why the f&x( does pyze not create the directory and gives me a permission error. Could it be that the pyze owner (I installed it out of the same virtualenv with user hass) cannot access this folder? How can I verify who’s the pyze default owner?

Hi @mastermarkush,

Did you check if there was a directory “/home/hass/.credentials/” ?

no, this directory has not been created automatically. I created it manually. The same error as described above after restart.

I appreciate your help, however I can’t help myself in thinking that the manual installation of pyze is the root cause of this error. Any other ideas?

Everything points to permission issues (not an issue with pyze or hassRenaultZE).
Maybe your Home Assistant setup is corrupted.

Since you installed the pyze module manually, have you tried to run the pyze CLI at the console prompt?

First, you open the JSON from Amazon, based on your location (this is for France).
https://renault-wrd-prod-1-euw1-myrapp-one.s3-eu-west-1.amazonaws.com/configuration/android/config_fr_FR.json
Then you make a note of the API keys: [‘servers’][‘gigyaProd’][‘apikey’] for Gigya, and [‘servers’][‘wiredProd’][‘apikey’] for Kamereon.

Then you run these four commands in the console prompt.
$ export GIGYA_API_KEY=XXXXXXXX
$ export KAMEREON_API_KEY=YYYYYYYY
$ pyze login
$ pyze status

Does anyone have this custom component working in hass.io ? I’ve just tried and I’m getting a similar pyze error:

Error while setting up platform renaultze
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/renaultze/sensor.py", line 71, in async_setup_platform
    g.account_info()
  File "/usr/local/lib/python3.7/site-packages/pyze/api/credentials.py", line 20, in inner
    raise MissingCredentialException(name)
pyze.api.credentials.MissingCredentialException: gigya

All I did was create the renaultze folder in the custom_components with the 3 files and put the -platform renaultze sensor in my configuration.yaml, I naiively assumed pyze would get installed and any credentials needed would be created


Have you something like that in your configuration ?

sensor: 
  - platform: renaultze
    name: Zoé
    username: !secret renaultzoe_login
    password: !secret renaultzoe_password
    vin: !secret renaultzoe_vin

Yes, exactly that, along with:

    android_lng: en_GB

but I think it is failing before reading any of that as it tries to setup the custom component and fails on the pyze missing credential.

and the other weird thing: I just ssh’ed in to hass.io and most of the paths in the error are empty: /usr/local/src doesn’t exist and /usr/local/lib is empty


I’m not sure you can view the source by ssh in hass.io. It’s possible but not standard.
And according to the log of the error there is an exception within the pyze code. It means it’s installed and interpreted. I think we will need @epenet to understand this one.

Hi,

According to the traceback, pyze is installed correctly - so no problem there.

The error “MissingCredentialException: gigya” indicates that it failed to generate a valid token in the previous phase (g.login(), which comes before g.account_info()).

I think the most likely issue is incorrect credentials (bad username/password).

There is a PR on Pyze to be able to trace errors.

@blaine I have pushed an update to Github, in the Develop Branch.

I have tweaked the initialisation routine to clear the cached credentials, and raise an error if the login fails.

I remember having mixing login and password between old and new applications. I hope you have checked the login/password you have put in HA are working directly in the web application. If not, start here :wink:

Thanks @epenet for the super speed response! I tried this and now I get a login failure:

Error while setting up platform renaultze
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/renaultze/sensor.py", line 74, in async_setup_platform
    raise RenaultZEError("Login failed")
custom_components.renaultze.sensor.RenaultZEError: Login failed

Thanks for the reminder @oncleben31, I triple checked my username password and vin in the secrets.yaml and they match exactly with the details I have in my iOS Renault ZE Services app which continues to work.

Any other suggestions of things to try?

Thanks for the confirmation - I’ve now merged my dev updates into master branch.

Regarding your login issue, I guess it now moves into Pyze territory.
You should download the latest code from jamesremuscat, and try the API directly.
Remember to get the API keys from https://renault-wrd-prod-1-euw1-myrapp-one.s3-eu-west-1.amazonaws.com/configuration/android/config_en_GB.json.

from pyze.api import Gigya, Kamereon, Vehicle, CredentialStore

cred = CredentialStore()
cred.clear()

g_url = xxx #jsonresponse['servers']['gigyaProd']['target']
g_key = xxx #jsonresponse['servers']['gigyaProd']['apikey']
g = Gigya(api_key=g_key,root_url=g_url)
g.login('email', 'password')  # You should only need to do this once
g.account_info()  # Retrieves and caches person ID

k_url = yyy #jsonresponse['servers']['wiredProd']['target']
k_key = yyy #jsonresponse['servers']['wiredProd']['apikey']
k = Kamereon(api_key=k_key,root_url=k_url,gigya=g)  # Gigya argument is optional - if not supplied it will create one

v = Vehicle('YOUR_VIN', k)  # Kamereon argument is likewise optional

v.battery_status()