Thanks for the update!
I can confirm the sensor “charging power” now works all the time. But I noticed the sensor has a value of -1 kW when not connected to a wallbox. The value is 0 kW when the car is connected but not charging and the value when charging is spot on with the value depicted in the Me-app.
Is that negative value when not charging and not being connected to a charger intended the be like that?
Hi @Thomas01 ,
current actual values are not available via the API but you can use the avarage values.
Power output since since start is the attribute “electricconsumptionstart” of the rangeelectric sensor. The average speed is available via the sensor “ID_average_speed_start”.
BR
Rene
Hi @M31Galaxy15287 ,
this is correct, whenever the API does not provide values, I use -1 as the initial default value for the charging power sensor. I decided to set this value to have a chance to react later on. Is this value a problem?
Yes, if using an utility meter to count the used energy… I would prefer to be 0
With the next release the default value is 0. The change is done in the master branch on github already, in case someone would like to test it.
And, can someone test if the missing unit at startup causing problems with the statistics? Background: I always use the reported unit from the API and as the API does not provide a value, I also don’t know the unit.
A Better Routeplanner with Home Assistant
Goal:
Supply (realtime) data to A Better Routeplanner (ABRP).
This task is has two big steps, which are
- Setup ABRP Live Data
- Push Data from HA to ABRP
In Detail, these are:
1.1. Get (user) Token for your car from ABRP
1.2. Obtain API key for ABR
2.1. Setup Automation to send a REST URL in regular intervals to ABRP
2.2. Construct the REST URL
2.3. Set up various sensor data for the REST URL
1.1/1.2 Get Token and API key from ABRP.
To get the user token for the car in ABRP, select the car, click on “Live data”, then on “Link Generic”. Note the Token.
To get the API key, send an email to [email protected] and request a “Telemetry-Only API key”. See also the API documentation under Iternio Telemetry API (via https://www.iternio.com/api “Telemetry API”).
For the HA stuff, we start from the end and move to the beginning.
Note: I have an EQS, hence a lot of my examples are named EQS. Feel free to substitute your own names. Also, I redacted my licence plate number in all the component names in HA, set all instances of "XXX"
to your car.
2.3. Set up Sensor Data
ABRP interprets negative power as charging the car, and positive power for driving. As the MercedesME API does not provide driving power, and only charging power in positive value, we need first to invert the charging power. Also ABRP expects status information (car is parked, car is charging, car is fast charging) as either 1 or 0, so we have to mangle these also.
sensor:
- platform: template
sensors:
eqs_power_abrp:
friendly_name: EQS Power for ABRP
icon_template: mdi:flash
value_template: >
{% if states('sensor.XXX_charging_power')|float(0) > 0 %}
{{states('sensor.XXX_charging_power')|float(0)*(-1)}}
{% else %}
0
{% endif %}
- platform: template
sensors:
eqs_is_charging:
friendly_name: EQS is charging
value_template: >
{% if state_attr('sensor.XXX_range_electric', 'chargingstatus') in ["0", "5", "6", "9", "10", "11"] %}
1
{% else %}
0
{% endif %}
- platform: template
sensors:
eqs_is_dc_charging:
friendly_name: EQS is DC charging
value_template: >
{% if state_attr('sensor.XXX_range_electric', 'chargingstatus') in ["6", "11"] %}
1
{% else %}
0
{% endif %}
- platform: template
sensors:
eqs_is_parking:
friendly_name: EQS is parking
icon_template: mdi:car-brake-parking
value_template: >
{% if is_state('binary_sensor.XXX_park_brake_status', "off") %}
0
{% else %}
1
{% endif %}
2.2. Construct the REST URL
Put your own token and API key in.
As we do not have the driving power available, I removed the power (and speed) parameter if the car is not charging. Under “car_model”, I do supply the car model again (don’t know if its necessary, as the token was already generated for a specific car in your ABRP account). To get the description of the car, send an API request of https://api.iternio.com/1/tlm/get_carmodels_list (no key or token required). You may also skip supplying the car model.
You could also check the proper construction of the url in HA under “Developer Tools” → “TEMPLATE”.
Copy everything in the url part (from "{% set token"
to and including "https://api.iternio.com/1/tlm..."
), paste it into the template editor, copy the result and paste it into your browser. Check the response, and if OK, check the ABRP website.
rest_command:
abrp:
url: >
{% set token = "TOKEN" %}
{% set api_key = "APIKEY" %}
{% set power = "" %}
{% if is_state('sensor.eqs_is_charging', "1") %}
{% set power = ", \"speed\":0, \"power\":"~states('sensor.eqs_power_abrp') %}
{% endif %}
https://api.iternio.com/1/tlm/send?token={{token}}&api_key={{api_key}}&tlm={"utc":{{utcnow().strftime("%s")}}, "soc":{{states('sensor.XXX_state_of_charge')}}{{power}}, "lat":{{state_attr('device_tracker.XXX_device_tracker','latitude')}}, "lon":{{state_attr('device_tracker.XXX_device_tracker','longitude')}}, "is_charging":{{states('sensor.eqs_is_charging')}}, "is_dcfc":{{states('sensor.eqs_is_dc_charging')}}, "is_parked":{{states('sensor.eqs_is_parking')}}, "heading":{{state_attr('device_tracker.XXX_device_tracker', 'positionHeading')}}, "odometer":{{states('sensor.XXX_odometer')}}, "est_battery_range":{{states('sensor.XXX_range_electric')}}, "car_model":"mercedes:eqs:22:108:rwd"}
method: POST
headers:
content_type: "charset=utf-8; application/x-www-form-urlencoded"
2.1. Setup Automation
Now that the REST command has been constructed, use an Automation to push regular updates of your car to ABRP.
Goal here:
If driving or charging, update ABRP every 5 seconds (as recommended by ABRP). Also continue updating every 5s up to 30s after parking (to accurately get the parked position and state). Start the 5s update shortly before driving (ie when the doors are unlocked).
And finally, if parked, update only every hour.
Some of these conditions may be redundant, haven’t cleaned them up yet, works fine for me.
alias: ABRP upload
description: Uploads EQS data to A Better Routeplanner
trigger:
- platform: time_pattern
seconds: /5
condition:
- condition: or
conditions:
- condition: template
value_template: "{{ now().minute == 27 and (28 < now().second < 33) }}"
- condition: numeric_state
entity_id: sensor.eqs_is_charging
above: "0"
- condition: numeric_state
entity_id: sensor.eqs_is_parking
below: "1"
- condition: not
conditions:
- condition: state
entity_id: sensor.eqs_is_parking
state: "1"
for:
hours: 0
minutes: 0
seconds: 30
- condition: numeric_state
entity_id: sensor.XXX_lock
above: "0"
attribute: doorLockStatusOverall
action:
- service: rest_command.abrp
data: {}
mode: single
And that should take care of an automated update of ABRP from HA.
Many thanks to Rene for the MercedesMe 2020 integration, that makes this all possible.
The integration stopped working this morning. It’s asking me to reconfigure. I delete the Cache file and when I enter my email address for the PIN it never gets sent. I tried it a few times. Any ideas?
Hi, what is your region? Are you on version 0.9.8 at minimum? What is the output of debug log? And did you startet the mobile app and checked the app?
Region: Europe (Ireland)
Version: 0.9.9
Mobile app is working fine
Let me check log
Hello, is there any news in this case? The integration no longer works for me either. I deleted my entry in the hope that I can relink it, but no email comes with the 6-digit code.
Hi, are you sure that you are running at least version 0.9.8 of this component? If yes, please open a new github issue and share as much as possible information including debug log and information about your environment. (Issues · ReneNulschDE/mbapi2020 · GitHub)
BR
Rene
same here :-(. v0.9.9
Same here…
Hi @jgriffin , Just to clarify what is your HA version and what is your HA installation method? (Supervised, HA-OS, Core, …)
Thx
Rene
PS: Looks like I found the reason. My HA-core acts differently then HA-OS, …
Hi @dirkcx ,
Just to clarify what is your HA version and what is your HA installation method? (Supervised, HA-OS, Core, …)
Thx
Rene
PS: Looks like I found the reason. My HA-core acts differently then HA-OS, …
Hi @AlexMPH,
Just to clarify what is your HA version and what is your HA installation method? (Supervised, HA-OS, Core, …)
Thx
Rene
PS: Looks like I found the reason. My HA-core acts differently then HA-OS, …
Hi @ReneNulschDE,
I am new to HA, using the latest version on Docker.
HACS:
Mercedes Me:
No Email received so far.
I am using the Mercedes Me App (iOS) since Nov 23 with the same Mailaddress
Hi @dirkcx ,
thx, can you share the docker image that you used Or feel free to open a new github issue with all the information under GitHub - ReneNulschDE/mbapi2020: Custom Component to integrate MercedesME devices into Home-Assistant
The forum is not good to discuss issues where multiple reasons could be the case.
Thx
Rene
Latest ha supervised on debian