Xee integration

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.

but this no autoupdate token no?

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.

Confirmes android apps switch to V4 api and no more data update to V3 anymore :frowning:

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.

that’s interesting …

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!!!

image

i try integrate the map now

Map is too easy to need explanation :slight_smile:

##########
  - 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/

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) :frowning:

is strange… this no work on my homeassitant… no create the device track…
image
image

maybe is a problem with my ha version…

Home Assistant 0.108.6

device_tracker:
  - platform: mqtt_json

Plateform is not mqtt

oh, this is a test… with mqtt_json no work…

And with / at the end of the path?

yes!! this works now… thanks for the support!


fantastic!!

No problems.

What we need now is a full components.

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.

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.