Skip to content

Commit

Permalink
Merge pull request #1531 from okaegi/acthor100
Browse files Browse the repository at this point in the history
acthor leistungsabfrage
  • Loading branch information
benderl committed Aug 20, 2021
2 parents 88f2f8f + 9a16a6a commit 3d2fcbd
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions modules/smarthome/acthor/watt.py
Expand Up @@ -40,34 +40,28 @@
faktor = 6000/instpower
else:
faktor = 3000/instpower
pvmodus = 0
if os.path.isfile(file_stringpv):
f = open( file_stringpv , 'r')
pvmodus =int(f.read())
f.close()
powerc = 0
# aktuelle Leistung lesen
client = ModbusTcpClient(ipadr, port=502)
#
#
start = 1000
resp=client.read_holding_registers(start,10,unit=1)
value1 = resp.registers[0]
all = format(value1, '04x')
aktpower= int(struct.unpack('>h',codecs.decode(all, 'hex'))[0])
if count5==0:
# pv modus
pvmodus = 0
if os.path.isfile(file_stringpv):
f = open( file_stringpv , 'r')
pvmodus =int(f.read())
f.close()
# log counter
count1 = 999
if os.path.isfile(file_stringcount):
f = open( file_stringcount , 'r')
count1 =int(f.read())
f.close()
count1=count1+1
# aktuelle Leistung lesen
client = ModbusTcpClient(ipadr, port=502)
#
#
start = 1000
resp=client.read_holding_registers(start,10,unit=1)
#
#start = 3524
#resp=client.read_input_registers(start,10,unit=1)
#
value1 = resp.registers[0]
all = format(value1, '04x')
#aktpower= int(struct.unpack('>h', all.decode('hex'))[0])
aktpower= int(struct.unpack('>h',codecs.decode(all, 'hex'))[0])
value1 = resp.registers[3]
all = format(value1, '04x')
status= int(struct.unpack('>h',codecs.decode(all, 'hex') )[0])
Expand Down Expand Up @@ -110,7 +104,6 @@
# test only
#json return power = aktuelle Leistungsaufnahme in Watt, on = 1 pvmodus, powerc = counter in kwh
#answer = '{"power":225,"on":0} '
powerc = 0
answer = '{"power":' + str(aktpower) + ',"powerc":' + str(powerc) + ',"on":' + str(pvmodus) + '} '
f1 = open('/var/www/html/openWB/ramdisk/smarthome_device_ret' + str(devicenumber), 'w')
json.dump(answer,f1)
Expand All @@ -136,3 +129,10 @@
f = open( file_stringcount , 'w')
f.write(str(count1))
f.close()
else:
if pvmodus == 99:
pvmodus = 0
answer = '{"power":' + str(aktpower) + ',"powerc":' + str(powerc) + ',"on":' + str(pvmodus) + '} '
f1 = open('/var/www/html/openWB/ramdisk/smarthome_device_ret' + str(devicenumber), 'w')
json.dump(answer,f1)
f1.close()

0 comments on commit 3d2fcbd

Please sign in to comment.