Erster Stand der Hintergrundprozesse, die auf der Synology unter /volume1/homes/wagner/SolarManager laufen: der Manager selbst, die Sammler je Geraet, die MQTT-Bruecke, der Wecker und - neu hinzugezogen - der AutoAction-Runner, der als Hintergrundprozess hierher gehoert und nicht ins Web-Verzeichnis. Zugangsdaten stehen nicht mehr im Quelltext, sondern in config.ini, die nicht mit eingecheckt wird. Vorlage ist config.ini.example, gelesen wird sie von konfig.py. Betroffen waren solarManager.py (Datenbank und Wattpilot), zeit.py, gatherWaterData.py, wecker.py und skoda_testdaten.py, das sich das Passwort bisher aus dem Quelltext eines anderen Moduls herausgesucht hat. Die Kia-Anbindung ist mit dem Fahrzeug entfallen: kiaTest.py, gatherCarData.py und hyundai_kia_connect_api sind nicht mehr dabei, ebenso gatherInverterData.py, auf das nur noch eine auskommentierte Zeile zeigte. Die mitgelieferten Bibliotheken bleiben im Repository - die NAS hat kein pip, sie muessen neben den Skripten liegen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
133 lines
5.1 KiB
Python
133 lines
5.1 KiB
Python
import json
|
|
import asyncio
|
|
import aiohttp
|
|
import sys
|
|
import logging
|
|
import math
|
|
from dataclasses import dataclass
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
@dataclass
|
|
class ChargerData:
|
|
p_l1ev:float = 0
|
|
p_l2ev:float = 0
|
|
p_l3ev:float = 0
|
|
Iset_ev:float = 0
|
|
Phase_set_ev:int = 0
|
|
AllowCharging_ev:bool = False
|
|
mode:str = ""
|
|
connected:bool = False
|
|
eto:int = 0 # Gesamtzaehlerstand der Wallbox in Wh
|
|
|
|
|
|
async def gatherNeededStatus() -> ChargerData:
|
|
ret = ChargerData
|
|
#print("get charger status...");
|
|
timeout = aiohttp.ClientTimeout(total=3)
|
|
try:
|
|
async with aiohttp.ClientSession() as session:
|
|
async with session.get('http://192.168.179.122/api/status?filter=psm,fup,amp,frc,nrg,lmo,car,pgrid,pakku,ppv,eto',timeout=timeout) as response: #?filter=psm,fup,amp,frc,nrg,lmo,car
|
|
if response.status == 200:
|
|
html = await response.text()
|
|
#logging.warning(html)
|
|
state = json.loads(html)
|
|
# Gesamtzaehler der Wallbox in Wh. Genauer als die Summe
|
|
# ueber die Fuenf-Minuten-Leistungswerte: die Differenz
|
|
# zweier Staende trifft den Ladevorgang auf die
|
|
# Wattstunde, waehrend eine Summe aus Mittelwerten an den
|
|
# Raendern immer danebenliegt.
|
|
ret.eto = int(state.get("eto",0) or 0)
|
|
ret.p_l1ev = state["nrg"][7]/1000.0
|
|
ret.p_l2ev = state["nrg"][8]/1000.0
|
|
ret.p_l3ev = state["nrg"][9]/1000.0
|
|
ret.Iset_ev = state["amp"]
|
|
ret.Phase_set_ev = state["psm"]
|
|
ret.AllowCharging_ev = state["frc"]
|
|
if state["car"] == 2 or state["car"] == 4:
|
|
ret.connected = True
|
|
else:
|
|
ret.connected = False
|
|
if state["fup"] == True and state["lmo"] == 4:
|
|
ret.mode = "Eco"
|
|
elif state["fup"] == True and state["lmo"] == 5:
|
|
ret.mode = "Next Trip"
|
|
else:
|
|
ret.mode = "Default"
|
|
|
|
except:
|
|
return ret
|
|
#print("Body:", html)
|
|
return ret
|
|
|
|
async def setPVparameters(pGrid:int,pPv:int,pAkku:int):
|
|
timeout = aiohttp.ClientTimeout(total=3)
|
|
#logging.warning('{"pGrid":'+str(round(pGrid))+',"pAkku":'+str(round(pAkku))+',"pPv":'+str(round(pPv))+'}')
|
|
#_LOGGER.error('{"pGrid":'+str(round(pGrid))+',"pAkku":'+str(round(pAkku))+',"pPv":'+str(round(pPv))+'}')
|
|
try:
|
|
async with aiohttp.ClientSession() as session:
|
|
async with session.get('http://192.168.179.122/api/set?ids={"pGrid":'+str(round(pGrid))+',"pAkku":'+str(round(pAkku))+',"pPv":'+str(round(pPv))+'}',timeout=timeout) as response:
|
|
if response.status != 200:
|
|
#_LOGGER.error('goE Return: %s' % await response.text())
|
|
return False
|
|
#else:
|
|
# _LOGGER.error('goE Return: %s' % await response.text())
|
|
except Exception as error:
|
|
_LOGGER.error(f"Error during sending GoE Parameters: %s",error)
|
|
return False
|
|
|
|
|
|
async def setChargePower(power:int, currPhases:int, currAmp:int, currCharging:bool):
|
|
timeout = aiohttp.ClientTimeout(total=3)
|
|
|
|
if(power < 3700):
|
|
phases = 1
|
|
amp = math.floor(power/240)
|
|
elif(power > 4500):
|
|
phases = 2
|
|
amp = math.floor((power/3)/240)
|
|
else:
|
|
amp = 16
|
|
|
|
if(amp < 6):
|
|
amp = 0
|
|
elif(amp > 16):
|
|
amp = 16
|
|
if(phases != currPhases):
|
|
logging.warning("Change phases: "+str(phases))
|
|
#async with aiohttp.ClientSession() as session:
|
|
# async with session.get('http://192.168.178.64/api/?psm='+phases,timeout=timeout) as response:
|
|
# if response.status != 200:
|
|
# return False
|
|
if(amp != currAmp and amp):
|
|
logging.warning("Change amp: "+str(amp))
|
|
if(currCharging == False):
|
|
logging.warning("start charging")
|
|
#async with aiohttp.ClientSession() as session:
|
|
# async with session.get('http://192.168.178.64/api/set?amp='+amp,timeout=timeout) as response:
|
|
# if response.status != 200:
|
|
# return False
|
|
elif(currCharging):
|
|
logging.warning("stop charging")
|
|
#async with aiohttp.ClientSession() as session:
|
|
# async with session.get('http://192.168.178.64/api/set?frc=1',timeout=timeout) as response:
|
|
# if response.status != 200:
|
|
# return False
|
|
|
|
#status = charger.get_status(status_type=goecharger_api_lite.GoeCharger.STATUS_FULL)
|
|
#print(json.dumps(status, indent=4))
|
|
|
|
#adjust amps
|
|
#curl "http://1.2.3.4/api/set?amp=16"
|
|
#current energy: nrg energy array, U (L1, L2, L3, N), I (L1, L2, L3), P (L1, L2, L3, N, Total), pf (L1, L2, L3, N)
|
|
#set 1-phase
|
|
#curl "http://1.2.3.4/api/set?psm=1"
|
|
|
|
#set 3-phase
|
|
#curl "http://1.2.3.4/api/set?psm=2"
|
|
|
|
#start charging
|
|
#curl "http://1.2.3.4/api/set?frc=0"
|
|
|
|
#stop charging
|
|
#curl "http://1.2.3.4/api/set?frc=1"
|