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 23 forks source link

Help for INSTALLATION in Homeassistant #194

Closed karl1809 closed 7 months ago

karl1809 commented 7 months ago

I am a Beginner with Homeassistant. I have an MG5 and wanted install your Installation.

The Intagration with the userinterface of Homeassistant was not successful.

Then I tried to download zip-file and copied it in to the folder \192.168.0.179\config\custom_components
of Homeassistant Then I tried $ python ./mqtt_gateway.py -m tcp://my-broker-host:1883 -u -p Unfortunatly without success.

Please help me. How can install your MG-Integration in Homeassistant.

Tonio16 commented 7 months ago

Hello (a nice to have stuff)

On which type of computer are you running HA? Do you know docker? Did you try the install methods listed in the github?

Because the use of the service is not depending of HA. I am using it with jeedom for example. It just has to run and to have access to the internet. To use the service, you have to install a mqtt broker and for easiness of use, to activate mqtt discovery in the service configuration file.

Antoine

nanomad commented 7 months ago

@karl1809 For HA there's an add-on available

https://github.com/SAIC-iSmart-API/saic-home-assistant-addon

karl1809 commented 7 months ago

Hello Tonio16, hallo nanomad, thank you a lot for your help. I couldnow successful install the addon, but there are still errors and no connection . I can find a device "saic" in homeassistant but no integration. My inputs are "name", "pass" and "telefon". Are there other inputs strongly necessary?

I have installet Mosquito-MQTT-Broker in Homeassistant

2024-03-16 12:41:35,356 [ INFO ] [CONNECTION MADE] - gmqtt.mqtt.protocol 2024-03-16 12:41:35,357 [WARNING ] [CONNACK] 0x5 - gmqtt 2024-03-16 12:41:35,358 [ INFO ] [CONN CLOSE NORMALLY] - gmqtt.mqtt.protocol 2024-03-16 12:41:35,358 [ INFO ] [RECONNECT] ignored error while disconnecting, trying to reconnect anyway - gmqtt 2024-03-16 12:41:35,358 [ ERROR ] Exception in callback MqttPackageHandler._handle_exception_in_future(>) handle: <Handle MqttPackageHandler._handle_exception_in_future(>)> - asyncio Traceback (most recent call last): File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/base_events.py", line 684, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/usr/src/app/./mqtt_gateway.py", line 395, in run await self.publisher.connect() File "/usr/src/app/mqtt_publisher.py", line 83, in connect await self.client.connect(host=self.host, port=self.port, version=gmqtt.constants.MQTTv311, ssl=ssl_context) File "/usr/local/lib/python3.12/site-packages/gmqtt/client.py", line 235, in connect raise self._error gmqtt.mqtt.handler.MQTTConnectError: code 5 (Connection Refused: not authorised)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.12/asyncio/events.py", line 84, in _run self._context.run(self._callback, *self._args) File "/usr/local/lib/python3.12/site-packages/gmqtt/mqtt/handler.py", line 217, in _handle_exception_in_future if future.exception(): ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/gmqtt/client.py", line 255, in reconnect async def reconnect(self, delay=False): asyncio.exceptions.CancelledError 2024-03-16 12:41:41,368 [ INFO ] [CONNECTION MADE] - gmqtt.mqtt.protocol 2024-03-16 12:41:41,370 [WARNING ] [CONNACK] 0x5 - gmqtt 2024-03-16 12:41:41,372 [ INFO ] [CONN CLOSE NORMALLY] - gmqtt.mqtt.protocol Traceback (most recent call last): File "/usr/src/app/./mqtt_gateway.py", line 855, in asyncio.run(mqtt_gateway.run(), debug=debug_log_enabled()) File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/base_events.py", line 684, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/usr/src/app/./mqtt_gateway.py", line 395, in run await self.publisher.connect() File "/usr/src/app/mqtt_publisher.py", line 83, in connect await self.client.connect(host=self.host, port=self.port, version=gmqtt.constants.MQTTv311, ssl=ssl_context) File "/usr/local/lib/python3.12/site-packages/gmqtt/client.py", line 235, in connect raise self._error gmqtt.mqtt.handler.MQTTConnectError: code 5 (Connection Refused: not authorised) 2024-03-16 12:41:41,390 [ ERROR ] Task was destroyed but it is pending! task: <Task pending name='Task-9' coro=<Client.reconnect() done, defined at /usr/local/lib/python3.12/site-packages/gmqtt/client.py:255> wait_for=> - asyncio 2024-03-16 12:41:41,402 [ ERROR ] Task was destroyed but it is pending! task: <Task pending name='Task-1' coro=<Client._resend_qos_messages() running at /usr/local/lib/python3.12/site-packages/gmqtt/client.py:176>> - asyncio sys:1: RuntimeWarning: coroutine 'Client._resend_qos_messages' was never awaited


