Skip to content

Commit

Permalink
idm ....
Browse files Browse the repository at this point in the history
Aktuelle Leistung wird nun bei jedem Durchlauf gelesen.
Pv Leistung wird nun immer geschrieben (egal ob Gerät on oder off ist)
Variablen zentral initialisiert
  • Loading branch information
okaegi committed Aug 6, 2023
1 parent e4b372b commit c9a8fcc
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions packages/modules/smarthome/idm/watt.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,28 @@
count5 = 0
with open(file_stringcount5, 'w') as f:
f.write(str(count5))
# aktuelle Leistung lesen
client = ModbusTcpClient(ipadr, port=502)
# test
# start = 3501
# navvers = "2"
# prod
start = 4122
if navvers == "2":
rr = client.read_input_registers(start, 2, unit=1)
else:
rr = client.read_holding_registers(start, 2, unit=1)
raw = struct.pack('>HH', rr.getRegister(1), rr.getRegister(0))
lkw = float(struct.unpack('>f', raw)[0])
aktpower = int(lkw*1000)
modbuswrite = 0
neupower = 0
# pv modus
pvmodus = 0
if os.path.isfile(file_stringpv):
with open(file_stringpv, 'r') as f:
pvmodus = int(f.read())
if count5 == 0:
# pv modus
pvmodus = 0
if os.path.isfile(file_stringpv):
with open(file_stringpv, 'r') as f:
pvmodus = int(f.read())
# log counter
count1 = 999
if os.path.isfile(file_stringcount):
Expand All @@ -53,22 +69,7 @@
count1 = 0
with open(file_stringcount, 'w') as f:
f.write(str(count1))
# aktuelle Leistung lesen
client = ModbusTcpClient(ipadr, port=502)
# test
# start = 3501
# navvers = "2"
# prod
start = 4122
if navvers == "2":
rr = client.read_input_registers(start, 2, unit=1)
else:
rr = client.read_holding_registers(start, 2, unit=1)
raw = struct.pack('>HH', rr.getRegister(1), rr.getRegister(0))
lkw = float(struct.unpack('>f', raw)[0])
aktpower = int(lkw*1000)
# logik nur schicken bei pvmodus
modbuswrite = 0
if pvmodus == 1:
modbuswrite = 1
# Nur positiven Uberschuss schicken, nicht aktuelle Leistung
Expand Down Expand Up @@ -101,10 +102,6 @@
pvwnew = builder.to_registers()
# json return power = aktuelle Leistungsaufnahme in Watt,
# on = 1 pvmodus, powerc = counter in kwh
answer = '{"power":' + str(aktpower) + ',"powerc":0'
answer += ',"send":' + str(modbuswrite) + ',"sendpower":' + str(neupower)
answer += ',"on":' + str(pvmodus) + '}'
writeret(answer, devicenumber)
if count1 < 3:
log.info(" %d ipadr %s ueberschuss %6d Akt Leistung %6d Pv %6d"
% (devicenumber, ipadr, uberschuss, aktpower, pvwatt))
Expand All @@ -113,7 +110,14 @@
# modbus write
if modbuswrite == 1:
client.write_registers(74, regnew, unit=1)
client.write_registers(78, pvwnew, unit=1)
if count1 < 3:
log.info("devicenr %d ipadr %s device written by modbus " %
(devicenumber, ipadr))
client.write_registers(78, pvwnew, unit=1)
else:
if pvmodus == 99:
pvmodus = 0

Check warning on line 119 in packages/modules/smarthome/idm/watt.py

View workflow job for this annotation

GitHub Actions / build

trailing whitespace
answer = '{"power":' + str(aktpower) + ',"powerc":0'
answer += ',"send":' + str(modbuswrite) + ',"sendpower":' + str(neupower)
answer += ',"on":' + str(pvmodus) + '}'
writeret(answer, devicenumber)

0 comments on commit c9a8fcc

Please sign in to comment.