MG Motor Mg5 Electric Car Integration

Someone on the MG forums suggested changing the picture to monochrome with a picture editor, which I had a little trouble doing to get a dark enough grey from the original orange but they posted one they created, so I flipped that to portrait and have this so far:

I think portrait mode gives a bit more room to place info icons on the phone screen. I might add a couple of extra things, e.g. the range estimate, odometer.

I also found this site:
https://www.the-blueprints.com/vectordrawings/show/28488/mg_4_ev/

Like you I need to learn how to use icons for things like battery status, whether charger plugged in/charging, if aircon control can go on the image.

1 Like

Added a couple of extras. Easy to overwhelm the image.

The range estimate number is anomalous, that will correct itself.

1 Like

I took inspiration and created a modified version of displaying entities in an image.

4 Likes

Fwiw:
When I added the token with dashes instead of underscores it worked straight away:

- ABRP_USER_TOKEN=LSJE53458PT054876=gs750ap6-587a-1504-xs58-12345s87f584

I’m trying to run the mqtt gateway via docker. My MQTT container is in the same stack.

Everything can connect to the mqtt container such as zigbee2mqtt and other docker containers but I can’t get this gateway to connect even if I run under host mode.

I’m mqtt is anonymous. Logs just suggest connection refused.

The car (MG4) refuses to charge after the EVSE (Wallbox Pulsar Plus) has been on ‘Pause’ for a while.

I run an automation on the EVSE to start charging when the Solar inverter (SMA) voltage rises too high. This to prevent the solar system from shutting down. With my Polestar connected this works great, during a two week vacation it prevented dozens of solar system shutdowns.

However with the MG4 it does not (always) work. When the EVSE has been on ‘Pause’ for a wile, then when the automation kicks in and wants to car to charge, the car does not accept a charge, the EVSE status goes into ‘Waiting for car demand’.

What is causing this behavior, what could a work around be?

Behavior:

  • MG4 connected at 11:50
  • paused from 11:50 to 12:10
  • charging from 12:10 to 12:18 (based on solar inverter voltage)
  • paused from 12:18 to 16:03, at 16:03 charge initiated, but not starting
  • waiting for demand from 16:03 on, charging not accepted by the car

PS
This behavior also makes that the scheduled charge automation does not always work.

The only way to start charging again that I could find is to physically disconnect the car and reconnect it again (hard to do from 1000 miles away). Also forcing a refresh does not re-enable charging.

I’m not sure but this issue seems unrelated to the MG integration.

I would agree. Not the MG integration, not the EVSE integration, not the HA automation. It seems to be the reaction of the car to the EVSE switching on and off (more precisely in and out of ‘paused’).

I can’t figure out what causes this. Sometimes it works fine a whole day, sometimes it fails after the the first switch. Just wondering if anybody else has seen this work or fail and if there is a fix.

I’m clearly just guessing here, but have you checked in your car settings so there is no scheduled charge set?

Hi all, it’s an amazing feature that I’d like to use for my MG5!
I have some questions:

  • is it possible to use it to retrieve history of charge sessions and how much power was taken?
  • is it only linked to saic api or does it need OBD plug?
  • is it possible to use it for change charge settings: schedule, target
?
    Thank you very much for your work!

There is a power sensor and a sensor for plugged-in.
You should be able to feed the power sensor to a utility meter when ever the plugged-in sensor is ‘on’

ODB plug is not required

Yes.
There are settings for Target SOC, current adjustment for 6/8/16 and Max amps, a toggle to start and stop charging, start and stop times, and a selection for charge till target SOC or till stop time.

@wattmatters are you able to share the yaml for the latest versions of your dashboards?

I find it difficult to separate out the yaml from all my other dashboard code. I’m no coder so unfamiliar with whatever useful editing tools there are that might help with this.

This is the dashboard intended for our phones, with the overhead car image. It is placed inside of a 1 card panel (not masonry or side panel view).

Hopefully enough in there to help with the larger dashboard I have for the computer screen, as extracting that from everything else I have on my dashboard is too much.

