diff --git a/CHANGELOG.md b/CHANGELOG.md index 656ff01..4ba673b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v0.1.0 +* Added: Device name can be changed in the `config.ini` +* Added: Device instance can be changed in the `config.ini` +* Added: How to create multiple instances in `README.md` +* Changed: Topic variable name in `config.ini` + ## v0.0.2 * Added: Set logging level in `config.default.ini` * Changed: Logging levels of different messages for clearer output diff --git a/README.md b/README.md index 5b8bbe0..127d87c 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,26 @@ If the seconds are under 5 then the service crashes and gets restarted all the t If the script stops with the message `dbus.exceptions.NameExistsException: Bus name already exists: com.victronenergy.grid.mqtt_grid"` it means that the service is still running or another service is using that bus name. +### Multiple instances + +It's possible to have multiple instances, but it's not automated. Follow these steps to achieve this: + +1. Save the new name to a variable `driverclone=dbus-mqtt-grid-2` + +2. Copy current folder and add a number `cp -r /data/etc/dbus-mqtt-grid/ /data/etc/$driverclone/` + +3. Rename the main script `mv /data/etc/$driverclone/dbus-mqtt-grid.py /data/etc/$driverclone/$driverclone.py` + +4. Fix the script references for service and log + ``` + sed -i 's:dbus-mqtt-grid:'$driverclone':g' /data/etc/$driverclone/service/run + sed -i 's:dbus-mqtt-grid:'$driverclone':g' /data/etc/$driverclone/service/log/run + ``` + +5. Change the `device_name` and increase the `device_instance` in the `config.ini` + +Now you can install and run the cloned driver. Should you need another instance just increase the number in step 1 and repeat all steps. + ### Compatibility It was tested on Venus OS Large `v2.92` on the following devices: diff --git a/dbus-mqtt-grid/config.sample.ini b/dbus-mqtt-grid/config.sample.ini index 88123f4..968b15d 100644 --- a/dbus-mqtt-grid/config.sample.ini +++ b/dbus-mqtt-grid/config.sample.ini @@ -11,6 +11,14 @@ ; default: WARNING logging = WARNING +; Device name +; default: MQTT Grid +device_name = MQTT Grid + +; Device VRM instance +; default: 31 +device_instance = 31 + ; used when no voltage is received voltage = 230 @@ -43,6 +51,6 @@ broker_port = 1883 ; Password used for connection ;password = mypassword -; Topic where the meters data as JSON string is published +; Topic where the grid data as JSON string is published ; minimum required JSON payload: {"grid": { "power": 0.0 } } -topic_meters = enphase/envoy-s/meters +topic = enphase/envoy-s/meters diff --git a/dbus-mqtt-grid/dbus-mqtt-grid.py b/dbus-mqtt-grid/dbus-mqtt-grid.py index bae3b77..9779edf 100644 --- a/dbus-mqtt-grid/dbus-mqtt-grid.py +++ b/dbus-mqtt-grid/dbus-mqtt-grid.py @@ -98,7 +98,7 @@ def on_connect(client, userdata, flags, rc): if rc == 0: logging.info("MQTT client: Connected to MQTT broker!") connected = 1 - client.subscribe(config['MQTT']['topic_meters']) + client.subscribe(config['MQTT']['topic']) else: logging.error("MQTT client: Failed to connect, return code %d\n", rc) @@ -112,7 +112,7 @@ def on_message(client, userdata, msg): grid_L3_power, grid_L3_current, grid_L3_voltage, grid_L3_forward, grid_L3_reverse # get JSON from topic - if msg.topic == config['MQTT']['topic_meters']: + if msg.topic == config['MQTT']['topic']: if msg.payload != '' and msg.payload != b'': jsonpayload = json.loads(msg.payload) @@ -175,6 +175,7 @@ def __init__( deviceinstance, paths, productname='MQTT Grid', + customname='MQTT Grid', connection='MQTT Grid service' ): @@ -192,8 +193,8 @@ def __init__( self._dbusservice.add_path('/DeviceInstance', deviceinstance) self._dbusservice.add_path('/ProductId', 0xFFFF) self._dbusservice.add_path('/ProductName', productname) - self._dbusservice.add_path('/CustomName', productname) - self._dbusservice.add_path('/FirmwareVersion', '0.0.2') + self._dbusservice.add_path('/CustomName', customname) + self._dbusservice.add_path('/FirmwareVersion', '0.1.0') #self._dbusservice.add_path('/HardwareVersion', '') self._dbusservice.add_path('/Connected', 1) @@ -272,7 +273,7 @@ def main(): # MQTT setup - client = mqtt.Client("MqttGrid") + client = mqtt.Client("MqttGrid_" + str(config['MQTT']['device_instance'])) client.on_disconnect = on_disconnect client.on_connect = on_connect client.on_message = on_message @@ -357,8 +358,9 @@ def main(): pvac_output = DbusMqttGridService( - servicename='com.victronenergy.grid.mqtt_grid', - deviceinstance=31, + servicename='com.victronenergy.grid.mqtt_grid_' + str(config['MQTT']['device_instance']), + deviceinstance=int(config['MQTT']['device_instance']), + customname=config['MQTT']['device_name'], paths=paths_dbus )