Dennis89 Guter Tipp mit dem subprocess.
Habe jetzt all anderen scripts gesichert und dann geloescht und nur noch die am laufen:
pi@solaranzeige:~/th $ ls
ms.log SG_Ready.py WP-Licht.py
pi@solaranzeige:~/th $
Alles mit subprocess mit # versehen, d.h. jetzt sind nur noch diese 2 script aktive und schreiben beide auf ms.log:
script, SG-Ready.py
#!/usr/bin/env python3
import json
import requests
import logging
import locale
import datetime
from datetime import datetime
import http.client
import time
from time import sleep
from influxdb import InfluxDBClient
while True:
sleep(30)
locale.setlocale(locale.LC_ALL, 'de_DE.utf8')
logging.basicConfig(filename='/home/pi/th/ms.log', format='%(asctime)s %(message)s', datefmt="Woche %V %a %d.%m.%Y %H:%M:%S",
level=logging.INFO)
# Zeitfenster
now = datetime.now()
Now = now.hour * 60 + now.minute
timewindow1 = (9*60+0) <= Now < (16*60+0) # ein
timewindow2 = (16*60+1) <= Now < (17*60+1) # aus
timewindow3 = (20*60+0) <= Now < (23*60+0) # ein Nachtbooster
timewindow4 = (23*60+1) <= Now < (23*60+2) # aus Nachtbooster
timewindow5 = (23*60+5) <= Now < (23*60+6) # ein Nachtabsenkung
timewindow6 = (7*60+0) <= Now < (7*60+1) # aus Nachtabsenkung
# Periode Winter oder Sommer
monat = datetime.now().month
sommer = monat >= 3 and monat <= 9
winter = not (sommer)
# Enspeisung Influx auslesen
client = InfluxDBClient(host='192.168.0.29', port=8086) # ip oder localhost
client.switch_database('zaehler')
results = client.query('SELECT "Gesamtleistung" FROM "AC" GROUP BY * ORDER BY DESC LIMIT 1')
points = results.get_points
point = 0
for point in points():
shelly_eks = point['Gesamtleistung']
einspeisung = shelly_eks
# Raumtemperatur auslesen (Wohnzimmer west / Controme)
response = requests.get("http://192.168.0.23/get/json/v1/1/temps/")
obj = response.json()
for raum in obj[0]["raeume"]:
if raum ["name"] == "Wohnen west":
if raum ["sensoren"][1]["wert"]:
print(raum["sensoren"][1]["wert"])
logging.info("Temp: %.2f", raum ["sensoren"][1]["wert"]) # Logeintrag
zu_kalt = raum ["sensoren"][1]["wert"]<= 20.5
zu_warm = raum ["sensoren"][1]["wert"]>= 21.5
# Shel1y WP_Verbrauch auslesen
response = requests.get("http://192.168.0.140/status")
obj = response.json()
print (obj ["emeters"][0]["power"])
low = obj ["emeters"][0]["power"] <= 20
high = obj ["emeters"][0]["power"] >= 400
# Signal, dass WP Startet
if (obj ["emeters"][0]["power"]) > 50 and (obj ["emeters"][0]["power"]) < 250:
logging.info('WP StartStartStartStartStart') # Logeintrag
# bit1 IP .150 / bit2 IP .151
# SG-Ready Scenario 1 1 ON / ON Leistung Max 110%
if winter and einspeisung <= -1500 and timewindow1: # 9-16h
conn = http.client.HTTPConnection("[192.168.0.151]")
conn.request("GET", "/relay/0?turn=on") # Closed
logging.info('SG-Ready bit2 ein -1500') # Logeintrag
sleep(1)
conn = http.client.HTTPConnection("[192.168.0.150]")
conn.request("GET", "/relay/0?turn=on") # Closed
logging.info('SG-Ready bit1 ein -1500') # Logeintrag
sleep(3600) # Minimum 1h eingeschaltet
logging.info('SG-Ready sleep') # Logeintrag
# SG-Ready Aus Scenario 0 0 OFF / OFF Normalbetrieb
if winter and einspeisung > -100 and timewindow1: # 9-16h
conn = http.client.HTTPConnection("[192.168.0.150]")
conn.request("GET", "/relay/0?turn=off") # Open
logging.info('SG-Ready bit1 aus1 -500') # Logeintrag
sleep(1)
conn = http.client.HTTPConnection("[192.168.0.151]")
conn.request("GET", "/relay/0?turn=off") # Open
logging.info('SG-Ready bit2 aus1 -500') # Logeintrag
sleep(1800)
# SG-Redy Aus
if winter and timewindow2: # 17h
conn = http.client.HTTPConnection("[192.168.0.150]")
conn.request("GET", "/relay/0?turn=off") # Open
logging.info('SG-Ready bit1 aus2 -500') # Logeintrag
sleep(1)
conn = http.client.HTTPConnection("[192.168.0.151]")
conn.request("GET", "/relay/0?turn=off") # Open
logging.info('SG-Ready bit2 aus2 -500') # Logeintrag
sleep(1)
# Nachtbooster Ein/Aus
# SG-Ready Scenario 1 1 ON / ON Leistung Max (110%) (110% muss in Panasonic WP gessetzt sein)
if winter and timewindow3 and zu_kalt: # < 20.5 # 20h
conn = http.client.HTTPConnection("[192.168.0.151]")
conn.request("GET", "/relay/0?turn=on") # Closed
logging.info('SG-Ready Nb bit2 ein 20:00h') # Logeintrag
sleep(1)
conn = http.client.HTTPConnection("[192.168.0.150]")
conn.request("GET", "/relay/0?turn=on") # Closed
logging.info('SG-Ready Nb bit1 ein 20:00h') # Logeintrag
if winter and timewindow4: # 23h
conn = http.client.HTTPConnection("[192.168.0.150]")
conn.request("GET", "/relay/0?turn=off") # Open
logging.info('SG-Ready Nb bit1 aus 23:00h') # Logeintrag
sleep(1)
conn = http.client.HTTPConnection("[192.168.0.151]")
conn.request("GET", "/relay/0?turn=off") # Open
logging.info('SG-Ready Nb bit2 aus 23:00h') # Logeintrag
# Nachtabsenkung Ein/Aus
# SG-Ready Scenario 0 1 OFF / ON Leistung Min (95%) (95% muss in Panasonic WP gessetzt sein)
if winter and timewindow5 and zu_warm: # > 21.5° # 23.05h
conn = http.client.HTTPConnection("[192.168.0.151]")
conn.request("GET", "/relay/0?turn=on") # Closed
logging.info('SG-Ready bit2 ein 23:050h') # Logeintrag
sleep(1)
conn = http.client.HTTPConnection("[192.168.0.150]")
conn.request("GET", "/relay/0?turn=off") # Open
logging.info('SG-Ready bit1 aus 23:05h') # Logeintrag
if winter and timewindow6: # 7h
conn = http.client.HTTPConnection("[192.168.0.150]")
conn.request("GET", "/relay/0?turn=off") # Open
logging.info('SG-Ready bit1 aus 7:00h') # Logeintrag
sleep(1)
conn = http.client.HTTPConnection("[192.168.0.151]")
conn.request("GET", "/relay/0?turn=off") # Open
logging.info('SG-Ready bit2 aus 7:00h') # Logeintrag
Alles anzeigen
und
script WP-Licht.py
#!/usr/bin/env python3
import logging
import locale
import json
import requests
import subprocess
import time
from time import sleep
while True:
sleep(30)
locale.setlocale(locale.LC_ALL, 'de_DE.utf8')
logging.basicConfig(filename='/home/pi/th/ms.log', format='%(asctime)s %(message)s', datefmt="Woche %V %a %d.%m.%Y %H:%M:%S",
level=logging.INFO)
# Shel1y WP_Verbrauch auslesen
response = requests.get("http://192.168.0.140/status")
obj = response.json()
print (obj ["emeters"][0]["power"])
logging.info("Watt: %.2f", obj ["emeters"][0]["power"]) # Logeintrag
low = obj ["emeters"][0]["power"]<= 20.0
high = obj ["emeters"][0]["power"]>= 400
# Licht high/low schalten
# if low:
# subprocess.run ("/home/pi/th/WP-Licht_low.py")
# if high:
# subprocess.run ("/home/pi/th/WP-Licht_high.py")
# E-Mail senden
# if obj ["emeters"][0]["power"]<= 4.0:
# subprocess.run ("/home/pi/th/Mail_WP_Aus.py")
Alles anzeigen
Nach reboot sieht ms.log aber immer noch nicht so toll aus.
Woche 45 Fr 11.11.2022 21:46:11 Temp: 20.54
Woche 45 Fr 11.11.2022 21:46:11 SG-Ready Nb bit2 ein 20:00h
Woche 45 Fr 11.11.2022 21:46:12 SG-Ready Nb bit1 ein 20:00h
Woche 45 Fr 11.11.2022 21:46:19 Watt: 1165.24
Woche 45 Fr 11.11.2022 21:46:43 Temp: 20.54
Woche 45 Fr 11.11.2022 21:46:44 SG-Ready Nb bit2 ein 20:00h
Woche 45 Fr 11.11.2022 21:46:45 SG-Ready Nb bit1 ein 20:00h
Woche 45 Fr 11.11.2022 21:46:45 Watt: 1159.76
Woche 45 Fr 11.11.2022 21:46:46 Temp: 20.54
Woche 45 Fr 11.11.2022 21:46:46 SG-Ready Nb bit2 ein 20:00h
Woche 45 Fr 11.11.2022 21:46:47 SG-Ready Nb bit1 ein 20:00h
Woche 45 Fr 11.11.2022 21:46:49 Watt: 1160.58
Woche 45 Fr 11.11.2022 21:47:15 Watt: 1160.73
Woche 45 Fr 11.11.2022 21:47:16 Temp: 20.54
Woche 45 Fr 11.11.2022 21:47:16 SG-Ready Nb bit2 ein 20:00h
Woche 45 Fr 11.11.2022 21:47:17 SG-Ready Nb bit1 ein 20:00h
Woche 45 Fr 11.11.2022 21:47:19 Temp: 20.54
Woche 45 Fr 11.11.2022 21:47:19 SG-Ready Nb bit2 ein 20:00h
Woche 45 Fr 11.11.2022 21:47:19 Watt: 1166.46
Woche 45 Fr 11.11.2022 21:47:20 SG-Ready Nb bit1 ein 20:00h
Woche 45 Fr 11.11.2022 21:47:32 Watt: 1166.87
Woche 45 Fr 11.11.2022 21:47:33 Temp: 20.54
Woche 45 Fr 11.11.2022 21:47:33 SG-Ready Nb bit2 ein 20:00h
Woche 45 Fr 11.11.2022 21:47:34 SG-Ready Nb bit1 ein 20:00h
Woche 45 Fr 11.11.2022 21:47:45 Watt: 1166.17
Woche 45 Fr 11.11.2022 21:47:48 Temp: 20.54
Woche 45 Fr 11.11.2022 21:47:49 SG-Ready Nb bit2 ein 20:00h
Woche 45 Fr 11.11.2022 21:47:49 Watt: 1160.33
Woche 45 Fr 11.11.2022 21:47:50 SG-Ready Nb bit1 ein 20:00h
Woche 45 Fr 11.11.2022 21:47:51 Temp: 20.54
Woche 45 Fr 11.11.2022 21:47:51 SG-Ready Nb bit2 ein 20:00h
Woche 45 Fr 11.11.2022 21:47:52 SG-Ready Nb bit1 ein 20:00h
Woche 45 Fr 11.11.2022 21:48:02 Watt: 1167.14
Woche 45 Fr 11.11.2022 21:48:06 Temp: 20.54
Woche 45 Fr 11.11.2022 21:48:06 SG-Ready Nb bit2 ein 20:00h
Woche 45 Fr 11.11.2022 21:48:07 SG-Ready Nb bit1 ein 20:00h
Woche 45 Fr 11.11.2022 21:48:16 Watt: 1170.21
Woche 45 Fr 11.11.2022 21:48:19 Watt: 1165.95
Woche 45 Fr 11.11.2022 21:48:21 Temp: 20.54
Woche 45 Fr 11.11.2022 21:48:21 SG-Ready Nb bit2 ein 20:00h
Woche 45 Fr 11.11.2022 21:48:22 SG-Ready Nb bit1 ein 20:00h
Woche 45 Fr 11.11.2022 21:48:24 Temp: 20.54
Alles anzeigen