This repository contains a collection of scripts (including the Home Assistant Custom Component) in order to collect data from the sensors of a Mercedes-Benz car using Mercedes me API.
- Own a Mercedes Benz Car with Mercedes me installed and working.
- Create an application in https://developer.mercedes-benz.com/
- Register to the following APIs (all of them):
Notes:
- the APIs described above do not require any subscription in case you use them with your own car associated with the Mercedes me Account.
- not all sensors may be available in your own car; if a sensor is not available the data request returns no data.
- only one car is supported for the moment.
The Home Assistant Custom Component is a component to be added in Home Assistant in order to integrate the sensors of a Mercedes-Benz car using Mercedes me API. This component is still in development.
- Complete OAUTH2 Authentication & Get the First Token
- Get state after starts -> now it waits <scan_interval> seconds.
- Config Flow for automatic configuration
- Log Management
- Bugfix & Software optimizations
For further details please refer to issues list.
To use this custom component it's necessary to perform the following instructions:
- clone the repository
- create make a symbolic link from git_repost/custom_components/mercedesmeapi to hass_folder/custom_components
- Add in the configuration.yaml the following emelents:
mercedesmeapi:
client_id: <**INSERT_YOUR_CLIENT_ID**>
client_secret: <**INSERT_YOUR_CLIENT_SECRET**>
vehicle_id: <**INSERT_YOUR_VEHICLE_ID**>
enable_resources_file: <**ENABLE (true) OR DISABLE (false) RESOURCES - OPTIONAL (DEFAULT DISABLED)**>
scan_interval: <** TIME PERIOD (NUMBER OF SECONDS) TO REFRESH RESOURCES - OPTIONAL**>
- Actually it's not possible to retrieve the token from scratch. Please use the other scripts to retrieve the first token and copy it (.mercedesme_token) into the homeassistant configuration folder, in the same path where configuration.yaml is located
To enable advanced log please expand the logger module configuration with the following lines:
logger:
logs:
custom_components.mercedesmeapi: debug
There are two shell script:
- Python Version
- Bash Version The installation is the same, the usage is different.
To use this script it's necessary to perform the following instructions:
- clone the repository
- create a config file (.mercedesme_config) with:
CLIENT_ID=<**INSERT_YOUR_CLIENT_ID**>
CLIENT_SECRET=<**INSERT_YOUR_CLIENT_SECRET**>
VEHICLE_ID=<**INSERT_YOUR_VEHICLE_ID**>
ENABLE_RESOURCES_FILE: <**ENABLE (true) OR DISABLE (false) RESOURCES - (DEFAULT DISABLED)**>
where CLIENT_ID and CLIENT_SECRET referring to the application information that can be found in Mercedes Developer Console and VEHICLE_ID is the VIN of your car.
To create the first token it's necessary to perform the following steps:
- Create the APP and register it to all APIs as describe in the Pre-Requirements paragraph
- Logout in all browser from Mercedes Me (Developer site included)
- Execute the shell or python script with -t parameter to obrain the first token
- Open with a browser the link provided by the script: a login page will be shown
- Using your Mercedes Me credential log in: a new web-page will ask to authorize the APP created in the step 1 to access to the personal information associated to the APIs registered
- Enable all information and press Allow
- An error page will appear: check the URI: it's something like https://localhost/?code=DQ8htZSw4WtJ27r7sTrVJwszGWxrCx9emy5FDUFa
- Copy the part of the URI after code= (in this case DQ8htZSw4WtJ27r7sTrVJwszGWxrCx9emy5FDUFa) and paste into the running script
To execute the script read below:
usage: mercedes_me_api.py [-h] [-t] [-r] [-s] [-R] [-v]
optional arguments:
-h, --help show this help message and exit
-t, --token Procedure to obtatin the Access Token
-r, --refresh Procedure to refresh the Access Token
-s, --status Retrive the Status of your Vehicle
-R, --resources Retrive the list of available resources of your Vehicle
-v, --version show program's version number and exit
To execute the script read below:
Usage: mercedes_me_api.sh <arguments>
Example: mercedes_me_api.sh --token --fuel
or: mercedes_me_api.sh -l
Arguments:
-t, --token Procedure to obtatin the Access Token (stored into .mercedesme_token)
-r, --refresh Procedure to refresh the Access Token (stored into .mercedesme_token)
-f, --fuel Retrieve the Fuel Status of your Vehicle
-l, --lock Retrieve the Lock Status of your Vehicle
-s, --status Retrieve the General Status of your Vehicle
-e, --electric-status Retrieve the General Electric Status of your Vehicle
-o, --odometer Retrieve the Odometer reading of your Vehicle
-R, --resources Retrieve the list of available resources of your Vehicle
You can find change log under releases
MIT © Giorgio Ravera