"bc8a9ee2_saic_python_mqtt_gateway": { "name": "SAIC MQTT Gateway (Python)", "slug": "bc8a9ee2_saic_python_mqtt_gateway", "version": "0.5.15", "version_latest": "0.5.15", "update_available": false, "state": "error", "repository": "SAIC iSmart API Home Assistant Add-on", "icon": true, "auto_update": true, "changelog": "# SAIC MQTT Gateway (Python)\n\nAttention: With 0.5.x the saic gateway uses the new API version. Please switch to legacy version if the new API doesn't work for you!\n\n## 0.5.15\n\n### Fixed\n\n Battery capacity for MG5 SR Comfort\n\n## 0.5.14\n\n### Fixed\n\n Report correct total battery capacity for the MG4 Throphy Extended Range (Fixes #152)\n \n## 0.5.10\n\n### Added\n\n MQTT: Add support for scheduled battery heating. Payload is JSON with startTime and mode (on or off)\n HA: Expose scheduled battery heating\n HA: Expose some switches as sensors as well to ease automations\n\n## 0.5.9\n\n### Added\n\n MQTT: Add support for battery heating. True means ON, False means OFF\n HA: Expose battery heating as an ON-OFF switch\n\n## 0.5.8\n\n### Added\n\n MQTT: Add support for heated seats control on both front left and front right seats. Values range from 0-3 on some\n models, 0-1 on others. 0 means OFF\n HA: Expose heated seats control as either a select with 4 states (OFF, LOW, MEDIUM, HIGH) or as a ON-OFF switch\n depending on the reported car feature set\n\n## 0.5.7 \n\n### Fixed\n\n Align some vehicle control commands to their actual behavior on the official app\n Door closing command should be more reliable now\n\n### Added\n\n The new option SAIC_PHONE_COUNTRY_CODE can be used to specify the country code for the phone number used to login\n\n## 0.5.2\n\n### Fixed\n\n Gateway was not logging-in properly after a logout\n\n### Changed\n\n Config option SAIC_REST_URI now points to the new production API endpoint by default\n\n### Added\n\n Config option SAIC_REGION is used to select the new API region\n Config option SAIC_TENANT_ID is used to select the new API tenant\n\nBoth values default to the EU instance production values\n\n### Removed\n\n Drop config option SAIC_URI as it is no longer relevant\n\n## 0.5.1\n\n### Fixed\n\n Typo in check_for_new_essages() fixed\n\n### Added\n\n Configurable messages-request-interval\n\n## 0.5.0\n\n### Changed\n\n Switch to saic-python-client-ng library (New SAIC API)\n blowing only command fixed\n\n## 0.4.7\n\n### Changed\n\n Whenever a chargingValue is received that is different from the last received value, a forced refresh is performed\n The socTopic is an optional field in the charging station configuration\n\n## 0.4.6\n\n### Fixed\n\n Detection of battery type\n Remove special characters from username to generate valid MQTT topics\n Setting ha_discovery_enabled to False had no effect\n Docker image based on python:3.11-slim\n Force refresh by charging station only if charging value has changed\n MQTT connection error logging \n Front window heating enables \"Blowing only\"\n\n## 0.4.5\n\n### Fixed\n\n Binary string decoding issue fixed in saic-python-client 1.6.5\n \n## 0.4.4\n\n### Fixed\n\n Error message decoding issue fixed in saic-python-client 1.6.4\n\n## 0.4.3\n\n### Fixed\n\n Previous fix corrects dispatcher message size for V2 messages. Now it is also fixed for V1 messages.\n\n## 0.4.2\n\n### Fixed\n\n Previous fix works only for messages without application data. Those are typically error messages that are provided with wrong dispatcher message size\n\n## 0.4.1\n\n### Fixed\n\n Calculate dispatcher message size and use the calculated value if it differs from the provided API value\n \n## 0.4.0\n\n### Added\n\n Control charge current limit\n Dynamic refresh period during charging\n Force polling around scheduled charging start\n Further A/C enhancements\n Generic charging station integration (OPENWB_LP_MAP argument is deprecated now)\n TLS support\n\n## 0.3.0\n\n### Added\n\n Keep polling for a configurable amount of time after the vehicle has been shutdown\n Battery (SoC) target load\n Start/Stop charging\n Enhanced A/C control\n Turn off message requests when refresh mode is off\n Home Assistant auto-discovery\n\n### Fixed\n\n Vehicle and charging status updates stop after a while\n Inconsistent topic name for battery management data (BMS) removed\n\n## 0.2.4\n\n### Added\n\n docker support for architecture linux/arm/v7\n\n## 0.2.3\n\n### Added\n\n Using new saic-ismart-client (version 1.3.0)\n Feature: transmit ABRP data even if we have no GPS data\n\n### Fixed\n\n empty environment variables are ignored\n Driving detection fixed\n\n## 0.2.2\n\nVehicle control commands are finally working\n\n### Added\n\n Turn front window defroster heating on or off\n Turn A/C on or off\n Configurable re-login delay\n Using new saic-ismart-client (version 1.2.6)\n Environment variable to configure log level\n\n### Fixed\n environment variable overwrites the predefined default value\n\n## 0.2.1\n\n### Added\n\n MQTT commands documented in README.md\n\n### Changed\n\n Wait 15 seconds (average SMS delivery time) for the vehicle to wake up.\n Using new saic-ismart-client (version 1.1.7)\n\n### Fixed\n\n Make force command more reliable\n\n## 0.2.0\n\n### Changed\n\n- latest to 0.2.0 \n\n### Fixed\n\n- MQTT\n - PRESSURE_TO_BAR_FACTOR corrected\n - remoteClimateState topic corrected\n - Fix possible 'list index out of range' IndexError when processing VIN\u2026 \n - Using latest SAIC iSMART client version\n - force single fetch by MQTT message\n" } },

tosate commented 7 months ago

Hi @karl1809,

the line gmqtt.mqtt.handler.MQTTConnectError: code 5 (Connection Refused: not authorised) looks like your MQTT Broker requires authentication.

Try with:

python ./mqtt_gateway.py -m tcp://my-broker-host:1883 -u SAIC_USER -p SAIC_PASSWORD --mqtt-user MQTT_USER --mqtt-password MQTT_PASSWORD 
Tonno87 commented 7 months ago

Actually the gateway doesn't need an integration. You will find your car in the mqtt integration as a device

karl1809 commented 7 months ago

Thank you a lot for your great help. Now it works after a few trials. I completet MQTT-User and MQTT-Pass and my SAIC-Username (=HandyNo without country-Code) and my SAIC-Pass. My country-code (49) I put in in a separate line.