MG Motor Mg5 Electric Car Integration

Aside the occasional blip in the cabin temperature reading, which sometimes displays as 83°C (or something like that), I note my Range entity is now showing 2,046 km. Which would be nice but clearly that’s an error.

Restarting the add on makes no difference, while the range in the iSmart app shows 301 km.

This is one of the (minor) reasons I use manually defined sensors rather than auto discovery. You can filter out the spurious readings:

    - name: mg4_climate_temp_interior
      icon: mdi:thermometer
      state_topic: "saic/xxxx@yyyy/vehicles/LSJWxxxx/climate/interiorTemperature"
      value_template: "{{ '' if value == '87' else value }}"
      unit_of_measurement: "°C"

Yeah, thanks. It cleared itself. It’s certainly curious.

Adding in my 2c here for how I have this integrated. Using HA in a docker so add-ons was not option.

Have setup in “Container Manager” aka Docker on Synology NAS.

eclipse-mosquitto
As the broker, important piece I believe was the configuration to allow anon connections.

Make a folder for Mosquitto, and three sub folders. Volume mapping for container as below:

/docker/Mosquitto/config : /mosquitto/config
/docker/Mosquitto/data : /mosquitto/data
/docker/Mosquitto/log : /mosquitto/log

Under config folder have file mosquitto.conf with content as below:

persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
listener 1883
allow_anonymous true
socket_domain ipv4

saic-python-mqtt-gateway
And then since I am in AU, used the specific 0.4.6 version of

Add in envrionment variables to point at the NAS
MQTT_URI : tcp://[NASIP]:1883

Then realising the the 0.4.6 version has a different evironment variable name than the latest version of add-on has (this is what took me a while to work out)
SAIC_URI : https://tap-au.soimt.com/

MQTT
Back in HA, add in MQTT integration, point it at your NAS IP. Then slowly get data. Neat.

Have not tried like unlocking doors or anything yet, as im not near the car.
Actually just tried it then, seems to work, will reconfirm later.

1 Like

Managed to get my integration setup today thanks to this fantastic guide. I have a question for you though if you don’t mind watt??

Would it be possible for you to share the raw YAML for your current dash? I want to use it as a starting point for mine as the layout is brilliant

Here’s the code for the phone dashboard. I hope it helps.

Note: In the code below I have replaced my unique vehicle’s code with a generic identifier carID, so you would need to replace those sensors with your own created by the add-on.

The phone dashboard is set up as Panel (one card) type rather than the usual Masonry dashboard. It looks weird on a computer browser but suits our iPhone screens.

I also use some Mushroom cards, so you would need to install those in order to replicate this. These are a HACS front end, refer the link above.

I’m wondering whether a Mushroom card for indicating SOC would be nicer than the gauge I set up.

type: vertical-stack
cards:
  - type: horizontal-stack
    cards:
      - type: gauge
        entity: sensor.carID_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.carID_range
        icon: mdi:map-marker-distance
        name: Range
        vertical: true
      - type: custom:mushroom-entity-card
        entity: sensor.carID_auxiliary_battery_voltage
        layout: vertical
        name: Aux Battery
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-entity-card
        entity: binary_sensor.carID_charger_connected
        name: Charger
        layout: vertical
        primary_info: none
      - type: custom:mushroom-entity-card
        entity: binary_sensor.carID_battery_charging
        name: Charging?
        layout: vertical
        primary_info: none
      - type: custom:mushroom-entity-card
        entity: sensor.carID_power
        name: Power
        layout: vertical
        primary_info: none
  - type: horizontal-stack
    cards:
      - type: thermostat
        entity: climate.carID_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.carID_target_soc
            layout: vertical
            name: Target SOC
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-lock-card
        entity: lock.carID_doors_lock
        name: Doors
      - type: custom:mushroom-lock-card
        entity: lock.carID_boot_lock
        name: Boot
  - type: horizontal-stack
    cards:
      - type: tile
        entity: sensor.carID_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

I have two sensors above which are not generated natively by the add on.

They are counter.ev_days_since_100_soc and sensor.ev_mileage_monthly.

For sensor.ev_mileage_monthly I just created a Utility Meter helper based on the mileage sensor
sensor.carID_mileage. I have one for daily and monthly.

For counter.ev_days_since_100_soc I set up a counter helper which is controlled by two automations (although I probably could combine the automations into one).

The first automation increments the counter each day at midnight:

alias: EV - Increment Counter Days Since EV 100% SOC
description: Increment the days since EV 100% SOC cycle counter each day
trigger:
  - platform: time
    at: "00:00:00"
condition: []
action:
  - service: counter.increment
    data: {}
    target:
      entity_id:
        - counter.ev_days_since_100_soc
mode: single

The second resets the counter whenever SOC ever reaches 100%:

alias: EV - Reset Days Since 100% SOC
description: Reset Counter for number of days since the car was fully charged.
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.carID_soc
    above: 99
condition: []
action:
  - service: counter.reset
    target:
      entity_id: counter.ev_days_since_100_soc
    data: {}
mode: single

While functional, it’s still a fairly naive dashboard IMO.

I’m sure there are others who could make a much nicer looking dashboard, using animated images of the car for instance to highlight various things, a bit like what some clever cookies have done in this thread (way above my pay grade):

If it was ever done for the MG4 it would be super cool.

4 Likes

As a thank you for your assistance in getting this up and running I am sharing my picture elements card with you. It displays the tyre pressures in the correct locations on the car:

type: picture-elements
elements:
  - type: state-badge
    entity: sensor.lsjwh4097pn077873_tyres_front_left_pressure
    style:
      top: 17%
      left: 60%
      '--ha-label-badge-title-font-size': 0em
  - type: state-badge
    entity: sensor.lsjwh4097pn077873_tyres_front_right_pressure
    style:
      top: 80%
      left: 60%
      '--ha-label-badge-title-font-size': 0em
  - type: state-badge
    entity: sensor.lsjwh4097pn077873_tyres_rear_left_pressure
    style:
      top: 17%
      left: 30%
      '--ha-label-badge-title-font-size': 0em
  - type: state-badge
    entity: sensor.lsjwh4097pn077873_tyres_rear_right_pressure
    style:
      top: 80%
      left: 30%
      '--ha-label-badge-title-font-size': 0em
image: local/community/mg4-ext3.jpg

Use this image as the background and upload it to your HA instance under www/community

3 Likes

Wow, that’s neat, thanks! I’ve not knowingly used a picture elements card before, always good to learn something new.

If I may, where did you find the image? I’ve googled but no luck. It would be nice to get one matching our car’s colour.

Added a couple of things but gets easily cluttered.

Not sure I like the battery status with this one:

1 Like

I searched for “MG4 aerial view”

I was going to see if there was a way of setting the colour via a drop down and get one example of each available colour.

I am going to spend some time working out how best to add things like the battery status on the picture card.

1 Like

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.