Mercedes Benz integration

Hey Igi,

unfortunately, depending on the vehicle, there are still problems with some data points in the API. I am affected myself and will report here when the errors that affect me have been fixed by the Mercedes team.

But I am glad that you have come so far and use my integration.
Have fun with it!

Cheers Chris

I made some modifications with the widget:
EDIT: Dark mode support added.

uid: widget_Mercedes_v3
tags: []
props:
  parameters:
    - description: Label
      label: Label
      name: propLabel
      required: false
      type: TEXT
  parameterGroups: []
timestamp: May 18, 2021, 11:22:31 AM
component: f7-card
config:
  expandable: true
  swipeToClose: true
  backdrop: true
  class:
    - card-expandable-animate-width
  style:
    height: 120px
    max-height: 120px
    min-height: 120px
    min-width: 110px
    max-width: 400px
    margin: 5px
    --f7-theme-color: var(--f7-text-color)
    background-color: "=themeOptions.dark === 'light' ? 'white' : 'black'"
slots:
  default:
    - component: f7-card-content
      config:
        style:
          width: 100%
      slots:
        default:
          - component: oh-button
            config:
              iconF7: xmark_circle_fill
              iconSize: 30px
              style:
                position: absolute
                top: 0
                right: 0
                padding-top: 10px
                padding-bottom: 35px
                z-index: 999
              class:
                - card-opened-fade-in
                - cell-close-button
                - card-close
          - component: f7-block
            config:
              class:
                - no-padding
              style:
                margin: -5px
                height: 200px
            slots:
              default:
                - component: f7-row
                  config:
                    style:
                      height: 20px
                      white-space: nowrap
                      flex-wrap: nowrap
                      text-overflow: ellipsis
                  slots:
                    default:
                      - component: f7-col
                        slots:
                          default:
                            - component: f7-row
                              config:
                                class:
                                  - justify-content-flex-start
                                style:
                                  flex-wrap: nowrap
                                  width: 100%
                              slots:
                                default:
                                  - component: f7-icon
                                    config:
                                      material: directions_car
                                      size: 20px
                                      style:
                                        margin-top: 0px
                                  - component: Label
                                    config:
                                      text: My GLC 300e
                                      style:
                                        overflow: hidden
                                        white-space: nowrap
                                        text-overflow: ellipsis
                                        font-size: 16px
                                        font-weight: 600
                                        margin-left: 2px
                                        margin-top: -2px
                            - component: f7-row
                              config:
                                class:
                                  - justify-content-flex-start
                                style:
                                  flex-wrap: nowrap
                                  width: 100%
                              slots:
                                default:
                                  - component: f7-chip
                                    config:
                                      text: '="Bat: " + items.mbc_data_soc.displayState'
                                      color: "=items.mbc_data_soc.state < '10' ? 'red' : 'green'"
                                      style:
                                        font-size: 11px
                                        font-weight: 600
                                  - component: f7-chip
                                    config:
                                      text: '="Fuel: " + items.mbc_data_tanklevelpercent.displayState'
                                      color: "=items.mbc_data_tanklevelpercent.state < '20' ? 'red' : 'green'"
                                      style:
                                        font-size: 11px
                                        font-weight: 600
                            - component: f7-row
                              config:
                                style:
                                  height: 20px
                                  white-space: nowrap
                                  flex-wrap: nowrap
                                  text-overflow: ellipsis
                              slots:
                                default:
                                  - component: f7-chip
                                    config:
                                      text: "=items.mbc_data_doorlockstatusvehicle.state =='2' ? 'locked' : 'unlocked'"
                                      color: "=items.mbc_data_doorlockstatusvehicle.state =='2' ? 'green' : 'red'"
                                      style:
                                        font-size: 11px
                                        font-weight: 600
                            - component: f7-row
                              config:
                                class:
                                  - justify-content-flex-start
                                style:
                                  white-space: nowrap
                                  flex-wrap: nowrap
                                  text-overflow: ellipsis
                              slots:
                                default:
                                  - component: f7-icon
                                    config:
                                      material: ev_station
                                      size: 16px
                                      color: green
                                      style:
                                        margin-top: 20px
                                  - component: Label
                                    config:
                                      text: =(Number.parseFloat(items.mbc_data_rangeelectric.state.split(" ")[0])).toFixed(0) + ' km'
                                      style:
                                        text-overflow: ellipsis
                                        overflow: hidden
                                        white-space: nowrap
                                        margin-top: 20px
                                        margin-left: 1px
                                        font-size: 10px
                                        font-weight: 500
                                  - component: f7-icon
                                    config:
                                      material: local_gas_station
                                      size: 15px
                                      color: blue
                                      style:
                                        margin-top: 20px
                                        margin-left: 2px
                                  - component: Label
                                    config:
                                      text: =(Number.parseFloat(items.mbc_data_rangeliquid.state.split(" ")[0])).toFixed(0) + ' km'
                                      style:
                                        text-overflow: ellipsis
                                        overflow: hidden
                                        white-space: nowrap
                                        margin-left: 1px
                                        margin-top: 20px
                                        font-size: 10px
                                        font-weight: 500
          - component: f7-block
            config:
              class:
                - card-prevent-open
                - card-content-padding
              style:
                height: 200px
            slots:
              default:
                - component: oh-image
                  config:
                    url: http://192.168.178.90:8080/static/images/mb-glc300e.png
                    style:
                      width: 100%
                      height: 100%
                      object-fit: cover
                - component: oh-list
                  config:
                    class:
                      - padding
                  slots:
                    default:
                      - component: Label
                        config:
                          text: =props.Title?props.Title:"other States:"
                          style:
                            padding: 7px
                            border-bottom: 1px solid grey
                            font-weight: 600
                            color: gray
                            margin-top: 10px
                      - component: f7-list-item
                        slots:
                          header:
                            - component: f7-row
                              slots:
                                default:
                                  - component: f7-icon
                                    config:
                                      f7: lock
                                      size: 32px
                                      style:
                                        padding: 5px
                                  - component: Label
                                    config:
                                      text: Lock-Status
                                      style:
                                        margin-top: 10px
                          footer:
                            - component: f7-row
                              slots:
                                default:
                                  - component: Label
                                    config:
                                      text: =items.mbc_data_doorlockstatusvehicle.displayState
                                      style:
                                        margin-top: 8px
                                      color: gray
                      - component: f7-list-item
                        slots:
                          header:
                            - component: f7-row
                              slots:
                                default:
                                  - component: f7-icon
                                    config:
                                      f7: lock_shield
                                      size: 32px
                                      style:
                                        padding: 5px
                                  - component: Label
                                    config:
                                      text: Latch
                                      style:
                                        margin-top: 10px
                          footer:
                            - component: f7-row
                              slots:
                                default:
                                  - component: Label
                                    config:
                                      text: =items.mbc_data_decklidstatus.state
                                      style:
                                        margin-top: 8px
                                      color: gray
                      - component: f7-list-item
                        slots:
                          header:
                            - component: f7-row
                              slots:
                                default:
                                  - component: f7-icon
                                    config:
                                      f7: sun_max
                                      size: 32px
                                      style:
                                        padding: 5px
                                  - component: Label
                                    config:
                                      text: Sunroof
                                      style:
                                        margin-top: 10px
                          footer:
                            - component: f7-row
                              slots:
                                default:
                                  - component: Label
                                    config:
                                      text: =items.mbc_data_sunroofstatus.displayState
                                      style:
                                        margin-top: 8px
                      - component: f7-list-item
                        slots:
                          header:
                            - component: f7-row
                              slots:
                                default:
                                  - component: f7-icon
                                    config:
                                      f7: sum
                                      size: 32px
                                      style:
                                        padding: 5px
                                  - component: Label
                                    config:
                                      text: Total-km
                                      style:
                                        margin-top: 10px
                          footer:
                            - component: f7-row
                              slots:
                                default:
                                  - component: Label
                                    config:
                                      text: =items.mbc_data_odo.displayState
                                      style:
                                        margin-top: 8px
                      - component: f7-list-item
                        slots:
                          header:
                            - component: f7-row
                              slots:
                                default:
                                  - component: f7-icon
                                    config:
                                      f7: clock
                                      size: 32px
                                      style:
                                        padding: 5px
                                  - component: Label
                                    config:
                                      text: last update
                                      style:
                                        margin-top: 10px
                          footer:
                            - component: f7-row
                              slots:
                                default:
                                  - component: Label
                                    config:
                                      text: =items.mbc_lastConnectionDateTime.displayState
                                      style:
                                        margin-top: 8px
