The script xee.py
I use to get the Xee v4 location and vehicle data in json format is:
#!/usr/bin/env python3
import requests
import json
import yaml
from pathlib import Path
from os.path import join
url_status = "https://api.xee.com/v4/vehicles/{vehicle_id}/status"
TOKEN_YAML = join(str(Path.home()), ".homeassistant/secrets.yaml")
# Read parameters needed from file
with open(TOKEN_YAML, 'r') as stream:
try:
token_file_data = yaml.load(stream)
except yaml.YAMLError as exc:
print('YAML error: ', exc)
raise
except Exception as e:
print("Error reading secrets.yaml file: ", e)
raise
headers = {
'Authorization': token_file_data['xee_bearer_token'],
'Cache-Control': "no-cache",
}
resource = url_status.format(vehicle_id=token_file_data['xee_vehicle_id'])
response = requests.request("GET", resource, headers=headers)
if response.status_code == requests.codes.ok:
json_response = json.loads(response.text)
print(json.dumps(json_response))
else:
response.raise_for_status()
Then, the sensor is HA is configured like this:
- platform: command_line
name: car_status
json_attributes:
- signals
- location
- updatedAt
command: 'python3 ~/.homeassistant/scripts/xee.py'
value_template: 'OK'
And then following the guide from @vlaraort .
Javi_Jota
(Javi Jota)
March 6, 2020, 11:05am
22
but this no autoupdate token no?
tikismoke
(tikismoke)
April 17, 2020, 8:23am
23
Ok seems Xee have close or not make rework the V3 api server…
I have not the same value between the web apps my.xee and my xee2mqtt api v3 scripts.
Really need to switch to V4 but with an autoreload token like the Xee2mqtt plugin do.
tikismoke
(tikismoke)
April 22, 2020, 11:45am
24
Confirmes android apps switch to V4 api and no more data update to V3 anymore
tikismoke
(tikismoke)
April 26, 2020, 9:33pm
25
Found interesting things…
the Xee V4 Api looks like nearly the sames as withings with Oauth2.
Meanings we certainly could get a good start for python Xee V4 api from the https://pypi.org/project/withings-api/
In theory just to change url path and data needed.
tikismoke
(tikismoke)
April 30, 2020, 3:17pm
27
Hi all,
i’ve update the python xee sdk lib.
I also update my Xee2mqtt code so no more token problems.
When it expires it grab a new one automatically from refresh one’s.
All the explaination are in the Readme
Do not hesitate to ask, open ticket, PR etc.
Next step will be a complete hacs and hass compoents after that. (But it will take again a long time.)
Note also it makes a lot of print for the moment to debug…
1 Like
work fine!!!
i try integrate the map now
Map is too easy to need explanation
##########
- type: map
title: "Position Voiture"
aspect_ratio: 16:9
default_zoom: 14
entities:
- zone.home
- device_tracker.megane_location
- device_tracker.scenic_location
With device tracker:
device_tracker:
- platform: mqtt_json
devices:
megane_location: /XEE/13b8146a-dc20-4657-b1f8-af2a2d187ee8/location/
scenic_location: /XEE/539ae3b9-e854-48b6-afe6-0e5d43bae8cd/location/
tikismoke
(tikismoke)
May 10, 2020, 6:08pm
30
Just to say that ten days later the whole process still run and refresh token itself nicely.
Excepted computed_engine that do no more exist in my json response. But that’s an API issue not the process.
All good for now.
Someone have time to make it on hacs?
I’ve got lot to do on others integration (plcbus/Nespresso)
Javi_Jota
(Javi Jota)
May 21, 2020, 8:02am
31
is strange… this no work on my homeassitant… no create the device track…
maybe is a problem with my ha version…
Home Assistant 0.108.6
tikismoke
(tikismoke)
May 21, 2020, 8:24am
32
device_tracker:
- platform: mqtt_json
Plateform is not mqtt
Javi_Jota
(Javi Jota)
May 21, 2020, 8:25am
33
oh, this is a test… with mqtt_json no work…
tikismoke
(tikismoke)
May 21, 2020, 8:38am
34
And with / at the end of the path?
Javi_Jota
(Javi Jota)
May 21, 2020, 9:20am
35
yes!! this works now… thanks for the support!
tikismoke
(tikismoke)
May 21, 2020, 3:33pm
37
No problems.
What we need now is a full components.
tikismoke
(tikismoke)
May 21, 2020, 3:35pm
38
For maps you can add hours_to_show or something like this in some latest release.
Nice to see where car have been.
It seems the first attempt to run the xee2mqtt.py
script is trying to open a window browser. Does we need to run the script in a desktop computer? I have no X server and no brown in my home server.
tikismoke
(tikismoke)
June 14, 2020, 9:12am
40
You can just copy paste the URL in any browser. It’s need to made you connect to xee and will give you an auth code in exchange (to copy paste back in the console).
It’s only needed once to get the 1st token.