Good morning Renè,
now it has authenticated and MercedesMe has communicated the code but neither the device nor the entities appear anymore
Did you reauthenticate via the integration page? There is no way without the reauthentication because the component lost the refresh_token.
Other option:
- delete the component via the integration page
- delete the file .Mercedes… in the HA config folder
- restart HA
- add the component again
Hi, @ReneNulschDE
I have uninstalled everything and installed again new version.
I can not see any problems in logs but we have to wait few hours.
Component works in Poland.
Thank You and regards
2 = plugged in not charging.
Hi @ReneNulschDE,
First of all, I’d like to thank you for your amazing work! I’m totally new on HA and your custom component was one of the reason why I’m now using HA.
FYI I’m in France, so you can add ‘FR’ on the list of the countries where your component works
Thanks again and best regards
@ReneNulschDE Great work! one of the easiest integrations I’ve dealt with so far.
My contribution to this thread, I’ve integrated a telegram bot into my system. Reason being - sometimes you’re on a train and want to do things, but not wait for an app to load to with cellular/mobile signal. So, why not ping a command across and it’ll get done when you are out of said tunnel.
I’ve got it to:
- list car stats (I’ve created some custom sensors to tell me window states & sunroof states- ie, open, closed, partially opened, venting, moving).
- Flash your lights (cause this was amusing - and not something the default app does)
- lock doors
- unlock doors (not sure this is a good idea)
- close windows
- close sunroof
- turn on climate control (pre-heating for winter… assume aircon for summer!?)
Code to get you going if you wanna - and don’t forget to replace sensors with your own. (ps, just worked out the plugged in status indicator - so this is wrong currently in the code below).
Merc menu
- alias: Telegram bot Merc menu command
id: telegram-merc-menu-cmd
trigger:
- event_type: telegram_callback
platform: event
event_data:
data: /merc
- event_type: telegram_command
platform: event
event_data:
command: /merc
action:
- service: telegram_bot.send_message
data_template:
target: '{{ trigger.event.data.user_id }}'
callback_query_id: '{{ trigger.event.data.id }}'
message: The Merc!
disable_notification: true
inline_keyboard:
- 🔋 Car stats:/mercstats, 🚘 Flash your lights:/mercshowpos
- 🔑 Lock doors:/merclock, 🔓 Unlock doors:/mercunlock
- 🪟 Close windows:/mercclosewindows, ☀️ Close sunroof:/mercclosesunroof
- 🌡️ Turn on climate control:/mercclimate, 🔌 Start charging:/merccharge
- 🔙 Back to options:/options
All the commands here:
- alias: Telegram Merc show position (flash lights)
initial_state: 'on'
id: telegram-Merc-flash-lights
trigger:
- event_type: telegram_callback
event_data:
data: /mercshowpos
platform: event
- event_type: telegram_command
event_data:
command: /mercshowpos
platform: event
action:
- service: telegram_bot.send_message
data_template:
inline_keyboard:
- 🔵 Show options:/options
- 🔙 Back to Merc menu:/merc
message: '{{ [ "**click**", "Lost your car? I will flash the lights for you.", "Should I be discreet about it? ", "🎶 Coming to the light 🎶", "I will do that for you." ] | random }} '
target: '{{ trigger.event.data.user_id }}'
callback_query_id: '{{ trigger.event.data.id }}'
title: 🚘 Flashing your car lights.
- service: mbapi2020.sigpos_start
data:
vin: !secret merc_vin
- alias: Telegram Merc lock doors
initial_state: 'on'
id: telegram-Merc-lock-doors
trigger:
- event_type: telegram_callback
event_data:
data: /merclock
platform: event
- event_type: telegram_command
event_data:
command: /merclock
platform: event
action:
- service: telegram_bot.send_message
data_template:
inline_keyboard:
- 🔵 Show options:/options
- 🔙 Back to Merc menu:/merc
message: '{{ [ "**thwack**", "Locked.", "Beep!", "🎶 Three, four, she locked the door!
🎶", "Lockin good." ] | random }}
'
target: '{{ trigger.event.data.user_id }}'
callback_query_id: '{{ trigger.event.data.id }}'
title: 🔑 Locking the Merc
- service: mbapi2020.doors_lock
data:
vin: !secret merc_vin
- alias: Telegram Merc unlock doors
initial_state: 'on'
id: telegram-Merc-unlock-doors
trigger:
- event_type: telegram_callback
event_data:
data: /mercunlock
platform: event
- event_type: telegram_command
event_data:
command: /mercunlock
platform: event
action:
- service: telegram_bot.send_message
data_template:
inline_keyboard:
- 🔵 Show options:/options
- 🔙 Back to Merc menu:/merc
message: '{{ [ "**thwack**", "Locked.", "Beep!", "🎶 Three, four, she locked the door!
🎶", "Lockin good." ] | random }}
'
target: '{{ trigger.event.data.user_id }}'
callback_query_id: '{{ trigger.event.data.id }}'
title: 🔓 Unlocking the Merc
- service: mbapi2020.doors_unlock
data:
vin: !secret merc_vin
- alias: Telegram Merc close sunroof
initial_state: 'on'
id: telegram-Merc-close-sunroof
trigger:
- event_type: telegram_callback
event_data:
data: /mercclosesunroof
platform: event
- event_type: telegram_command
event_data:
command: /mercclosesunroof
platform: event
action:
- service: telegram_bot.send_message
data_template:
inline_keyboard:
- 🔵 Show options:/options
- 🔙 Back to Merc menu:/merc
message: '{{ [ "**click**", "Closing the sunroof.", "wwhiiirrrrthup!", "🎶 Rain rain, go away, come again another day!
🎶", "On it." ] | random }}
'
target: '{{ trigger.event.data.user_id }}'
callback_query_id: '{{ trigger.event.data.id }}'
title: 🔌 Start charging the Merc
- service: mbapi2020.sunroof_close
data:
vin: !secret merc_vin #vinNumber
- alias: Telegram Merc close windows
initial_state: 'on'
id: telegram-Merc-close-windows
trigger:
- event_type: telegram_callback
event_data:
data: /mercclosewindows
platform: event
- event_type: telegram_command
event_data:
command: /mercclosewindows
platform: event
action:
- service: telegram_bot.send_message
data_template:
inline_keyboard:
- 🔵 Show options:/options
- 🔙 Back to Merc menu:/merc
message: '{{ [ "**click**", "Closing the windows.", "wwhiiirrrrthup!", "🎶 Close the window, calm the light. And it will be all right.
🎶", "I will jump right too it" ] | random }}
'
target: '{{ trigger.event.data.user_id }}'
callback_query_id: '{{ trigger.event.data.id }}'
title: 🔌 Start charging the Merc
- service: mbapi2020.windows_close
data:
vin: !secret merc_vin #vinNumber
- alias: Telegram Merc climate control toggle
initial_state: 'on'
id: telegram-Merc-climate-control-toggle
trigger:
- event_type: telegram_callback
event_data:
data: /mercclimate
platform: event
- event_type: telegram_command
event_data:
command: /mercclimate
platform: event
action:
- service: telegram_bot.send_message
data_template:
inline_keyboard:
- 🔵 Show options:/options
- 🔙 Back to Merc menu:/merc
message: '{{ [ "**click**", "Turning it on? Turning it off? You really should
create an on or off switch.", "Hot or cold?", "🎶 hot potato! 🎶", "No problemo."
] | random }}
'
target: '{{ trigger.event.data.user_id }}'
callback_query_id: '{{ trigger.event.data.id }}'
title: '🌡️ Turn on climate control: Toggled'
#- service: switch.toggle
# entity_id: switch.carplate_auxheat #try same service as close windows?
- service: mbapi2020.preheat_start
data:
vin: !secret merc_vin
- alias: Telegram Merc stats
initial_state: 'on'
id: telegram-merc-stats
trigger:
- event_type: telegram_callback
event_data:
data: /mercstats
platform: event
- event_type: telegram_command
event_data:
command: /mercstats
platform: event
action:
- service: telegram_bot.send_message
data_template:
inline_keyboard:
- 🔵 Show options:/options
- 🔙 Back to Merc menu:/merc
message: ' Last updated: {{state_attr("sensor.carplate_car", "last_message_received")}}
Locked? {{states("lock.carplate_lock")}}
Driver window? {{states("sensor.carplate_window_driver")}}
Passenger window? {{states("sensor.carplate_window_passenger")}}
Back left window? {{states("sensor.carplate_window_backleft")}}
Back right window? {{states("sensor.carplate_window_backright")}}
Sunroof? {{states("sensor.carplate_sunroof_state")}}
Pre-conditioning? {{states("switch.carplate_auxheat")}}
Is it on? {% set ignitionstatus = states("sensor.carplate_ignition_state") %} {% if ignitionstatus == "0" %} Ignition lock {% elif ignitionstatus == "1" %} Ignition off {% elif ignitionstatus == "2" %} Ignition accessory {% elif ignitionstatus == "3" %} 3 means something? {% elif ignitionstatus == "4" %} Ignition on {% elif ignitionstatus == "5" %} Ignition start {% endif %}
Plugged in? {{ states("") }}
Charging: {{ states("sensor.carplate_charging_power") }}
Battery is at {{ states("sensor.carplate_state_of_charge") }} %
Estimated range (with heating) {{ states("sensor.carplate_range_electric") }} miles.
Where it is at: {{ states("device_tracker.carplate_device_tracker") }}.
'
target: '{{ trigger.event.data.user_id }}'
callback_query_id: '{{ trigger.event.data.id }}'
title: 🔋 Car stats for the Nissan Merc
Hope this inspires/helps folks too.
Hi @Mobiledude,
Trying to replicate your (very nice looking!) card but since I’m a big noob in HA, I encounter some bugs…
Could you just tell me step by step, the files I have to edit or create and the exact code to put in please?
What I’ve done:
- uploaded the .png file into the folder /www
- copy your source code and changed the ID of my vehicule
3; edited the configuration.yaml file with the source code you gave on the 1. - restart HA
But I’ve this error in my configuration.yaml file:
Any idea?
SOLVED: I replaced platform: template
by platform: template:
Thanks for this! I’m going add in my tweaks - for window states, I’ve given human readable language to them rather than codes you have to memorise. I’m in the UK, so driver window is front right in my yaml. And a similar thing for the general lock status:
#sunroof
carPlate_sunroof_state:
#if window 1 then x if window 2 then y if window 3 then z
#Sunroof codes
# 0: Tilt/slide sunroof is closed
# 1: Tilt/slide sunroof is complete open
# 2: Lifting roof is open
# 3: Tilt/slide sunroof is running
# 4: Tilt/slide sunroof in anti-booming position
# 5: Sliding roof in intermediate position
# 6: Lifting roof in intermediate position
value_template: >
{% set sunroofstatus = state_attr("sensor.carPlate_lock", "sunroofstatus") %}
{% if sunroofstatus == "0" %} Closed
{% elif sunroofstatus == "1" %} Open
{% elif sunroofstatus == "2" %} Lifting roof open
{% elif sunroofstatus == "3" %} Currently moving
{% elif sunroofstatus == "4" %} Anti-booming position
{% elif sunroofstatus == "5" %} Partially open
{% elif sunroofstatus == "6" %} Partially tilted
{% endif %}
friendly_name: Sunroof (carPlate)
icon_template: >-
mdi:weather-sunny
#windows
#window - binary sensors: on means open, off means closed
#if window 1 then x if window 2 then y if window 3 then z
# Status of windows
# 0: window in intermediate position
# 1: window completely opened
# 2: window completely closed
# 3: window airing position
# 4: window intermediate airing position
# 5: window currently running
carPlate_window_driver:
#if window 1 then x if window 2 then y if window 3 then z
value_template: >
{% set windowstatus = state_attr("binary_sensor.carPlate_windows_closed", "windowstatusfrontright") %}
{% if windowstatus == "0" %} Partially open
{% elif windowstatus == "1" %} Open
{% elif windowstatus == "2" %} Closed
{% elif windowstatus == "3" %} Airing position
{% elif windowstatus == "4" %} Intermediate airing
{% elif windowstatus == "5" %} Currently moving
{% endif %}
friendly_name: Driver window (carPlate)
icon_template: >-
mdi:car-door
carPlate_window_passenger:
#if window 1 then x if window 2 then y if window 3 then z
value_template: >
{% set windowstatus = state_attr("binary_sensor.carPlate_windows_closed", "windowstatusfrontleft") %}
{% if windowstatus == "0" %} Partially open
{% elif windowstatus == "1" %} Open
{% elif windowstatus == "2" %} Closed
{% elif windowstatus == "3" %} Airing position
{% elif windowstatus == "4" %} Intermediate airing
{% elif windowstatus == "5" %} Currently moving
{% endif %}
friendly_name: Passenger window (carPlate)
icon_template: >-
mdi:car-door
carPlate_window_backleft:
#if window 1 then x if window 2 then y if window 3 then z
value_template: >
{% set windowstatus = state_attr("binary_sensor.carPlate_windows_closed", "windowstatusrearleft") %}
{% if windowstatus == "0" %} Partially open
{% elif windowstatus == "1" %} Open
{% elif windowstatus == "2" %} Closed
{% elif windowstatus == "3" %} Airing position
{% elif windowstatus == "4" %} Intermediate airing
{% elif windowstatus == "5" %} Currently moving
{% endif %}
friendly_name: Back-left window (carPlate)
icon_template: >-
mdi:car-door
carPlate_window_backright:
#if window 1 then x if window 2 then y if window 3 then z
value_template: >
{% set windowstatus = state_attr("binary_sensor.carPlate_windows_closed", "windowstatusrearright") %}
{% if windowstatus == "0" %} Partially open
{% elif windowstatus == "1" %} Open
{% elif windowstatus == "2" %} Closed
{% elif windowstatus == "3" %} Airing position
{% elif windowstatus == "4" %} Intermediate airing
{% elif windowstatus == "5" %} Currently moving
{% endif %}
friendly_name: Back-left window (carPlate)
icon_template: >-
mdi:car-door
#Locks - status codes:
# 0: vehicle unlocked
# 1: vehicle internal locked
# 2: vehicle external locked
# 3: vehicle selective unlocked
#lock: on means open (unlocked), off means closed (locked)
carPlate_lock_summary:
value_template: >-
{% set doorlockstatus = state_attr("sensor.carPlate_lock", "doorStatusOverall") %}
{% if doorlockstatus == "0" %} Unlocked
{% elif doorlockstatus == "1" %} Locked
{% elif doorlockstatus == "2" %} Externally locked
{% elif doorlockstatus == "3" %} Selectively unlocked
{% endif %}
friendly_name: Lock summary (carPlate)
icon_template: >-
mdi:lock
Enjoy
OK, I deleted and reinstalled your wonderful integration, thanks for your support, everything is back to working smoothly.
Your work is extraordinary.
I have updated mbapi2020 to v0.5.14 and reauthenticated, everything works again. Thank you!
You can add DK to the list of countries supported, I’ve been using your integration for a while and it works great.
One thing im struggling with is how to expose the state attributes:
I think I need to create a template for each of them, but the Docs don’t make much sense to me
EDIT
Trying to do this for the doors and windows, but the template always returns “Open” or “partly open”
Code for windows
- platform: template
sensors:
ls71ftt_window_rear_right_ownvalue:
value_template: >-
{% if is_state('states.binary_sensor.ls71ftt_windows_closed.attributes.windowstatusrearright', '2') %}
closed
{% elif is_state('states.binary_sensor.ls71ftt_windows_closed.attributes.windowstatusrearright', '1') %}
open
{% else %}
partly open
{% endif %}
friendly_name: 'LS71FTT Rear right window status (renamed)'
unit_of_measurement: ''
Code for Doors
# Door and trunk status with own values
- platform: template
sensors:
ls71ftt_door_front_right_ownvalue:
value_template: >-
{% if is_state('states.sensor.ls71ftt_lock.attributes.doorstatusfrontright', 'false') %}
closed
{% else %}
open
{% endif %}
friendly_name: 'LS71FTT closing status front right (renamed)'
unit_of_measurement: ''
- platform: template
sensors:
ls71ftt_door_front_left_ownvalue:
value_template: >-
{% if is_state('states.sensor.ls71ftt_lock.attributes.doorstatusfrontleft', 'false') %}
closed
{% else %}
open
{% endif %}
friendly_name: 'LS71FTT closing status front left (renamed)'
unit_of_measurement: ''
- platform: template
sensors:
ls71ftt_door_rear_right_ownvalue:
value_template: >-
{% if is_state('states.sensor.ls71ftt_lock.attributes.doorstatusrearright', 'false') %}
closed
{% else %}
open
{% endif %}
friendly_name: 'LS71FTT closing status rear right (renamed)'
unit_of_measurement: ''
- platform: template
sensors:
ls71ftt_door_rear_left_ownvalue:
value_template: >-
{% if is_state('states.sensor.ls71ftt_lock.attributes.doorstatusrearleft', 'false') %}
closed
{% else %}
open
{% endif %}
friendly_name: 'LS71FTT closing status rear left (renamed)'
This shows the “state” attributes
Hi @jimmyeao ,
it is always good to check the value_templates in the Template Checker (HA, Developer Tools, Template) first.
To get the attribute values you should use:
state_attr("sensor.ls71ftt_lock", "doorstatusfrontright")
In your example:
# Door and trunk status with own values
- platform: template
sensors:
ls71ftt_door_front_right_ownvalue:
value_template: >-
{% set doorstatusfrontright = state_attr("sensor.ls71ftt_lock", "doorstatusfrontright") %}
{% if doorstatusfrontright == False %} Closed
{% elif doorstatusfrontright == True %} Open
{% else %} {{ doorstatusfrontright }}
{% endif %}
friendly_name: 'LS71FTT closing status front right (renamed)'
unit_of_measurement: ''
Check the good example from @Bergals too. (There are more in this thread for sure…)
Many thanks, this helped a heap
@ReneNulschDE Thanks again for all this work. Could I ask for a tweak to one of the sensors so I dont’ have to write a custom template sensor to fix it. I suspect it may also be the home assistant set-up (and having to deal with this hybrid metric & imperial stuff).
Under the attributes for the Odometer& range_electric - you’ve hard-coded “unit_of_measurement” to Kilometres… (or is this home assistant pushing the ‘unit system’ cause I’ve got it set to Metric??) and as an expat-South African I love it. But… I’m living in the UK and everything is in miles … so my car’s set to Miles.
The attributes for the Odometer reports a field “distance_unit” and “unit” as miles … so could I ask to update the code so it looks at that field and if Miles, report unit_of_measurement as a reflection of that? ie, km for kilometres vs mi for miles??
And now I’m wondering if I need to submit a change request to home-assistant core to add a hybrid/custom unit system.
Hi @Bergals ,
the displayed unit is based on your HA Metric/Imperial Setup. The value is based on MB-App-settings unit.
The odometer sensor has a special attribute distance-unit and this shows the unit out of the MB-App-setting.
Your request is that I should decide on the MB/App Setting only and ingnore the HA Setting?
BR
Rene
Today I received this error message…
custom_components.mbapi2020.errors.RequestError: Error requesting data from https://bff-prod.risingstars.daimler.com/v1/vehicle/self/masterdata: 401, message='Unauthorized', url=URL('https://bff-prod.risingstars.daimler.com/v1/vehicle/self/masterdata')
Does this come from a service that is missing or did I enter wrong credentials?
Rene, I’m not sure that’s exactly the case. On the EQC the ‘Range Electric’ entity exposes as shown below. If you use the ‘maxrange’ attribute, it displays as ‘km’ whatever you do in Lovelace, even though as you can see, the car is set to ‘MILES’ in ‘Distance unit’. I got around this with a template to pick the numeric value of maxrange, but perhaps there’s another way.
Hi Richard,
this is strange. I tested this with an EQC and GLCe. The maxrange attributes changed when I modified the setting in the MB app.
Here a screenshot with km selected in the MB-app:
And here when I select mi in the MB app:
The only value that will not change is original_value. This is always KM. The API delivers original_value and display_value. I use the display_value and this is based on the MB-App Setting.
Yes, it does the same for me, but HA will always display the maxrange attribute with a ‘km’ suffix in Lovelace. If you set units in LL it ignores it and if you add ‘miles’ suffix you then get “xxx.x km miles”
which card do you use to display this? Extended attributes like maxrange have no unit…
I tried the Entities card with following code:
type: entities
entities:
- entity: sensor.l_so300e_range_electric
- type: attribute
attribute: maxrange
name: Attribute Max Range
entity: sensor.l_so300e_range_electric
and the result shows no unit: