Skip to content

Commit 1563670

Browse files
committed
* 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`
1 parent 950eab3 commit 1563670

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v0.1.0
4+
* Added: Device name can be changed in the `config.ini`
5+
* Added: Device instance can be changed in the `config.ini`
6+
* Added: How to create multiple instances in `README.md`
7+
* Changed: Topic variable name in `config.ini`
8+
39
## v0.0.2
410
* Added: Set logging level in `config.default.ini`
511
* Changed: Logging levels of different messages for clearer output

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,26 @@ If the seconds are under 5 then the service crashes and gets restarted all the t
146146

147147
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.
148148

149+
### Multiple instances
150+
151+
It's possible to have multiple instances, but it's not automated. Follow these steps to achieve this:
152+
153+
1. Save the new name to a variable `driverclone=dbus-mqtt-grid-2`
154+
155+
2. Copy current folder and add a number `cp -r /data/etc/dbus-mqtt-grid/ /data/etc/$driverclone/`
156+
157+
3. Rename the main script `mv /data/etc/$driverclone/dbus-mqtt-grid.py /data/etc/$driverclone/$driverclone.py`
158+
159+
4. Fix the script references for service and log
160+
```
161+
sed -i 's:dbus-mqtt-grid:'$driverclone':g' /data/etc/$driverclone/service/run
162+
sed -i 's:dbus-mqtt-grid:'$driverclone':g' /data/etc/$driverclone/service/log/run
163+
```
164+
165+
5. Change the `device_name` and increase the `device_instance` in the `config.ini`
166+
167+
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.
168+
149169
### Compatibility
150170
151171
It was tested on Venus OS Large `v2.92` on the following devices:

dbus-mqtt-grid/config.sample.ini

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
; default: WARNING
1212
logging = WARNING
1313

14+
; Device name
15+
; default: MQTT Grid
16+
device_name = MQTT Grid
17+
18+
; Device VRM instance
19+
; default: 31
20+
device_instance = 31
21+
1422
; used when no voltage is received
1523
voltage = 230
1624

@@ -43,6 +51,6 @@ broker_port = 1883
4351
; Password used for connection
4452
;password = mypassword
4553

46-
; Topic where the meters data as JSON string is published
54+
; Topic where the grid data as JSON string is published
4755
; minimum required JSON payload: {"grid": { "power": 0.0 } }
48-
topic_meters = enphase/envoy-s/meters
56+
topic = enphase/envoy-s/meters

dbus-mqtt-grid/dbus-mqtt-grid.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def on_connect(client, userdata, flags, rc):
9898
if rc == 0:
9999
logging.info("MQTT client: Connected to MQTT broker!")
100100
connected = 1
101-
client.subscribe(config['MQTT']['topic_meters'])
101+
client.subscribe(config['MQTT']['topic'])
102102
else:
103103
logging.error("MQTT client: Failed to connect, return code %d\n", rc)
104104

@@ -112,7 +112,7 @@ def on_message(client, userdata, msg):
112112
grid_L3_power, grid_L3_current, grid_L3_voltage, grid_L3_forward, grid_L3_reverse
113113

114114
# get JSON from topic
115-
if msg.topic == config['MQTT']['topic_meters']:
115+
if msg.topic == config['MQTT']['topic']:
116116
if msg.payload != '' and msg.payload != b'':
117117
jsonpayload = json.loads(msg.payload)
118118

@@ -175,6 +175,7 @@ def __init__(
175175
deviceinstance,
176176
paths,
177177
productname='MQTT Grid',
178+
customname='MQTT Grid',
178179
connection='MQTT Grid service'
179180
):
180181

@@ -192,8 +193,8 @@ def __init__(
192193
self._dbusservice.add_path('/DeviceInstance', deviceinstance)
193194
self._dbusservice.add_path('/ProductId', 0xFFFF)
194195
self._dbusservice.add_path('/ProductName', productname)
195-
self._dbusservice.add_path('/CustomName', productname)
196-
self._dbusservice.add_path('/FirmwareVersion', '0.0.2')
196+
self._dbusservice.add_path('/CustomName', customname)
197+
self._dbusservice.add_path('/FirmwareVersion', '0.1.0')
197198
#self._dbusservice.add_path('/HardwareVersion', '')
198199
self._dbusservice.add_path('/Connected', 1)
199200

@@ -272,7 +273,7 @@ def main():
272273

273274

274275
# MQTT setup
275-
client = mqtt.Client("MqttGrid")
276+
client = mqtt.Client("MqttGrid_" + str(config['MQTT']['device_instance']))
276277
client.on_disconnect = on_disconnect
277278
client.on_connect = on_connect
278279
client.on_message = on_message
@@ -357,8 +358,9 @@ def main():
357358

358359

359360
pvac_output = DbusMqttGridService(
360-
servicename='com.victronenergy.grid.mqtt_grid',
361-
deviceinstance=31,
361+
servicename='com.victronenergy.grid.mqtt_grid_' + str(config['MQTT']['device_instance']),
362+
deviceinstance=int(config['MQTT']['device_instance']),
363+
customname=config['MQTT']['device_name'],
362364
paths=paths_dbus
363365
)
364366

0 commit comments

Comments
 (0)