MG Motor Mg5 Electric Car Integration

nice thankyou!!

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.