API integration

I got this working on my MG4 today although some of the numbers are a bit strange so will need some investigation but this has great potential for a nice dashboard

1681732417325.png
 
Hi All,
I am trying this one now but no luck.
Maybe you guys could shed some light...

added repository:

Installed both python and java version and run they both and separately for testing - all the same

Java doesnt have any logs rather than initial ones.
Python logs:
2023-05-24 13:35:58,780 Registering for abnormal messages
2023-05-24 13:35:58,968 Registering for moving messages
2023-05-24 13:35:59,151 Registering for region messages
2023-05-24 13:35:59,337 Registering for engineStart messages
2023-05-24 13:35:59,521 Registering for startVehicleStatus messages
2023-05-24 13:35:59,715 Registering for offCar messages
2023-05-24 13:35:59,900 Registering for speeding messages
2023-05-24 13:36:18,408 last activity: 2023-05-24 13:36:18
2023-05-24 13:36:18,584 0 messages received
2023-05-24 13:37:18,804 0 messages received
2023-05-24 13:38:19,007 0 messages received
2023-05-24 13:39:19,247 0 messages received
2023-05-24 13:40:19,463 0 messages received
2023-05-24 13:41:19,645 0 messages received
2023-05-24 13:42:19,854 0 messages received

Whats the difference between Java/Python versions??

I got kicked out of my phone app so I figure SAIC usr/passwd all good.
mosquitto borker running in HA for other apps as localhost so should be fine - should I set it in any particular way?
I am in EU so SAIC_URI left blank (use default)
What else am I missing?
How do I get the entities? Does it appear under MQTT integration?


Sorry about lots of questions but documentation for this one is very supperficial and I could not find more relevant info.
Examples of your config would be great
Any help welcome

Thanks
Dan
 
Hi All,
I am trying this one now but no luck.
Maybe you guys could shed some light...

added repository:

Installed both python and java version and run they both and separately for testing - all the same

Java doesnt have any logs rather than initial ones.
Python logs:
2023-05-24 13:35:58,780 Registering for abnormal messages
2023-05-24 13:35:58,968 Registering for moving messages
2023-05-24 13:35:59,151 Registering for region messages
2023-05-24 13:35:59,337 Registering for engineStart messages
2023-05-24 13:35:59,521 Registering for startVehicleStatus messages
2023-05-24 13:35:59,715 Registering for offCar messages
2023-05-24 13:35:59,900 Registering for speeding messages
2023-05-24 13:36:18,408 last activity: 2023-05-24 13:36:18
2023-05-24 13:36:18,584 0 messages received
2023-05-24 13:37:18,804 0 messages received
2023-05-24 13:38:19,007 0 messages received
2023-05-24 13:39:19,247 0 messages received
2023-05-24 13:40:19,463 0 messages received
2023-05-24 13:41:19,645 0 messages received
2023-05-24 13:42:19,854 0 messages received

Whats the difference between Java/Python versions??

I got kicked out of my phone app so I figure SAIC usr/passwd all good.
mosquitto borker running in HA for other apps as localhost so should be fine - should I set it in any particular way?
I am in EU so SAIC_URI left blank (use default)
What else am I missing?
How do I get the entities? Does it appear under MQTT integration?


Sorry about lots of questions but documentation for this one is very supperficial and I could not find more relevant info.
Examples of your config would be great
Any help welcome

Thanks
Dan
Python looks good, it's waiting for your engine so actually it has 0 messages received. If you drive there will be a message every 30 seconds.
At the moment you need to create mqtt sensors yourself. I'm working on an integration, but doesn't have much time at the moment. I will finish the wiki in the next few days. You can find the structure here:

 
Last edited:
Python looks good, it's waiting for your engine so actually it has 0 messages received. If you drive there will be a message every 30 seconds.
At the moment you need to create mqtt sensors yourself. I'm working on an integration, but doesn't have much time at the moment. I will finish the wiki in the next few days. You can find the structure here:

Cool, Thanks.

I will follow: MQTT Sensor

Any pointer on how to create it for this addon?
All I need at the moment is battery % for a car charging automation Im running.

I will keep an ey for an integration before going further....

Really appreciated, thanks
Dan
 
Cool, Thanks.

I will follow: MQTT Sensor

Any pointer on how to create it for this addon?
All I need at the moment is battery % for a car charging automation Im running.

I will keep an ey for an integration before going further....

Really appreciated, thanks
Dan
Try the following configuration with the python gateway:

sensor:
- name: mg5_soc
unique_id: uniqueid__mg5_soc
state_topic: "saic/[email protected]/vehicles/LSJE2XXXXXXXXXX/drivetrain/soc"
value_template: "{{ value }}"
unit_of_measurement: "%"

Additionally you will need the following topic to refresh your soc:

select:
- name: "MQTT Gateway Refresh Mode"
unique_id: uniqueid__saic_mqtt_gateway_refresh_mode
state_topic: "saic/[email protected]/vehicles/LSJE2XXXXXXXXXX/refresh/mode/set"
command_topic: "saic/[email protected]/vehicles/LSJE2XXXXXXXXXX/refresh/mode/set"
options:
- "periodic"
- "off"
- "force"

Note: You have to send "force" to the command topic to refresh your soc, automatic mode only works while driving! If you only need it for charging you should set it to off and use the force command to refresh.