2 Likes

Hey there, when i try to run the rule from the git files

rule “Call mb-connect python script with --data arg”

when

Time cron "0 */10 * ? * *" // every 10min

then

logInfo("mb-connect", "Calling mb-connect.py --data")

executeCommandLine(Duration.ofSeconds(45), "/usr/bin/python3", "/etc/openhab2/scripts/mb-connect/mb-connect.py", "--data")

end

i get the following log error message:

00:03:00.057 [ERROR] [untime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘Call mb-connect python script with --data arg’: ‘ofSeconds’ is not a member of ‘java.lang.Class<org.joda.time.Duration>’; line 6, column 24, length 22

im running OH 2.5.1 on my system.

Solved:The execute command changed from OH 2.5 to 3.0, the following code is working now:

executeCommandLine(“/usr/bin/python3 /etc/openhab2/scripts/mb-connect/mb-connect.py --data”, 45000)

1 Like

Hey @BlackJack ,

glad you could already solve the problem yourself and thanks for showing the solution here! :heartpulse:

I’m working on the script again. The image download works pretty good now. A few small things are fixed / added. I will test it a few more days and adjust the description, also the changes mentioned here from openHAB version 2.5 to 3.

Greetings
Chris

Since a couple of days I get following error message:

## Starting Mercedes Benz API connection ##
# The access token has expired, use the refresh token to get a new one.
# Error refreshing token:can only concatenate str (not "dict") to str
# Mercedes Benz API connection successfully established!
# Searching resources for selected scopes:
# Response Error

I can’t remember having changed anything in my setup except going back and forth between various OH milestone builds and the latest stable build due to other issues.

The script used to work flawlessly before. Any idea how I could fix this error? I already tried getting a new access token which works (it gets saved to the OH item) but obviously does not solve the issue.

Hey @pune2001 ,

off the top of my head, I can’t say much about it.
It would certainly help if you set the debug variable in the mb-connect.py script to True. That should give you more information.

Otherwise I can only recommend you to go through the whole process again as in my description to make sure that all items etc. are correct.

Cheers
Chris

I have updated my code. It is now easier to set the openHAB items etc. and you now have the possibility to download your vehicle images!

Also an article was published on Mercedes-benz.

The new release is on GitHub.

I hope you like it!

Cheers!
Chris

4 Likes

Very nice, im looking forward to try this when I have some spare time.

Thanks Mads

1 Like

Works like a charm. Also the image download. Thanks for the great work. :+1:

1 Like

Hi, I‘m developing the ConnectedCar binding and have already support for Audi, VW, VW ID (WeConnect), Skoda, SEAT and Skoda Enyaq.

I‘m thinking on adding support for Mercedes based on the work here = fully integrated binding (no longer script based).

How is the interest? Who likes to support with testing?

@spawny0815 what do you think?

7 Likes

Hey Markus,

that would be great, of course. It is also on my to do list, but I already know that I will not have time next year.
For the users it would be awesome of course, and it should not be difficult because of my work plus the good mercedes documentation.

I will be happy to support you as well as test. In addition, I am confident that you will find other testers here, as I have also been helped a lot.

Cheers Chris

3 Likes

Hi All,

Gone through the full install and no luck. Getting 403/401 errors. All credentials are correct including VIN.
Has anyone been successful implementing this in Australia? I have a suspicion that the APIs are not open to AUS market… :frowning:

Hey @alexander_romanov_pv ,

under the products you can look up for which markets the whole is valid.

Australia is unfortunately not listed here.

Chris

Maybe you would receive the vehicle images upside down… this could cause compatibility issues :wink: :upside_down_face:

1 Like

Nice one Thomas! :rofl:

1 Like

fyi: I started to integrate MercedesMe into the CarNet binding. So far I implemented a different login approach using a login code. The big advantage is that the initial setup is way easier. I already saw the access_token. Next is getting vehicle list and adapt the different API calls (status & control).

The final channel layout will be different to this integration, because I’ll unify with existing
implementation.

Let me know if someone wants to help on initial tests and testing. Updates will be posted to ConnectedCar thread

5 Likes

ok, let’s start testing :slight_smile:

@Oggerschummer @Kennet @spawny0815 @mst87 @tkropf @nils.schnabel @igi @hmerk
find infos here: ConnectedCar Binding myAudi, Volkswagen, VW ID, Mercedes, Skoda, Enyaq, Seat, Ford, WeCharge - #585 by markus7017

3 Likes

Very nice explanation of how to install the application! I managed to go through it completely. Unfortunately, I keep getting an error when running the script. Any idea what I am doing wrong?


[20:53:03] pi@openhabpi:/etc/openhab2/scripts/mb-connect$ python3 /etc/openhab2/scripts/mb-connect/mb-connect.py --data
  File "/etc/openhab2/scripts/mb-connect/mb-connect.py", line 332
    reply = input(f"{question} (y/n): ").lower()
                                      ^
SyntaxError: invalid syntax

You have to delete the “f” from → input(f"…

…but then there are even more errors.

The multi-line comment symbols are also a problem as well as .isoformat argument “timespec” for the milliseconds

Hey @DaveVdB @Mathias_Guderjahn ,

have you checked the requirements? python version?
I really don’t have much time at the moment. If you can help me and describe your setup in more detail, I can help you with it easier and faster.

Chris