MG Motor Mg5 Electric Car Integration

Just recently installed this and I’m blown away by how sophisticated it is.
(Having lots of fun already.)
One thing that puzzles me is these settings:

Gateway grace period after car shutdown 600 seconds
Gateway refresh period after car shutdown 120 seconds

What is the difference between these?

In the documentation it goes through each option for set up config and topic:

| /refresh/period/afterShutdown/set        | refresh interval (sec)   | After the vehicle has been shutdown, the gateway queries the status every 120 seconds (default value). The refresh interval can be modified with this topic.                                                                          |
| /refresh/period/inActiveGrace/set        | grace period (sec)       | After the vehicle has been shutdown, the gateway continues to query the state for 600 seconds (default value). The duration of this extended query period can be modified with this topic.                                            |

IOW it will (using default settings) poll the car a couple more times after it has been shut down but then cease polling after that.

Thanks wattmatters.
I’d figured that out about 2 hours ago!
The integration keeps polling the car after shutdown for 10 minutes at 2 minute intervals.
It’s pretty obvious really - a bit of a dumb question from me, but thanks for replying :slightly_smiling_face:

FYI if you set those values they will be reset to their defaults the next time the add-on restarts.
There’s a fix for this in the newer release, however it wasn’t backported to the AU/NZ version. I briefly messed about with my local install to try and backport the fix however I wasn’t successful and haven’t had the time to dedicate to it furher.

1 Like

Is it possible to get the code for all your manual sensors you’ve setup here?

Apologies, I missed your post.
Sure - the first few sensors are the normal ones provided by the integration (I have them defined manually as MQTT discovery is turned off in my deployment):

mqtt:
  sensor:
    - name: mg4_charge_connected
      icon: mdi:power-plug-outline
      state_topic: "saic/my@email/vehicles/LSJ_VIN/drivetrain/chargerConnected"
      value_template: "{{ value }}"

    - name: mg4_distance_total
      icon: mdi:counter
      state_topic: "saic/my@email/vehicles/LSJ_VIN/drivetrain/mileage"
      value_template: "{{ value |round(0) }}"
      unit_of_measurement: "km"

    - name: mg4_lvbattery
      icon: mdi:lightning-bolt-outline
      state_topic: "saic/my@email/vehicles/LSJ_VIN/drivetrain/auxiliaryBatteryVoltage"
      value_template: "{{ value }}"
      unit_of_measurement: "v"

sensor.evse_kwh is specific to my EVSE (well actually the supply side) and has nothing to do with the car.

The rest are template sensors to capture “point in time” measurements. They’re updated whenever a charger is connected/disconnected:

template:
  - trigger: #This trigger template sensor updates when the MG4 charger is unplugged, to capture the end of charging SOC
      - platform: state
        entity_id:
          - sensor.mg4_charge_connected
        from: "False"
        to: "True"
    sensor:
      - name: "mg4_t_charge_start_soc_kwh"
        icon: mdi:lightning-bolt-outline
        unit_of_measurement: "kWh"
        state: "{{ states('sensor.mg4_soc_kwh') }}"
      - name: "mg4_t_charge_start_range_used"
        icon: mdi:arrow-left-right
        unit_of_measurement: "km"
        state: "{{ states('sensor.mg4_u_distance_last_charge') }}"
      - name: "mg4_t_charge_start_range_remaining"
        icon: mdi:arrow-left-right
        unit_of_measurement: "km"
        state: "{{ states('sensor.mg4_range') }}"

  - trigger: #This trigger template sensor updates when the MG4 charger is unplugged, to capture the end of charging SOC
      - platform: state
        entity_id:
          - sensor.mg4_charge_connected
        from: "True"
        to: "False"
    sensor:
      - name: "mg4_t_charge_end_soc_kwh"
        icon: mdi:lightning-bolt-outline
        unit_of_measurement: "kWh"
        state: "{{ states('sensor.mg4_soc_kwh') }}"

And I have a utility meter sensor that’s referenced by one of the template sensors. There’s an automation which resets its value when the charger is unplugged

utility_meter:
  mg4_u_distance_last_charge: #Note, this counter is reset by an automation when charger is disconnected
    source: sensor.mg4_distance_total

How are you calculating sensor.mg4_energy_flow_from_grid

The mg flow from grid is from a current sensor I had in my power meter box. I have the MG charger but wasn’t able to integrate it. This was my work around solution.

Ah I have a MyEnergi Zappi which does expose some via its CT Clamp but this is data for the whole house.

I suppose I could make a Derivative sensor if it exceeds a certain % for a period of time. As typical use seems to be low and turning on EV charger nets it shooting to over 7kwH

Actually edit; found sensor.myenergi_home_power_charging which shows the W use of charging in real time.

The iSmart 2.0 app has finally started rolling out in Australia this afternoon.

I just swtiched from the legacy version and it works!

saic_rest_uri:
https://gateway-mg-au.soimt.com/api.app/v1/

saic_region:
au

everything else can be copied straight from the legacy version.

Fun fact though, If you keep HA using the legacy version then you can use the 2.0 app and have both going together.
As soon as you setup the newer HA addin it logs you out of the app again.

Good to know.

What does the new version enable compared with the old?

That might be preferable!

Main thing is just being on a maintained version again. The current version has a ton of fixes and updates that weren’t in the legacy branch.

Has this been reliable for you?
I get a lot of {"code":6,"message":"The service is not available,please try again later."} errors using the new API endpoint.
Have reverted to the legacy one for the time being.

I wonder if you have to try the new app at least once first before the new integration works? Did you try the app at all?

I don’t know if its needed or not, but I did run the new app before swapping my HA instance over.
I’m not seeing that error at all in my logs.

The add-in works, but it throws that error on a semi regular basis.
Good suggestion on logging in with the mobile app - I tried that, and obviously it works too, however the SAIC HA addin is still returning that same error intermittently.

I updated mine today to latest (no tag) using the uri and region suggested by @lkernan , and its been running fine. I cant see that error anywhere in my logs.

Is it possible the phone app keeps connecting and they are kicking each other out?

It was doing it before I installed the mobile app (I only installed the mobile app in the hope it fixed the issue).
Interestingly over the past couple of days I haven’t had any more errors. Still not sure what the underlying issue was as I’ve changed nothing in my config and haven’t restarted HA, the add-in or any of my networking gear.
Will keep an eye on it but for the moment it seems stable.

This post is amazing. I was literally giving up last night, but got it working in ten mins this morning.

Now i just need to make it look pretty and get some schedules set up for auto heating in the morning.

Thanks so much

Andy

Further update here.

Looking at peoples dashbaords it looks like im missing a lot of data?

  • Odometer readings?

Also how would i schedule my heating to come on in the morning - ive looked in automations and i cant see an option there?

Thanks
Andy