Skip to content

Commit

Permalink
Smarthome... (#2739)
Browse files Browse the repository at this point in the history
* Smarthome...

Neu wird das MQTT topic mess_only gepflegt. Wenn "kein Gerät" (also nur rein Leisungsmessung definiert ist der wert 1 sonst 0. Hier kann in Zukunft das GUI abfragen ob überhaupt  automatisch / manual Modus angezeigt wird (oder nicht einfach nur "nur Messung")
Lambda driver wurde an python logging angepasst

* flake8

* Smarthome...

topic wurde von mess_only auf meas_only umbenannt,

* Revert "Smarthome..."

This reverts commit 712f618.

* Revert "flake8"

This reverts commit f1925e8.

* revert change

* sleep

Sleep aus Smartcommon in smarthomemq verlagert (braucht es nur für 1.9)
  • Loading branch information
okaegi committed Jun 12, 2023
1 parent 274690b commit e683c1d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 60 deletions.
27 changes: 9 additions & 18 deletions packages/modules/smarthome/lambda_/off.py
@@ -1,42 +1,33 @@
#!/usr/bin/python3
import sys
import os
import time
import struct
import codecs

import logging
from smarthome.smartlog import initlog
from pymodbus.client.sync import ModbusTcpClient

named_tuple = time.localtime() # getstruct_time
time_string = time.strftime("%m/%d/%Y, %H:%M:%S lambda off.py", named_tuple)
devicenumber = str(sys.argv[1])
devicenumber = int(sys.argv[1])
ipadr = str(sys.argv[2])
uberschuss = int(sys.argv[3])
uberschussvz = str(sys.argv[4])
initlog("lambda", devicenumber)
log = logging.getLogger("lambda")
if (uberschussvz == 'UN'):
uberschuss = uberschuss * -1
bp = '/var/www/html/openWB/ramdisk/smarthome_device_'
# standard
file_string = bp + str(devicenumber) + '_lambda.log'
file_stringpv = bp + str(devicenumber) + '_pv'
file_stringcount = bp + str(devicenumber) + '_count'
if os.path.isfile(file_string):
pass
else:
with open(file_string, 'w') as f:
print('lambda start log', file=f)
with open(file_string, 'a') as f:
print('%s devicenr %s ipadr %s ueberschuss %6d try to connect (modbus)'
% (time_string, devicenumber, ipadr, uberschuss), file=f)
log.info(' off.py devicenr %d ipadr %s ueberschuss %6d try to connect (modbus)'
% (devicenumber, ipadr, uberschuss))
client = ModbusTcpClient(ipadr, port=502)
start = 103
resp = client.read_holding_registers(start, 2)
value1 = resp.registers[0]
all = format(value1, '04x')
aktpower = int(struct.unpack('>h', codecs.decode(all, 'hex'))[0])
with open(file_string, 'a') as f:
print('%s devicenr %s ipadr %s Akt Leistung %6d'
% (time_string, devicenumber, ipadr, aktpower), file=f)
log.info(' off.py devicenr %d ipadr %s Akt Leistung %6d'
% (devicenumber, ipadr, aktpower))
pvmodus = 0
if os.path.isfile(file_stringpv):
with open(file_stringpv, 'r') as f:
Expand Down
27 changes: 9 additions & 18 deletions packages/modules/smarthome/lambda_/on.py
@@ -1,14 +1,11 @@
#!/usr/bin/python3
import sys
import os
import time
import struct
import codecs

import logging
from smarthome.smartlog import initlog
from pymodbus.client.sync import ModbusTcpClient
named_tuple = time.localtime() # getstruct_time
time_string = time.strftime("%m/%d/%Y, %H:%M:%S lambda on.py", named_tuple)
devicenumber = str(sys.argv[1])
devicenumber = int(sys.argv[1])
ipadr = str(sys.argv[2])
uberschuss = int(sys.argv[3])
uberschussvz = str(sys.argv[4])
Expand All @@ -18,26 +15,20 @@
# standard
# lesen
# own log
file_string = bp + str(devicenumber) + '_lambda.log'
file_stringpv = bp + str(devicenumber) + '_pv'
file_stringcount = bp + str(devicenumber) + '_count'
if os.path.isfile(file_string):
pass
else:
with open(file_string, 'w') as f:
print('lambda start log', file=f)
with open(file_string, 'a') as f:
print('%s devicenr %s ipadr %s ueberschuss %6d try to connect (modbus)'
% (time_string, devicenumber, ipadr, uberschuss), file=f)
initlog("lambda", devicenumber)
log = logging.getLogger("lambda")
log.info(' on.py devicenr %d ipadr %s ueberschuss %6d try to connect (modbus)'
% (devicenumber, ipadr, uberschuss))
client = ModbusTcpClient(ipadr, port=502)
start = 103
resp = client.read_holding_registers(start, 2)
value1 = resp.registers[0]
all = format(value1, '04x')
aktpower = int(struct.unpack('>h', codecs.decode(all, 'hex'))[0])
with open(file_string, 'a') as f:
print('%s devicenr %s ipadr %s Akt Leistung %6d ' %
(time_string, devicenumber, ipadr, aktpower), file=f)
log.info(' on.py devicenr %d ipadr %s Akt Leistung %6d ' %
(devicenumber, ipadr, aktpower))
with open(file_stringpv, 'w') as f:
f.write(str(1))
count1 = 999
Expand Down
35 changes: 13 additions & 22 deletions packages/modules/smarthome/lambda_/watt.py
Expand Up @@ -2,25 +2,28 @@
import sys
import os
import time
import json
import struct
import codecs
import logging
from pymodbus.payload import BinaryPayloadBuilder, Endian
from pymodbus.client.sync import ModbusTcpClient
from smarthome.smartlog import initlog
from smarthome.smartret import writeret
named_tuple = time.localtime() # getstruct_time
time_string = time.strftime("%m/%d/%Y, %H:%M:%S lambda watty.py", named_tuple)
devicenumber = str(sys.argv[1])
devicenumber = int(sys.argv[1])
ipadr = str(sys.argv[2])
uberschuss = int(sys.argv[3])
uberschussvz = str(sys.argv[4])
forcesend = int(sys.argv[5])
# forcesend = 0 default acthor time period applies
# forcesend = 1 default overwritten send now
# forcesend = 9 default overwritten no send
initlog("lambda", devicenumber)
log = logging.getLogger("lambda")
if (uberschussvz == 'UN'):
uberschuss = uberschuss * -1
bp = '/var/www/html/openWB/ramdisk/smarthome_device_'
file_string = bp + str(devicenumber) + '_lambda.log'
file_stringpv = bp + str(devicenumber) + '_pv'
file_stringcount = bp + str(devicenumber) + '_count'
file_stringcount5 = bp + str(devicenumber) + '_count5'
Expand Down Expand Up @@ -88,18 +91,10 @@
with open(file_stringpv, 'w') as f:
f.write(str(pvmodus))
if count1 < 3:
if os.path.isfile(file_string):
pass
else:
with open(file_string, 'w') as f:
print('lambda start log', file=f)
with open(file_string, 'a') as f:
print('%s Nr %s ipadr %s ueberschuss %6d Akt Leistung %6d'
% (time_string, devicenumber, ipadr, uberschuss, aktpower),
file=f)
print('%s Nr %s ipadr %s neupower %6d pvmodus %1d modbusw %1d'
% (time_string, devicenumber, ipadr, neupower, pvmodus,
modbuswrite), file=f)
log.info(' %d ipadr %s ueberschuss %6d Akt Leistung %6d'
% (devicenumber, ipadr, uberschuss, aktpower))
log.info(' %d ipadr %s neupower %6d pvmodus %1d modbusw %1d'
% (devicenumber, ipadr, neupower, pvmodus, modbuswrite))
# modbus write
if modbuswrite == 1:
# andernfalls absturz bei negativen Zahlen
Expand All @@ -109,16 +104,12 @@
pay = builder.to_registers()
client.write_registers(102, [pay[0]])
if count1 < 3:
with open(file_string, 'a') as f:
print('%s devicenr %s ipadr %s written %6d %#4X' %
(time_string, devicenumber, ipadr, pay[0], pay[0]),
file=f)
log.info(' %d ipadr %s written %6d %#4X' %
(devicenumber, ipadr, pay[0], pay[0]))
else:
if pvmodus == 99:
pvmodus = 0
answer = '{"power":' + str(aktpower) + ',"powerc":0'
answer += ',"send":' + str(modbuswrite) + ',"sendpower":' + str(neupower)
answer += ',"on":' + str(pvmodus) + '}'
with open('/var/www/html/openWB/ramdisk/smarthome_device_ret' +
str(devicenumber), 'w') as f1:
json.dump(answer, f1)
writeret(answer, devicenumber)
1 change: 0 additions & 1 deletion packages/smarthome/smartcommon.py
Expand Up @@ -486,4 +486,3 @@ def mainloop(wattbezug: int, speicherleistung: int, speichersoc: int) -> None:
mqtt_man[pref + 'device_manual_control'] = workman
if (sendmess == 1):
sendmq(mqtt_man)
time.sleep(5)
2 changes: 1 addition & 1 deletion runs/smarthomemq.py
Expand Up @@ -100,4 +100,4 @@ def checkbootdone() -> int:
+ str(e))
wattbezug = 0
mainloop(wattbezug, speicherleistung, speichersoc)

time.sleep(5)

0 comments on commit e683c1d

Please sign in to comment.