MercedesME 2020 Home Assistant Integration

repository·master·Indexed 43 days ago

https://github.com/renenulschde/mbapi2020

A custom Home Assistant component for integrating Mercedes-Benz vehicle data. It provides access to sensors (fuel, range, tire pressure, battery state), binary sensors (warning lamps, theft system), locks, and services for remote control of climate, doors, windows, and engine start/stop. Supports real-time updates via WebSocket and requires a Mercedes-Benz account without MFA.

Tokens
5.7K
Snippets
19
Records
34
Agent score
6%

What's inside MercedesME 2020

  1. Install the MercedesME 2020 custom component

    master

    The MercedesME 2020 component is a Home Assistant custom component, not an Add-On.

    Prerequisites

    • Login first: Log in to the Mercedes-Benz iOS or Android app (or Mercedes Me Connect in North America) before installing the component.
    • MFA: Multi-Factor Authentication (MFA) is not supported. You must disable MFA on your account or use a dedicated account without MFA.

    Installation Steps

    1. Install the component using one of two methods:
      • Manual: Download the custom_component folder and copy it into your Home Assistant config folder.
      • HACS: Install the Home Assistant Custom Component Store (HACS) and select "MercedesME 2020" from the Integrations catalog.
    2. Restart Home Assistant.
    3. Refresh your browser window.
    4. Configure the integration: Go to Settings > Devices & Services > Add Integration and select "MercedesME 2020".
    5. Authenticate: Enter your Mercedes-Benz username and password when prompted.
  2. Prevent Mercedes-Benz account blocking

    master

    To minimize the risk of your Mercedes-Benz account being blocked by the service, follow these best practices:

    1. Use a dedicated account: Create a separate Mercedes-Benz user account specifically for Home Assistant.
    2. Invite the account to the vehicle: The primary vehicle owner should invite the new HA-MB account to access the vehicle (up to six additional users are allowed per vehicle).
    3. Avoid simultaneous use: Use the account exclusively in Home Assistant OR in the official Mercedes-Benz tools, but do not use both at the same time.

    Note on Geofencing: Certain features like geofencing data are only available to the primary user. If your Home Assistant setup requires geofencing, you must use the primary user account in HA and use secondary accounts for the official mobile apps.

  3. Configure optional MercedesME 2020 settings

    master

    You can manage optional settings via the Options dialog in Home Assistant under Configuration > Integrations.

    Available configuration keys:

    • Excluded Cars: A comma-separated list of VINs to exclude from integration.
    • PIN: The Security PIN required to execute special services. Set this up using your Mercedes-Benz mobile app.
    • Disable Capability Check: (North America only) When enabled, the component will skip checking the car's capabilities.
    • Debug Save Messages: When enabled, all relevant received messages are saved into the component's messages folder.
  4. How vehicle data is built and updated

    master

    The Client maintains a dictionary of Car objects, keyed by their VIN or FIN. Data is ingested through _build_car, which handles both full data loads (REST) and incremental updates (WebSocket/Push).

    Key behaviors:

    • Exclusion: If a car's VIN is in excluded_cars, it is ignored.
    • Data Modes: Data is categorized as pull (from REST) or push (from WebSocket).
    • Attribute Mapping: The client maps raw JSON attributes to structured CarAttribute objects for various components like Odometer, Tires, Windows, Electric, and Precond.
    • Synthetic Data: For REST data, if windowStatusOverall is missing, the client creates a synthetic status to ensure entity consistency.
  5. How the Client processes incoming WebSocket data

    master

    The Client uses an on_data handler to process various message types received via WebSocket. When a message arrives, the client identifies the msg_type and performs specific actions, often returning an acknowledgment command to the server.

    Supported message types include:

    • vepUpdates: Triggers _process_vep_updates and returns an acknowledgment with the received sequence_number.
    • vehicle_status_updates: Triggers _process_vehicle_status_updates.
    • apptwin_command_status_updates_by_vin: Processes command status updates.
    • assigned_vehicles: Processes assigned vehicle information.
    • data_change_event: Acknowledges data changes.
    • user_data_update, user_picture_update, user_pin_update, etc.: Various user-related updates that require sequence number acknowledgments.
  6. Available Diagnostic Sensors

    master

    Diagnostic sensors are hidden by default in Home Assistant; check the Devices page to view them.

    • Car: Monitors API communication. Attributes: full_update_messages_received, partital_update_messages_received, last_message_received, last_command_type, last_command_state, last_command_error_code, last_command_error_message.
    • RCP_Features: Shows true if extended configuration (like interior lighting) is available. Note: Users on versions < 0.6 may require re-authentication to enable this. Attribute: rcp_supported_settings (List of remote configuration options).
  7. Available Sensors

    master

    A wide range of sensors are available to monitor vehicle telemetry and state.

    Fuel and Range

    • Fuel Level (%): Attribute tankLevelAdBlue.
    • odometer: Attributes include distanceStart, averageSpeedStart, gasconsumptionstart, gasTankRange, gasTankLevel, tanklevelpercent, etc.
    • Oil Level (%)
    • Range Electric: Attributes include chargingstatus, distanceElectricalStart, maxrange, selectedChargeProgram.
    • Electric consumption start / Electric consumption reset
    • Charging power / Charging Power Limit (Attribute: chargingPowerRestriction)
    • State of Charge (soc): Represents battery charge level (0-100%). Attributes: maxSocLowerLimit, maxSoc.

    Vehicle State

    • Starter Battery State:
      • 0: green (Vehicle ok)
      • 1: yellow (Battery partly charged)
      • 2: red (Vehicle not available)
      • 3: serviceDisabled (Remote service disabled)
      • 4: vehicleNotAvalable (Vehicle no longer available)
    • Ignition state:
      • 0: lock
      • 1: off
      • 2: accessory
      • 4: on
      • 5: start
    • Aux Heat Status: Monitors heating/ventilation state. Attributes: auxheatActive, auxheattimeselection, temperature_points_frontLeft, etc.
    • Departure Time: Planned departure time for preconditioning. Attribute: departureTimeWeekday.
    • tirepressure[RearLeft|RearRight|FrontRight|FrontLeft]
    • Geofencing Violation: Values ENTER or LEAVE. Attribute: Last_event_zone.
  8. Available Binary Sensors

    master

    The integration provides several binary sensors to monitor vehicle status. Note that availability depends on your specific car model or purchased Mercedes-Benz licenses.

    Warning Sensors

    • warningwashwater
    • warningcoolantlevellow
    • warningbrakefluid
    • warningenginelight (Attributes: warningbrakefluid, warningwashwater, warningcoolantlevellow, warninglowbattery)
    • parkbrakestatus (Attribute: preWarningBrakeLiningWear)
    • tirewarninglamp (Attributes: tireMarkerFrontRight, tireMarkerFrontLeft, tireMarkerRearLeft, tireMarkerRearRight, tirewarningsrdk, tirewarningsprw, tireTemperatureRearLeft, tireTemperatureFrontRight, tireTemperatureRearRight, tireTemperatureFrontLeft)

    Status Sensors

    • theftsystemarmed (Attributes: carAlarmLastTime, carAlarmReason, collisionAlarmTimestamp, interiorSensor, interiorProtectionStatus, interiorMonitoringLastEvent, interiorMonitoringStatus, exteriorMonitoringLastEvent, exteriorMonitoringStatus, lastParkEvent, lastTheftWarning, lastTheftWarningReason, parkEventLevel, parkEventType, theftAlarmActive, towProtectionSensorStatus, towSensor)
    • windowsClosed (Attributes: windowstatusrearleft, windowstatusrearright, windowstatusfrontright, windowstatusfrontleft)
    • remoteStartActive (Attribute: remoteStartTemperature)
    • engineState
    • chargeFlapACStatus
    • Preclimate Status (Preconditioning) (Attributes: precondState, precondActive, precondError, precondNow, precondNowError, precondDuration, precondatdeparture, precondAtDepartureDisable, precondSeatFrontLeft, precondSeatFrontRight, precondSeatRearLeft, precondSeatRearRight, temperature_points_frontLeft, temperature_points_frontRight, temperature_points_rearLeft, temperature_points_rearRight)
    • wiperHealth (Attribute: wiperLifetimeExceeded)
  9. Available Locks

    master

    The integration provides lock entities.

    • Lock (Physical): Requires PIN setup in the Mercedes-Benz mobile app. If the PIN is not configured in the integration options, the lock will prompt for it during use.
    • Lock (Sensor): Monitors the status of various entry points. Internal value is doorlockstatusvehicle.
      • 0: vehicle unlocked
      • 1: vehicle internal locked
      • 2: vehicle external locked
      • 3: vehicle selective unlocked

    Attributes include: decklidstatus, doorStatusOverall, doorLockStatusOverall, doorlockstatusgas, doorlockstatusvehicle, doorlockstatusfrontleft, doorlockstatusfrontright, doorlockstatusrearright, doorlockstatusrearleft, doorlockstatusdecklid, doorstatusrearleft, doorstatusfrontright, doorstatusrearright, doorstatusfrontleft, rooftopstatus, sunroofstatus, engineHoodStatus.

  10. Available Buttons and Switches

    master

    You can control vehicle functions using the following buttons and switches:

    Buttons

    • Flash light
    • Preclimate start
    • Preclimate stop

    Switches

    • AuxHeat: Start/Stop the auxiliary heating of the car.
    • Preclimate: Start/Stop the preclimate function of the car.