title: Home
views:
  - icon: mdi:car
    title: MG
    path: e
    type: panel
    badges: []
    cards:
      - type: vertical-stack
        cards:
          - type: picture-elements
            image: local/community/MG4-top-grey1.jpeg
            elements:
              - type: state-badge
                entity: sensor.lsjwhXXXXXX_soc
                style:
                  top: 10%
                  left: 44%
                  '--ha-label-badge-title-font-size': 0em
              - type: state-badge
                entity: sensor.lsjwhXXXXXX_range
                style:
                  top: 10%
                  left: 56%
                  '--ha-label-badge-title-font-size': 0em
              - type: state-icon
                entity: binary_sensor.lsjwhXXXXXX_battery_charging
                style:
                  top: 9.5%
                  left: 50%
                  '--ha-label-badge-title-font-size': 0em
              - type: state-badge
                entity: lock.lsjwhXXXXXX_doors_lock
                style:
                  top: 60%
                  left: 50%
                  '--ha-label-badge-title-font-size': 0em
              - type: state-badge
                entity: lock.lsjwhXXXXXX_boot_lock
                style:
                  top: 85%
                  left: 50%
                  '--ha-label-badge-title-font-size': 0em
              - type: state-badge
                entity: climate.lsjwhXXXXXX_vehicle_climate
                style:
                  top: 45%
                  left: 56%
                  '--ha-label-badge-title-font-size': 0em
              - type: state-badge
                entity: sensor.lsjwhXXXXXX_interior_temperature
                style:
                  top: 45%
                  left: 44%
                  '--ha-label-badge-title-font-size': 0em
              - type: state-badge
                entity: sensor.lsjwhXXXXXX_tyres_front_left_pressure
                style:
                  top: 30%
                  left: 21%
                  '--ha-label-badge-title-font-size': 0em
              - type: state-badge
                entity: sensor.lsjwhXXXXXX_tyres_front_right_pressure
                style:
                  top: 30%
                  left: 78.5%
                  '--ha-label-badge-title-font-size': 0em
              - type: state-badge
                entity: sensor.lsjwhXXXXXX_tyres_rear_left_pressure
                style:
                  top: 71%
                  left: 21%
                  '--ha-label-badge-title-font-size': 0em
              - type: state-badge
                entity: sensor.lsjwhXXXXXX_tyres_rear_right_pressure
                style:
                  top: 71%
                  left: 79%
                  '--ha-label-badge-title-font-size': 0em
          - type: horizontal-stack
            cards:
              - type: gauge
                entity: sensor.lsjwhXXXXXX_soc
                name: SOC
                needle: true
                segments:
                  - from: 0
                    color: '#FF0000'
                  - from: 1.47
                    color: '#FF0F00'
                  - from: 2.94
                    color: '#FF1E00'
                  - from: 4.41
                    color: '#FF2D00'
                  - from: 5.88
                    color: '#FF3C00'
                  - from: 7.35
                    color: '#FF4B00'
                  - from: 8.82
                    color: '#FF5A00'
                  - from: 10.29
                    color: '#FF6900'
                  - from: 11.76
                    color: '#FF7800'
                  - from: 13.24
                    color: '#FF8700'
                  - from: 14.71
                    color: '#FF9600'
                  - from: 16.18
                    color: '#FFA500'
                  - from: 17.65
                    color: '#FFB400'
                  - from: 19.12
                    color: '#FFC300'
                  - from: 20.59
                    color: '#FFD200'
                  - from: 22.06
                    color: '#FFE100'
                  - from: 23.53
                    color: '#FFF000'
                  - from: 25
                    color: '#FFFF00'
                  - from: 26.57
                    color: '#F7FD00'
                  - from: 28.14
                    color: '#F0FC00'
                  - from: 29.71
                    color: '#E9FA00'
                  - from: 31.29
                    color: '#E1F900'
                  - from: 32.86
                    color: '#DAF701'
                  - from: 34.43
                    color: '#D3F601'
                  - from: 36
                    color: '#CCF401'
                  - from: 37.57
                    color: '#C4F301'
                  - from: 39.14
                    color: '#BDF101'
                  - from: 40.71
                    color: '#B6F002'
                  - from: 42.29
                    color: '#AEEE02'
                  - from: 43.86
                    color: '#A7ED02'
                  - from: 45.43
                    color: '#A0EC02'
                  - from: 47
                    color: '#99EA02'
                  - from: 48.57
                    color: '#91E903'
                  - from: 50.14
                    color: '#8AE703'
                  - from: 51.71
                    color: '#83E603'
                  - from: 53.29
                    color: '#7BE403'
                  - from: 54.86
                    color: '#74E303'
                  - from: 56.43
                    color: '#6DE104'
                  - from: 58
                    color: '#66E004'
                  - from: 59.57
                    color: '#5EDE04'
                  - from: 61.14
                    color: '#57DD04'
                  - from: 62.71
                    color: '#50DC04'
                  - from: 64.29
                    color: '#48DA05'
                  - from: 65.86
                    color: '#41D905'
                  - from: 67.43
                    color: '#3AD705'
                  - from: 69
                    color: '#33D605'
                  - from: 70.57
                    color: '#2BD405'
                  - from: 72.14
                    color: '#24D306'
                  - from: 73.71
                    color: '#1DD106'
                  - from: 75.29
                    color: '#15D006'
                  - from: 76.86
                    color: '#0ECE06'
                  - from: 78.43
                    color: '#07CD06'
                  - from: 80
                    color: '#00CC07'
                  - from: 81.18
                    color: '#08C410'
                  - from: 82.35
                    color: '#10BC19'
                  - from: 83.53
                    color: '#18B422'
                  - from: 84.71
                    color: '#20AC2B'
                  - from: 85.88
                    color: '#28A434'
                  - from: 87.06
                    color: '#309C3D'
                  - from: 88.24
                    color: '#389446'
                  - from: 89.41
                    color: '#408C4F'
                  - from: 90.59
                    color: '#488458'
                  - from: 91.76
                    color: '#507C61'
                  - from: 92.94
                    color: '#58746A'
                  - from: 94.12
                    color: '#606C73'
                  - from: 95.29
                    color: '#68647C'
                  - from: 96.47
                    color: '#705C85'
                  - from: 97.65
                    color: '#78548E'
                  - from: 98.82
                    color: '#804C97'
                  - from: 100
                    color: '#8845A1'
                unit: '%'
              - type: tile
                entity: sensor.lsjwhXXXXXX_range
                icon: mdi:map-marker-distance
                name: Range
                vertical: true
              - type: custom:mushroom-entity-card
                entity: sensor.lsjwhXXXXXX_auxiliary_battery_voltage
                layout: vertical
                name: Aux Battery
          - type: horizontal-stack
            cards:
              - type: custom:mushroom-entity-card
                entity: binary_sensor.lsjwhXXXXXX_charger_connected
                name: Charger
                layout: vertical
                primary_info: none
              - type: custom:mushroom-entity-card
                entity: binary_sensor.lsjwhXXXXXX_battery_charging
                name: Charging?
                layout: vertical
                primary_info: none
              - type: custom:mushroom-entity-card
                entity: sensor.lsjwhXXXXXX_power
                name: Power
                layout: vertical
                primary_info: none
          - type: horizontal-stack
            cards:
              - type: thermostat
                entity: climate.lsjwhXXXXXX_vehicle_climate
                name: Car Aircon
                show_current_as_primary: true
                features:
                  - type: climate-hvac-modes
                    hvac_modes:
                      - 'off'
                      - auto
              - type: vertical-stack
                cards:
                  - type: custom:mushroom-entity-card
                    entity: counter.ev_days_since_100_soc
                    name: Days Since 100% SOC
                    layout: vertical
                  - type: custom:mushroom-number-card
                    entity: number.lsjwhXXXXXX_target_soc
                    layout: vertical
                    name: Target SOC
          - type: horizontal-stack
            cards:
              - type: custom:mushroom-lock-card
                entity: lock.lsjwhXXXXXX_doors_lock
                name: Doors
              - type: custom:mushroom-lock-card
                entity: lock.lsjwhXXXXXX_boot_lock
                name: Boot
          - type: horizontal-stack
            cards:
              - type: tile
                entity: sensor.lsjwhXXXXXX_mileage
                icon: mdi:counter
                name: Odometer
                show_entity_picture: false
                vertical: false
                color: accent
              - type: tile
                entity: sensor.ev_mileage_monthly
                color: accent
                name: Monthly km

