From 9a16a6a4f5f96d5e1ea254c28bd64ef7b10b51cb Mon Sep 17 00:00:00 2001 From: okaegi Date: Fri, 20 Aug 2021 18:26:05 +0200 Subject: [PATCH] acthor leistungsabfrage Es wird nun beim jeden durchlauf immer ein Return file geschrieben --- modules/smarthome/acthor/watt.py | 44 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/modules/smarthome/acthor/watt.py b/modules/smarthome/acthor/watt.py index 1c89a6967..34a9b5cd0 100644 --- a/modules/smarthome/acthor/watt.py +++ b/modules/smarthome/acthor/watt.py @@ -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]) @@ -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) @@ -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() \ No newline at end of file