MG Motor Mg5 Electric Car Integration

Sorry to hear about you waiting for your car :slightly_smiling_face:

My integration is running, when I drive the car and turn it off. And it’s set to periodic, but unless I hit the force button it does not update after the car is parked. When is “periodic” supposed to run for others?
I just set it up so I don’t have much experience with the add-on yet, I noticed it yesterday around midnight that it did not update any values since I came home around 19:00 so I thought the integration had issues and I restarted it. Then everything also updated fine once. It also updates fine while it charged during night. But again after I was done driving this morning it does not update after for hours until I then drive again or charge it. Is that as expected or ? It would be nice to have the periodic updates as it is set to :grinning:

1 Like

Where are those setting? (gateway active refresh periodo, gw grace periodo
). I cant find them at the addon configuration -edited: they are created by the addon, got it-.

hi,
what is the SAIC_USER is it ISMART user of the MG app ?
from where do i get it ?

Yes you are right it is the same user that you use in the Phone App. And it has to be the email and not phone number, you can log in with both in app but not with this integration it has to be email.

Want to share my new observations with the integration now running for a few days and also hear your experience with it if its same or different.
I have Marvel R and the integration works to collect a lot of sensors but here is what I have found out.

  • It only updates when im driving the car.

  • Initially I thought it also updated the progress during charging, but it does not.

  • I do have the “periodic” setting enabled( its default) , but It does not update. Now my sensors haven’t been updated for 19 hours since I last used the car. It only updates from the system if I use the force or if I drive the car.

Again, could anyone tell me what is the expected behaviour of the integration? I could possibly setup an automation that would hit the force state at a specific interval, but I thought the whole point is that it should be doing it is self on a regular basic. Perhaps it is also working as expected for others, but then I need to find out what could be wrong with my system since it does not fetch new values.

Thanks in advance.

Found the info in the add-on documentation section. It is working as intended (only when start of car is detected)
Let me share the info here as well for others. Of course I could play around third entry to set it lower like once per hour or something, but If it is set so high there must be a real concern for draining the battery. Oh well the stats are good to have from driving, I just thought I would have it more often from this besides when driving.

  • The gateway queries the vehicle and charge status periodically after a vehicle start event has happened (default value: periodic. The periodic refresh can be switched off (value: off). A refresh can also be forced (value: force).

  • In case a vehicle start event has occurred, the gateway queries the status every 30 seconds (default value). The refresh interval can be modified with this topic.

  • Vehicle and charge status are queried once per day (default value: 86400) independently from any event. Changing this to a lower value might affect the 12V battery of your vehicle. Be very careful!

  • 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.

  • 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.

2 Likes

Thanks for your help

hmmm when my car is at home and charging I need to monitor the soc for some automations. (I have configured that the car is always directly charged until a customizable threshhold is reached, after that, the car shall only be charged when there is coming enough power from the solar panels
)

Do I need to create an own automation and can I then set in this automation the “Gateway refresh mode” to forced??

Thank you for sharing this info. There is a lot there that we dont need, so an iteration of this would be to make it clearer in the notes or the setup what needs to be done, however I appreciate it is still beta.

Hello,

I am in the process of buying a MG4. I was of course looking for an integration.

I have seen that a python client library exists, does it rely on the addon ? it seems it does not need it.

I have the idea of developing an full-python integration for iSmart (without the need of the addon, nor the need of MQTT), would anything prevent it?

Is there already some work in progress on this subject?

(BTW I have already developed the Calaos integration)

If you want to do it, no reason why not. The existing MQTT gateway Docker image works great for our MG4 — I run it outside HA.

Thank for your instructions
 worked great


Now both me and my wife can control/view status of the car without being logged out from the MG iSmart App all the time!

Of course now its time to create some automations for this great integration.
If have already created notifications to get status back to my our phones when we turn on defrost or changed the battery target SOC.

Now i want to create an automation with timer when we want to start the vehicle climate with warm or cold air
 i now the entity for this is:

climate.lsje*******091118_vehicle_climate

Is it possible to also set a climate temperature or is it just “Auto” that is possible?

Anyone else expiring issues with their implementation in HA atm ?
I got the iOS app update today of the MG smart and it didn’t work for an hour as said network error and later I had to log off and back to get it to work. But it does work now. But now I noticed that the add on in home assistant is crashed with errors in the log so my entities are unavailable. And if I start it again shortly after it crashed. Just wonder if I’m the only one seeing this. :man_shrugging:

Update: The watchdog to make sure the add-on runs in case of a failure does not kick in on this crash so it stays in stopped state due to this exception.

task crashed with an exception - __main__
Traceback (most recent call last):
  File "/usr/src/app/./mqtt_gateway.py", line 90, in handle_vehicle
    vehicle_status = self.update_vehicle_status()
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/./mqtt_gateway.py", line 110, in update_vehicle_status
    vehicle_status_rsp_msg = self.saic_api.get_vehicle_status_with_retry(self.vin_info)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 193, in get_vehicle_status_with_retry
    return self.handle_retry(self.get_vehicle_status, vin_info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 457, in handle_retry
    return self.__handle_retry_with_app_data(func, vin_info=vin_info, max_retries=max_retries)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 488, in __handle_retry_with_app_data
    rsp = func(vin_info)
          ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/saic_api.py", line 188, in get_vehicle_status
    self.message_V2_1_coder.decode_response(vehicle_status_rsp_hex, vehicle_status_rsp_msg)
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/ota_v2_1/Message.py", line 12, in decode_response
    return super().decode_response(message, decoded_message)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/saic_ismart_client/common_model.py", line 495, in decode_response
    buffered_message_bytes = io.BytesIO(bytes.fromhex(message[5:]))
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: non-hexadecimal number found in fromhex() arg at position 4

Hi TripleJ,
Yes, I experience the same behaviour. I am running the saic-python-mqtt-gateway in a docker container and I’ve seen it restart a few times during the last couple of hours and values are not updated. My MG iOS app also doesn’t load any updated values which makes me think this has something to do with MG’s api not responding.

Hi Herbert,

I think you are right that is MG’s Api having issues or perhaps even some changes to it that causes the integration crash like this. But also as we have seen their own app has issues. I also threw the error code here for the developer to see the exception and perhaps figure out how to properly handle it so it does not crash like so. But I should properly see if someone have shared this at GitHub, and if not post it there so they can get a proper ticket to look at the exception.

Also everything “unknown” on my side :disappointed:

Most likely your add-on is stopped due to the crash, and will keep crashing if you turn it on.

The addon has moved to using the “new” SAIC API.
If it doesn’t work you need to switch to using the legacy version of the integration from the add-on store.

For example, those of us in Australia apparently don’t have the new API yet. We need to use the legacy one for now.

edit: Nov 2024: Australia has now moved to iSmart 2.0 as well. The normal version of the addon now works.

2 Likes

Any issues changing to the legacy integration ? Did the entity names stay the same across the change ?

When I realised 0.5.1 wasn’t working I just rolled back to 0.4.6.
Hesitant to change to legacy incase my entity names or customisations are lost.

The new latest version works great for me for my Marvel R.
After the crashes and now developer released the new version I just updated and things started to work again on this new API.
I don’t know what will happen when you switch to legacy, but since it is most likely the url and api calls the entities will stay the same I would assume.