MG / SAIC - Custom Integration

Thank you, literally on a HACS video now

A

Hi @all

this is my Probelm:

Error setting up entry MG SAIC - LSJWHxxxxxxxxx for mg_saic
Traceback (most recent call last):
File “/config/custom_components/mg_saic/coordinator.py”, line 73, in _async_update_data
self._is_generic_charging_response(charging_info)
File “/config/custom_components/mg_saic/coordinator.py”, line 191, in _is_generic_charging_response
raise GenericResponseException(
custom_components.mg_saic.coordinator.GenericResponseException: Generic charging response received.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 635, in __async_setup_with_context
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/config/custom_components/mg_saic/init.py”, line 42, in async_setup_entry
await coordinator.async_setup()
File “/config/custom_components/mg_saic/coordinator.py”, line 53, in async_setup
await self.async_config_entry_first_refresh()
File “/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py”, line 309, in async_config_entry_first_refresh
await self._async_refresh(
File “/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py”, line 382, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/config/custom_components/mg_saic/coordinator.py”, line 141, in _async_update_data
await asyncio.sleep(delay)
File “/usr/local/lib/python3.12/asyncio/tasks.py”, line 665, in sleep
return await future
^^^^^^^^^^^^
asyncio.exceptions.CancelledError

HI I think I found the problem: you can either use only the iSmart app or Home Assistant (HA). When I start the integration, I get logged out of the app. Then it works briefly, but when I log back into the app, it stops working in HA. Is there a solution for this?

BG Nico

Hi @NED21

No, by the moment there is no way to use both things at the same time. You either use the iSmart App or this integration. It is clearly stated on the repository and info.

MG says that they are working on it, but so far, no news on that update that I was told that was coming.

Hi All,

Im back for some help if possible, ive installed HACS, and Varetas repositry - its asked for my log in which i have done but now im stumped.

I cant see what i need to do next - is there a walkthough or help file please :slight_smile:
Thanks
A

Hi,

You may check the repository Readme.

Without much more information on what/where are you stopped, I cannot be of help. Some more info and I may give you some hints.

But mostly check the instructions on GitHub - ad-ha/mg-saic-ha: MG SAIC Custom Integration for Home Assistant

Cheers

Thanks for replying.

I have followed your guide

  1. Go to Configuration → Integrations.
  2. Click on the “+ Add Integration” button.
  3. Search for “MG SAIC” and follow the instructions to set up the integration.
  4. Select your type of account (email or phone), enter the details and select your region (EU, Asia, China)
  5. Once connected to the API, a list of available VINs associated with your account will be shown. Select the vehicle that you want to integrate and finish the process.

Picked my VIN and then nothing happens.

Have lots of errors in the log file.

Maybe it isnt for me - all i wanted to do was schedule defrosting :frowning:
A

So, if you have errors maybe is because you get generic responses based on the data provided by MG.

You may keep trying until you get the data available. Or, instead, you can share those logs on Github (Issues ¡ ad-ha/mg-saic-ha ¡ GitHub) and I can work on that to find a solution. If is something different from the issues on course.

Cheers

This is a fantastic integration - really chuffed with it. Accepting you cannot use the app and this at the same time, is there anyway to force it to reconnect when it loses connection due to using the app? I see in the logs it starts getting authentication failed messages. I know I can reload the integration and that logs it back in, but otherwise it just sits there in a failed state. Would be great to be able to set a timeframe to automatically go back in, if it loses it. :slight_smile:

So the login is renewed if necessary, but only if the initial token is not revoked by using your own credentials on any other place (App or other HA instance, for example).

I may look into this, but is something that I did not explore yet, as I find the app quite cumbersome and the integration, on my own use case, is being way more useful.

Thanks for the feedback.

I’ve only had my MG4 less than a week but this is a fantastic integration, thanks for all your hard work.
I would appreciate a means of the integration automatically re-establishing the connection after being bumped off by someone using the app. Son and daughter also use the car so difficult to prevent someone logging on from time to time.
Probably a configurable time delay before re-enabling the integration and bumping them off the app would be best😀

Thanks again,
Steve

Thanks for the feedback.

Sure, I will try to look into it and see if I may get a workaround for that.

Cheers

What an amazing, usefull integration on HA.

I’m a MG4 owner too from Taiwan, When I try to add to my HA, the Phone Login information doesn’t include Taiwan’s country code(+886), so the setup can’t proceed, is there any fix for Taiwan users? that would be very grateful!

note: Region of Taiwan’s MG App called "My MG, it’s similar to your iSmart but not the same one.

I appreciate your patience in reading. I can assist you in testing so all MG4 users in Taiwan can use it smoothly. Thank you very much.

@PizA

Hi. I can add the country code to the list, but I am not sure on which server your vehicle’s information is. I’ve added all country codes that appear on the iSmart app, which leads me to think that those are the ones where the info we are getting is valid.

So far I know and are tested the servers for Europe and Australia. I’ve an hint on the China server, but Taiwan I am not sure where does that links to. If you are able to get that info, it might be easier to manage.

As the app is different, maybe the server and dataset is also different. But let’s see what can we find and how can we work around it.

Can’t you use the email login?

1 Like

Hi @VaReTaS ,


Using mitmproxy to fetch our MyMG APP’s API requests, and so far as I know, Taiwan’s MG App Server is located in Europe.

However, the login method of the APP does not support email, I think the login information might saved in some other way and then sent to the EU Server

Information such as VIN can be obtained through the API request. Will this be helpful for integration?

Thanks for replying.

Hi @PizA

So seems like your app uses the same endpoint as the whole integration, but only login phone, which shall make it easy to manage.

Since it looks like you can handle this. Are you able to add Taiwan’s country code in const.py on the integration, under country codes, restart Home Assistant and check if you are able to login?

If you follow the same code pattern, once you restart you’ll have the Taiwan option.

If you are able to get it login, I will then add Taiwan to the country code list.

If you have any trouble, let me know.

@PizA

Were you able to test on your instance if by adding Taiwan’s country code you were able to login?

Cheers

Hi everyone,

Latest updates to the integration currently on release 0.7.1.

There was a long way (although in a short period) with a lot of changes, new sensors, adaptations and modifications to get this integration better with every release. I hope that is now being better for all of you and that is improving your experience.

Any feedback will be appreciated.

in addition, sorry I do not come here with every update, but here is a list of the latest changes since the last announcement on 0.4.4.

0.7.1

  • Revise Update Interval scheme. Now correctly set to default after Charging or Powered On Vehicle.
  • Add new Next Update Time sensor.

0.7.0

WHAT’S NEW

  • Revise backend code to re-login if authentication token expired
    • Useful if you used the app and still want HA to get updated data.
  • Refactor update intervals schedule and internal management update (closes #50) (hope it closes #48)
  • Added new Update Interval for Powered On vehicle (default 15 minutes)
  • Added Last Key Seen sensor (from #47)
  • Added Last Update Time sensor (closes #49)
    • This sensor will show the time elapsed since the last successful data update

WHAT’S CHANGED

  • Refactor AC and Climate Commands (from #47)
    • Climate Control status revised and working (closes #44)
    • Previous Start AC button replaced by AC Blowing Switch (closes #44) :triangular_flag_on_post:
    • Ensure that all switches have their status updated
  • Fix Rear Window Defrost (from #47) :triangular_flag_on_post:
    • This has been transformed into a switch.
    • Now with possibility to turn on and off, with updated status
  • Change Front Defrost from button to switch :triangular_flag_on_post:
    • Now with possibility to turn on and off, with updated status
  • Move “Open Boot” button to Lock, to avoid accidental calls. (from #47) :triangular_flag_on_post:
    • This only works to unlock. Lock has to be done manually on the vehicle, as the API do not allow for boot closure.
  • Rename Battery Voltage to Ancillary Battery Voltage (from #47)

BACKEND CHANGES

  • Revise code and sort classes alphabetically, for better understanding, and breakdown by data type (status, charging, etc…)
  • Reorganize and refactor some code sections to improve handling and performance
  • Update EN and ES translation files

0.6.2

  • Adjust Current and Voltage Factors for BMS data (closes #33)
  • Adjust Charging Current Sensor formula for BMS data (closes #33)
  • Adjust Charging Power Sensor for BMS data (closes #33)

0.6.1

  • Revise Power Usage Since Last Charge correction factor.
  • Revise Total Battery Capacity state class to correct Warning message from HA. (closes #43)

0.6.0

  • Reorganize Sensor definitions
  • Revise Electric Range sensor. Obtain data from Charging Data with fallback on Vehicle Status (closes #41)
  • Added Sensors:
    • Total Battery Capacity
    • Power Mode
  • Added Binary Sensors:
    • Engine Status
    • Dipped Beam Status
    • Main Beam Status
    • Side Lights Status
    • Wheel Tyre Monitor Status

0.5.2

  • Fix vehicle type being override automatically
  • Add new services and switches:
    • Sunroof
    • Charging Port Lock
  • Update translations
  • Minor fixes

0.5.1

  • Fix vehicle type being override automatically. Get vehicle type defined in config flow.

0.5.0

  • Refactor API data access. Build access blocks for Info, Status and Charging Data and separate failsafe updates.
  • Redefined retry mechanisms. Each dataset is now accessed and retried separately.
  • Refactor and separate sensors and entities setup and updates by dataset.
  • Failsafe start. All sensors and entities shall be created and wait for updates, even if data is not available.
  • Failsafe start exception to Basic Vehicle Info, which will result on integration not being deployed on first setup…
  • Revise GPS sensor setup and update

0.4.8

  • Revise initial setup process and handling of generic responses.
  • Limit maximum duration of retries under constant generic responses situation.
  • Add missing country codes to Phone Login on configuration process.

0.4.7

  • Refactor endpoints definition on API access to be region specific
  • Add endpoint for Australia/New Zealand
  • Fix charging switch status (On/Off), based on vehicle status
  • Fix exception handling for generic responses and exception for cancelled tasks
  • Fix minor translation issues
  • Fix Charging Duration sensor decimal correction
  • Add Debug log for Generic Charging Data response Debug log

0.4.6

  • Fix generic responses being parsed and not caught in exception

0.4.5

  • Revise code for setup of Fuel Level and Fuel Range sensors on ICE vehicles
  • Add new “Update Vehicle Data” service, for manual updates
  • Add new “Update Vehicle Data” button
  • Refactor Generic Response handling and retrying to trigger on manual updates
  • Improve exceptions’ handling on Generic Responses
  • Revise translations and typos
3 Likes

Thanks for adding the re-login feature! Will let you know how I get on. :slight_smile:

No worries. Let me know if you find any issue.

1 Like