Universal card for displaying vehicle information from ngocjohn:

1 Like

I have set this up but am having an issue. I have checked the logs and its telling me my accounts been locked and to wait a day or change the password. I have changed the password using the app, but still no joy. The app works fine with new password.

Preformatted text 2024-09-30 13:54:08,659 [ ERROR ] MqttGateway crashed due to an Exception during startup - main
Traceback (most recent call last):
File “/usr/src/app/./mqtt_gateway.py”, line 441, in run
login_response_message = await self.saic_api.login()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/saic_ismart_client_ng/api/base.py”, line 72, in login
result = await self.deserialize(req, response, LoginResp)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/saic_ismart_client_ng/api/base.py”, line 185, in deserialize
raise se
File “/usr/local/lib/python3.12/site-packages/saic_ismart_client_ng/api/base.py”, line 170, in deserialize
raise SaicApiException(error_message, return_code=return_code)
saic_ismart_client_ng.exceptions.SaicApiException: return code: 15033, message: Sorry, the account has been locked, please try again tomorrow or you may reset password by clicking “forgot password”if you forget it.
return code: 15033, message: Sorry, the account has been locked, please try again tomorrow or you may reset password by clicking “forgot password”if you forget it.
2024-09-30 13:54:08,704 [ ERROR ] Task was destroyed but it is pending!
task: <Task pending name=‘Task-1’ coro=<Client._resend_qos_messages() running at /usr/local/lib/python3.12/site-packages/gmqtt/client.py:176>> - asyncio
sys:1: RuntimeWarning: coroutine ‘Client._resend_qos_messages’ was never awaited Preformatted text

