SAIC-iSmart-API / saic-python-mqtt-gateway

A service that queries the data from an MG iSMART account and publishes the data over MQTT and to other sources
MIT License
71 stars 21 forks source link

charging_stations.json does not recognise when charging has stopped #122

Closed denisfrench closed 8 months ago

denisfrench commented 9 months ago

Expected behaviour:

When the gateway receives a payload on the chargeStateTopic topic that is not equal to chargingValue, the binary_sensor.<REDACTED>_battery_charging sensor should be changed to off, and/or a forced refresh performed to confirm the vehicle charging state.

Actual behaviour:

A payload that is not equal to chargingValue does not appear to change any sensors, or force a refresh. The gateway logs and HA sensors continue to indicate the vehicle is charging until the next periodic update. At low charge rates (eg when linked to solar output) it may take 20mins or half an hour for the gateway and sensors to be re-synced with the vehicle state.

System:

SAIC MQTT Gateway (Python) version: 0.4.6 Core 2023.12.4 Supervisor 2023.12.0 Operating System 11.2 MG4 77kWh

Log extract:

Vehicle had been charging (payload 3). Charging was disabled from OpenEVSE web interface (payload 254), with no change in sensor state or forced update.

2023-12-28 17:17:11,403 [ DEBUG  ] HV battery is charging. Should refresh: False - vehicle
2023-12-28 17:17:12,407 [ DEBUG  ] HV battery is charging. Should refresh: False - vehicle
2023-12-28 17:17:13,411 [ DEBUG  ] HV battery is charging. Should refresh: False - vehicle
2023-12-28 17:17:13,802 [ DEBUG  ] Received message over topic openevse/state with payload 254 - mqtt_publisher  ### Multiple previous identical rows indicating OpenEVSE charging disabled.
2023-12-28 17:17:13,803 [ DEBUG  ] Received message over topic openevse/vehicle with payload 1 - mqtt_publisher
2023-12-28 17:17:13,804 [ DEBUG  ] Vehicle with vin LSJ<REDACTED> is connected to its charging station - mqtt_publisher
2023-12-28 17:17:14,414 [ DEBUG  ] HV battery is charging. Should refresh: False - vehicle
2023-12-28 17:17:15,418 [ DEBUG  ] HV battery is charging. Should refresh: False - vehicle
2023-12-28 17:17:15,519 [ DEBUG  ] Received message over topic openevse/state with payload 2 - mqtt_publisher  ### OpenEVSE switched back to solar divert mode (not charging yet).
2023-12-28 17:17:15,520 [ DEBUG  ] Received message over topic openevse/vehicle with payload 1 - mqtt_publisher
2023-12-28 17:17:15,520 [ DEBUG  ] Vehicle with vin LSJ<REDACTED>is connected to its charging station - mqtt_publisher
2023-12-28 17:17:16,422 [ DEBUG  ] HV battery is charging. Should refresh: False - vehicle
2023-12-28 17:17:17,426 [ DEBUG  ] HV battery is charging. Should refresh: False - vehicle
2023-12-28 17:17:18,283 [ DEBUG  ] Received message over topic openevse/state with payload 3 - mqtt_publisher  ### OpenEVSE initiates charging based on solar output.
2023-12-28 17:17:18,284 [ DEBUG  ] Charging value has changed from 2 to 3. - mqtt_publisher
2023-12-28 17:17:18,284 [ DEBUG  ] Vehicle with vin LSJ<REDACTED>is charging. Setting refresh mode to force - mqtt_publisher
2023-12-28 17:17:18,285 [  INFO  ] Setting refresh mode to force - vehicle
2023-12-28 17:17:18,286 [ DEBUG  ] Refresh mode set to force - vehicle
2023-12-28 17:17:18,287 [ DEBUG  ] Received message over topic openevse/vehicle with payload 1 - mqtt_publisher
2023-12-28 17:17:18,287 [ DEBUG  ] Vehicle with vin LSJ<REDACTED>is connected to its charging station - mqtt_publisher
2023-12-28 17:17:18,430 [  INFO  ] Setting refresh mode to periodic - vehicle
2023-12-28 17:17:18,431 [ DEBUG  ] Refresh mode set to periodic - vehicle
2023-12-28 17:17:18,432 [  INFO  ] Updating vehicle status - __main__

It would be very helpful for the binary_sensor.<REDACTED>_battery_charging sensor to be updated by the charging_stations.json implementation in near-realtime, to provide immediate feedback when charging is stopped. I have created a dashboard within HA to improve on the phone app and get around the single user problem, but at this time the dashbaord is put out of sync with the vehicle state whenever charging is stopped.

tosate commented 9 months ago

Hi @denisfrench

this is a valid point, thank you! I will force the refresh whenever a chargingValue is received that is different from the last received value.

denisfrench commented 8 months ago

Thanks for coming up with the solution so quickly!

Apologies for not providing feedback sooner, which was complicated by my setup which resulted in a race condition that I had to work through.

I've developed a workaround which unfortunately required disabling charging_stations.json and instead using HA automations.

To be clear; this issue/FR is not the root cause. I'll therefore close this issue as fixed.