diff --git a/SunGather/config-example.yaml b/SunGather/config-example.yaml index 19a2e27..014fe66 100644 --- a/SunGather/config-example.yaml +++ b/SunGather/config-example.yaml @@ -64,6 +64,7 @@ exports: # topic: "inverter/{model}/registers" # [Optional] Default: "inverter/{model}/registers", Variable {model} will be replaced with model number of inverter # username: # [Optional] Username is MQTT server requires it # password: # [Optional] Password is MQTT server requires it + # client_id: # [Optional] Client id for mqtt connection. Defaults to "SunGather", need to be set to different values if you want to run multiple instances of sungather. homeassistant: True # [Optional] Default False, Publish discovery and sensors for HomeAssistant ha_sensors: # [Optional] / [Required] ha_discovery: True, Topics to enable discovery for HA - name: "Daily Generation" diff --git a/SunGather/exports/mqtt.py b/SunGather/exports/mqtt.py index 93dcd43..4838fa8 100644 --- a/SunGather/exports/mqtt.py +++ b/SunGather/exports/mqtt.py @@ -11,10 +11,12 @@ class export_mqtt(object): # Configure MQTT def configure(self, config, inverter): + model = inverter.getInverterModel(True) self.mqtt_config = { 'host': config.get('host', None), 'port': config.get('port', 1883), - 'topic': config.get('topic', "inverter/{model}/registers").replace('{model}', inverter.getInverterModel(True)), + 'client_id': config.get('client_id', f'SunGather-{model}'), + 'topic': config.get('topic', f"inverter/{model}/registers"), 'username': config.get('username', None), 'password': config.get('password',None), 'homeassistant': config.get('homeassistant',False) @@ -26,8 +28,8 @@ class export_mqtt(object): if not self.mqtt_config['host']: logging.info(f"MQTT: Host config is required") return False - - self.mqtt_client = mqtt.Client(client_id="SunGather") + client_id = self.mqtt_config['client_id'] + self.mqtt_client = mqtt.Client(client_id) self.mqtt_client.on_connect = self.on_connect self.mqtt_client.on_disconnect = self.on_disconnect self.mqtt_client.on_publish = self.on_publish