Any ideas?

this looks great, do you use it and have some config?

I had a play around with this on the long weekend. It’s quite elegant:

Still massaging the layout (the UI is quite good once you wrap your head around it). Code:

type: custom:vehicle-status-card
button_card:
  - button:
      primary: Charger Connected
      secondary:
        - entity: sensor.mg4_charge_connected
          attribute: ''
          state_template: ''
      notify: ''
    button_type: action
    hide_button: false
    card_type: default
    default_card: []
    custom_card: []
    button_action:
      entity: sensor.mg4_charge_connected
      tap_action:
        action: more-info
      hold_action:
        action: none
      double_tap_action:
        action: none
  - button:
      primary: Odometer
      secondary:
        - entity: sensor.mg4_distance_total
          attribute: ''
          state_template: ''
      notify: ''
    button_type: action
    hide_button: false
    card_type: default
    default_card: []
    custom_card: []
    button_action:
      entity: sensor.mg4_distance_total
      tap_action:
        action: more-info
      hold_action:
        action: none
      double_tap_action:
        action: none
  - button:
      primary: AUX Battery
      secondary:
        - entity: sensor.mg4_lvbattery
          attribute: ''
          state_template: ''
      notify: ''
    button_type: action
    hide_button: false
    card_type: default
    default_card: []
    custom_card: []
    button_action:
      entity: sensor.mg4_lvbattery
      tap_action:
        action: more-info
      hold_action:
        action: none
      double_tap_action:
        action: none
  - button:
      primary: EVSE
      secondary:
        - entity: sensor.evse_kwh
          attribute: ''
          state_template: ''
      notify: ''
    button_type: action
    hide_button: false
    card_type: default
    default_card: []
    custom_card: []
    button_action:
      entity: sensor.evse_kwh
      tap_action:
        action: more-info
      hold_action:
        action: none
      double_tap_action:
        action: none
images:
  - url: /api/image/serve/de7ce78bd4c53e589df5748364cb6d16/original
    title: MG4_T.JPG
indicators:
  group:
    - name: Charging Data
      icon: mdi:car
      visibility: ''
      items:
        - entity: sensor.mg4_t_charge_start_soc_kwh
          name: Start SOC
          icon: ''
        - entity: sensor.mg4_t_charge_start_range_used
          name: Start Range Used
          icon: ''
          attribute: ''
        - entity: sensor.mg4_t_charge_start_range_remaining
          name: Start Range Remaining
          icon: ''
          attribute: ''
        - entity: sensor.evse_kwh
          name: EVSE kWh
          icon: ''
          attribute: ''
        - entity: sensor.mg4_t_charge_end_soc_kwh
          name: Charge End SOC
          icon: ''
          attribute: ''
  single: []