number:
- name: mqtt_gateway_active_refresh
unique_id: uniqueid__mqtt_gateway_active_refresh
state_topic: "saic/saic/[email protected]/vehicles/LSJE2XXXXXXXXXX/refresh/period/active"
command_topic: "saic/saic/[email protected]/vehicles/LSJE2XXXXXXXXXX/refresh/period/active/set"
mode: "box"
max: "86400"

Note: You can change the value of the automatic refresh time. Default is 30s.
At the moment all these settings are not persistent!


Have fun :)
 
While this is cool, I'd be tempted to keep an eye on the 12v battery voltage in the car while using non-standard software - pinging it every 30s could stop the electronics in the car from going to sleep.
 
While this is cool, I'd be tempted to keep an eye on the 12v battery voltage in the car while using non-standard software - pinging it every 30s could stop the electronics in the car from going to sleep.
Yep I read it in a different addon Im trying as well
(GitHub - ReverseEngineeringDE/iSmart-Gateway-Home-Assistant-Add-on: This repository allows Home Assistant users to access the data of their MG5 electric (2022) car via the iSmart/iSmart lite API.)

Not sure what the main differences are but looks this one get data straight from the rest api while tonno's go thru mqtt some how (?)

Anyway, happy to test and learn but full implementation only when there is an integration and some sort of control on how often we wake up the whole thing...

if possible to get it from api, it would be good to get the state of the 12v battery for monitoring/security...

I had my batterry dying on me before for some reason (if doesnt go to sleep, it drains the 12v quite fast)...
 
Okay, I try to clarify some things:

The main difference is that the old add-on was based on http requests. No manual request, no data! There is no internal logic to prevent battery drain.

The idea behind the mqtt gateway is to provide the data to every system you want over mqtt. Additionaly the python gateway has a internal logic to prevent battery drain. While in periodic mode the gateway watches for engine on messages from ismart to start pulling your data.
As long as the engine is off it doesn't pull any data from the car.

If you set the mode to off it stops any automatic pulling.

If you charge your car, ismart cannot wake the gateway to pull data. So you have to do it with the force command.

Hope this helps :)
 
Following this with much interest. I run Home Assistant but have no MG (yet) to experiment with.

I was looking into a scripting a simple DIY PV only charge setup (i.e. similar to a Zappi that uses only excess Solar capacity, but using basic charging hardware or even the granny cable).

Does anyone know if MG4 (and therefore hopefully at some point this API) allows you to limit the kW charge rate when charging via AC/granny?
 
Following this with much interest. I run Home Assistant but have no MG (yet) to experiment with.

I was looking into a scripting a simple DIY PV only charge setup (i.e. similar to a Zappi that uses only excess Solar capacity, but using basic charging hardware or even the granny cable).

Does anyone know if MG4 (and therefore hopefully at some point this API) allows you to limit the kW charge rate when charging via AC/granny?
as far as I know you can't charge a full electric car with granny cables (hybrids only) , you need a charging station... too much juice/s (amps)!
it could technically work but if catches fire, insurance will bail...
 
as far as I know you can't charge a full electric car with granny cables (hybrids only) , you need a charging station... too much juice/s (amps)!
it could technically work but if catches fire, insurance will bail...
Completely incorrect. You can fully charge an electric car using plug-in chargers. We have been doing it for the last 2 months while we have been sorting a charger.

Yes you need to be carefully about what you're plugging it into as it will pull a constant high current draw but provided you have good wiring it will be fine i.e. ours is plugged into a socket which is 1 cable from the main consumer unit.

As for insurance bailing, on what grounds? I plugged something into a plug to the BS standards and there was a fire? Insurance would have no grounds not to pay out but I think the bigger issue is more your house has burnt down.
 
agreed RobQuads. Not concerned about using a granny cable here, my expected daily use is fairly low km/s so even a slow charge on a cloudy day would still be able to top up the car for me.

My query was the granny pulls maybe 7 amps, and I was wondering if there is a software option in the car to set/change the charging amps value so HA could respond to variations in excess available solar by setting the charge rate up or down.

Example below, obviously this requires the vehicle to support updating charge amps:
 
as far as I know you can't charge a full electric car with granny cables (hybrids only) , you need a charging station... too much juice/s (amps)!
it could technically work but if catches fire, insurance will bail...
Incorrect. You absolutely can charge a BEV with a granny cable, it will just take ages.
ev-database.org quote the MG4 SE LR & Trophy as taking 31h45m to fully charge on a granny cable.
 
My query was the granny pulls maybe 7 amps, and I was wondering if there is a software option in the car to set/change the charging amps value so HA could respond to variations in excess available solar by setting the charge rate up or down.
Under the Battery tile on the Charge tab, there's an option to select the maximum charge current. From memory these are 6A, 10A, 16A and Maximum. The one time I used the granny lead I just left it at Maximum, as the granny lead control box set the charge current.
 

Are you enjoying your MG4?

  • Yes

    Votes: 518 79.2%
  • I'm in the middle

    Votes: 89 13.6%
  • No

    Votes: 47 7.2%
Support us by becoming a Premium Member

Latest MG EVs video

MG3 Hybrid+ & Cyberster Configurator News + hot topics from the MG EVs forums
Subscribe to our YouTube channel
Back
Top Bottom