# HG changeset patch # User Daniel O'Connor # Date 1639381599 -37800 # Node ID 91bfaba8f6b67208df51f0898e8745ea5b605966 # Parent a9df202d14b7d40f4ef95c12c39b5f4146832035 Add victron dbus parser diff -r a9df202d14b7 -r 91bfaba8f6b6 victron.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/victron.py Mon Dec 13 18:16:39 2021 +1030 @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import dbus +import time + +class Victron(object): + def __init__(self, obj): + self.obj = obj + self.bus = dbus.SystemBus() + + def get_data(self): + ACIn_L1_volts = self.bus.get_object(self.obj, '/Ac/ActiveIn/L1/V').GetValue().real + ACIn_L1_freq = self.bus.get_object(self.obj, '/Ac/ActiveIn/L1/F').GetValue().real + ACIn_L1_current = self.bus.get_object(self.obj, '/Ac/ActiveIn/L1/I').GetValue().real + ACIn_active = bool(self.bus.get_object(self.obj, '/Ac/ActiveIn/Connected').GetValue()) + ACOut_L1_volts = self.bus.get_object(self.obj, '/Ac/Out/L1/V').GetValue().real + ACOut_L1_freq = self.bus.get_object(self.obj, '/Ac/Out/L1/F').GetValue().real + ACOut_L1_current = self.bus.get_object(self.obj, '/Ac/Out/L1/I').GetValue().real + Battery_Voltage = self.bus.get_object(self.obj, '/Dc/0/Voltage').GetValue().real + Battery_Current = self.bus.get_object(self.obj, '/Dc/0/Current').GetValue().real + return ACIn_L1_volts, ACIn_L1_freq, ACIn_L1_current, ACIn_active, ACOut_L1_volts, ACOut_L1_freq, ACOut_L1_current, Battery_Voltage, Battery_Current + +def main(): + v = Victron('com.victronenergy.vebus.ttyUSB0') + while True: + try: + v.get_data() + except (AttributeError, dbus.exceptions.DBusException) as e: + print('Error getting data, sleeping 30 seconds:', str(e)) + time.sleep(25) + time.sleep(5) + +if __name__ == '__main__': + main()