layout_config:
  button_grid:
    rows: 3
    swipe: true
  hide:
    button_notify: false
    buttons: false
    images: false
    indicators: false
    mini_map: true
    range_info: false
  theme_config:
    mode: auto
    theme: default
  images_swipe:
    max_height: 200
    max_width: 400
mini_map:
  device_tracker: device_tracker.mg4_location
  enable_popup: false
  theme_mode: auto
name: Bluey
range_info:
  - energy_level:
      - entity: sensor.mg4_soc_percent
        attribute: ''
        icon: ''
    range_level:
      - entity: sensor.mg4_range
        attribute: ''
    progress_color: ''
tire_preview: null
btn_preview: null
card_preview: null
default_card_preview: null

1 Like

Hi @PeatyPete and @wattmatters.
You may have already had some similar issues and resolved them but felt others reading this thread may benefit from my troubles. As mentioned my SOC was only updating at the rate of “Gateway charging refresh period” which is between 1000 and 1500 seconds while charging (between 17 - 25mins).
I have setup some automations that track the excess power being generated and changes the “current limit” in the MG integration so that I am not drawing from the grid to charge the MG. So the 17 - 25 minute updates were a little bit too long to accurately adjust the current based energy being fed into the grid.

My solution was to create a template sensor that tracks how long it has been since HA received a charge update from the MG, then use an automation to force an update if the car is charging and the time since last update is greater than 300 seconds (5 mins)

#Automation
- id: '17148028106762'
  alias: MG current force update when inactive
  description: check for update when inactive
  mode: single
  trigger:
  - platform: numeric_state
    entity_id:
      - sensor.mg4_seconds_since_update
    above: 300
  condition:
  - condition: numeric_state
    entity_id: sensor.mg4_energy_flow_from_grid
    above: 20
  - condition: state
    entity_id: binary_sensor.lsjwh4094pn199624_battery_charging
    state: 'on'
  action:
  - action: select.select_option
    metadata: {}
    data:
      option: force
    target:
      entity_id: select.lsjwh4094pn199624_gateway_refresh_mode

#Sensor
template:
  - sensor:
      - name: "mg4_seconds_since_update"
        unit_of_measurement: "Seconds"
        state: >
          {% set n = now() %}
          {% set t = states('sensor.lsjwh4094pn199624_last_charge_state') | as_datetime | as_local %}
          {{ (n-t).seconds }}

I am wary of the 12V battery with the drain issue when polling more frequently and when you stand next to the car you hear some of the systems turn on and the driver’s screen flashes on for a few seconds when the update is sent. Hopefully, the fact that the automation will only run when it is plugged in and charging will mean it will be ok. Do you know if the 12V battery charges during EV charging?

Interesting idea!
I wouldn’t be concerned about the LV battery - according to the manual the car charges it automatically as needed (refer the “Intelligent Charging” section).
My observation is “Intelligent Charging” always takes place when the car is charging. Eg, here’s my last charging session. You can see the LV battery jump during the session:

Our MG4 does. It also gets charged while driving.

Just check the auxiliary battery voltage during a charge session, that will tell you. It is an entity provided by the integration. e.g. here is my car’s charging power and auxiliary battery voltage during a charge session (note, the charging power data is from my own home circuit monitoring, not this integration):

You can see the auxiliary battery voltage rises to over 14 V while the car is being charged, then once the charging has ceased the auxiliary battery voltage drops back to normal resting voltage (a little less as it is being polled for a short while after a charge session).

Here’s the last 30 days of auxiliary battery voltage data:

Can see how it is regularly lifted >14 V when the car gets charged or is being driven, then drops down in between. In last couple of weeks we have not driven the car aside from this weekend just gone and so can see how the auxiliary battery voltage has slowly dropped in that two weeks.

Note that on the right side the voltage shows the auxiliary battery being charged again - the car in this instance was not being charged, but the auxiliary battery also gets recharged while driving.