Skip to content

Commit

Permalink
prep for 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
britkat1980 committed Oct 26, 2023
1 parent 4943d3f commit 0518918
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ COPY GivEnergy-Smart-Home-Display-givtcp/ ./GivEnergy-Smart-Home-Display-givtcp
COPY givenergy_modbus/ /usr/local/lib/python3.10/site-packages/givenergy_modbus

COPY startup.py startup.py
COPY startup_3.py startup_3.py
#COPY startup_3.py startup_3.py
COPY redis.conf redis.conf
COPY settings.json /app/settings.json

Expand Down Expand Up @@ -108,4 +108,4 @@ ENV EVC_SELF_RUN_TIMER=5

EXPOSE 6345 1883 3000 5173 6379 9181

CMD ["python3", "/app/startup_3.py"]
CMD ["python3", "/app/startup.py"]
8 changes: 8 additions & 0 deletions GivTCP/HA_Discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def create_device_payload(topic,SN):
# If its a rate then change to Watts
if "SOC" in str(topic).lower():
tempObj['unit_of_meas']="%"
tempObj['min']=4
tempObj['max']=100
tempObj['mode']="slider"
elif "limit" in str(topic).lower(): #if EVC current
tempObj['unit_of_meas']="A"
tempObj['min']=6
Expand All @@ -221,6 +224,11 @@ def create_device_payload(topic,SN):
tempObj['min']=0
tempObj['max']=HAMQTT.getinvbatmax()
tempObj['mode']="slider"
elif "max_session_energy" in str(topic).lower():
tempObj['unit_of_meas']="kWh"
tempObj['min']=0
tempObj['max']=100
tempObj['mode']="slider"
else:
tempObj['unit_of_meas']="%"
elif GivLUT.entity_type[str(topic).split("/")[-1]].devType=="button":
Expand Down
4 changes: 4 additions & 0 deletions GivTCP/REST.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def getAll():
def reboot():
return wr.rebootinverter()

@giv_api.route('/restart', methods=['GET'])
def restart():
return wr.rebootAddon

#Publish last cached Invertor Data
@giv_api.route('/readData', methods=['GET'])
def rdData():
Expand Down
8 changes: 4 additions & 4 deletions GivTCP/evc.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ def hybridmode():
with open(GivLUT.regcache, 'rb') as inp:
invRegCache= pickle.load(inp)
sparePower=invRegCache[4]['Power']['Power']['PV_Power']-invRegCache[4]['Power']['Power']['Load_Power']+evcRegCache['Charger']['Active_Power_L1']
spareCurrent=int(min(sparePower/invRegCache[4]['Power']['Power']['Grid_Voltage'],0)+6) #Spare current cannot be negative
if not spareCurrent==evcRegCache['Charger']['Current_L1']:
spareCurrent=int(max((sparePower/invRegCache[4]['Power']['Power']['Grid_Voltage']),0)+6) #Spare current cannot be negative
if not spareCurrent==evcRegCache['Charger']['Charge_Limit']:
logger.info("Topping up min charge with Solar curent ("+str(spareCurrent-6)+"A), setting EVC charge to: "+str(spareCurrent)+"A")
setCurrentLimit(spareCurrent)

Expand All @@ -405,7 +405,7 @@ def solarmode():
setChargeControl("Start")
setCurrentLimit(spareCurrent)
else:
if not evcRegCache['Charger']['Control_Charge']=="Stop":
if not evcRegCache['Charger']['Charge_Control']=="Stop":
logger.info("Solar excess dropped to below 6A, stopping charge")
setChargeControl("Stop")

Expand All @@ -420,7 +420,7 @@ def importcap():
evccurrent=float(evcRegCache['Charger']['Current_L1'])
if importcurrent>GiV_Settings.evc_import_max_current:
excess=importcurrent-GiV_Settings.evc_import_max_current
newcurrent=int(max(6,evccurrent-excess))
newcurrent=int(max(6,evccurrent-excess)) #newcurrent must be at least 6A
logger.info("Import current exceeded ("+str(excess)+"), reducing EVC charge to: "+str(newcurrent)+"A")
setCurrentLimit(newcurrent)

Expand Down
2 changes: 1 addition & 1 deletion buildx.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -t britkat/giv_tcp-dev:2.3.104 -t britkat/giv_tcp-dev:latest --push .
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -t britkat/giv_tcp-dev:2.3.112 -t britkat/giv_tcp-dev:latest --push .
::docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -t britkat/giv_tcp-dev:latest --push .
::docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -t britkat/giv_tcp-ma:latest -t britkat/giv_tcp-ma:2.3.3 --push .
68 changes: 60 additions & 8 deletions startup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from genericpath import exists
import os, pickle, subprocess, logging,shutil, shlex, schedule
from time import sleep
Expand All @@ -7,8 +7,10 @@
import sys
import requests
from GivTCP.findInvertor import findInvertor
from GivTCP.findEVC import findEVC
import givenergy_modbus.model.inverter
from givenergy_modbus.client import GivEnergyClient
from pymodbus.client.sync import ModbusTcpClient

selfRun={}
mqttClient={}
Expand All @@ -29,6 +31,18 @@
def palm_job():
subprocess.Popen(["/usr/local/bin/python3","/app/GivTCP_1/palm_soc.py"])

def validateEVC(HOST):
logger.info("Validating "+str(HOST))
try:
client = ModbusTcpClient(HOST)
regs = client.read_holding_registers(97,6).registers
systime=datetime(regs[0],regs[1],regs[2],regs[3],regs[4],regs[5]).replace(tzinfo=timezone.utc).isoformat()
return True
except:
e=sys.exc_info()
logger.info(e)
return False

def getInvDeets(HOST):
try:
client=GivEnergyClient(host=HOST)
Expand Down Expand Up @@ -115,11 +129,32 @@ def getInvDeets(HOST):
inverterStats={}
invList={}
list={}
evclist={}
logger.critical("Scanning network for inverters...")
try:
for subnet in networks:
if networks[subnet]:
count=0
# Get EVC Details
while len(evclist)<=0:
if count<2:
logger.info("EVC- Scanning network ("+str(count+1)+"):"+str(networks[subnet]))
evclist=findEVC(networks[subnet])
if len(evclist)>0: break
count=count+1
else:
break
if evclist:
poplist=[]
for evc in evclist:
if validateEVC(evclist[evc]):
logger.info("GivEVC found at: "+str(evclist[evc]))
else:
logger.info(evclist[evc]+" is not an EVC")
poplist.append(evc)
for pop in poplist:
evclist.pop(pop) #remove the unknown modbus device(s)
# Get Inverter Details
while len(list)<=0:
if count<2:
logger.info("Scanning network ("+str(count+1)+"):"+str(networks[subnet]))
Expand All @@ -129,7 +164,7 @@ def getInvDeets(HOST):
else:
break
if list:
logger.info(str(len(list))+" Inverters found on "+str(networks[subnet])+" - "+str(list))
logger.debug(str(len(list))+" Inverters found on "+str(networks[subnet])+" - "+str(list))
invList.update(list)
for inv in invList:
deets={}
Expand All @@ -145,6 +180,8 @@ def getInvDeets(HOST):
Stats['Model']=deets[2]
Stats['Generation']=deets[1]
inverterStats[inv]=Stats
else:
logger.error("Unable to interrogate inverter to get base details")
count=count+1
else:
break
Expand Down Expand Up @@ -174,8 +211,8 @@ def getInvDeets(HOST):
#rqdash=subprocess.Popen(["/usr/local/bin/rq-dashboard","-u redis://127.0.0.1:6379"])
#logger.critical("Running RQ Dashboard on port 9181")

vueConfig=subprocess.Popen(["npm", "run", "dev","-- --host"],cwd="/app/config_frontend")
logger.critical("Running Config Frontend")
#vueConfig=subprocess.Popen(["npm", "run", "dev","-- --host"],cwd="/app/config_frontend")
#logger.critical("Running Config Frontend")

##########################################################################################################
#
Expand Down Expand Up @@ -326,10 +363,15 @@ def getInvDeets(HOST):
selfRun[inv]=subprocess.Popen(["/usr/local/bin/python3",PATH+"/read.py", "self_run2"])

if os.getenv('EVC_ENABLE')=="True" and inv==1: #only run it once
logger.critical ("Running EVC read loop every "+str(os.getenv('EVC_SELF_RUN_TIMER'))+"s")
evcSelfRun=subprocess.Popen(["/usr/local/bin/python3",PATH+"/evc.py", "self_run2"])
logger.critical ("Subscribing MQTT Broker for EVC control")
mqttClientEVC=subprocess.Popen(["/usr/local/bin/python3",PATH+"/mqtt_client_evc.py"])
if not os.getenv('EVC_IP_ADDRESS')=="":
logger.critical ("Running EVC read loop every "+str(os.getenv('EVC_SELF_RUN_TIMER'))+"s")
evcSelfRun=subprocess.Popen(["/usr/local/bin/python3",PATH+"/evc.py", "self_run2"])
logger.critical ("Subscribing MQTT Broker for EVC control")
mqttClientEVC=subprocess.Popen(["/usr/local/bin/python3",PATH+"/mqtt_client_evc.py"])
evcChargeModeLoop=subprocess.Popen(["/usr/local/bin/python3",PATH+"/evc.py", "chargeMode"])
logger.critical ("Setting chargeMode loop to manage different charge modes every 60s")
else:
logger.critical("EVC IP is missing from config. Please update and restart GivTCP")

if os.getenv('MQTT_OUTPUT')=="True" or isAddon:
logger.critical ("Subscribing MQTT Broker for control")
Expand Down Expand Up @@ -398,6 +440,16 @@ def getInvDeets(HOST):
os.chdir(PATH)
logger.critical ("Restarting EVC read loop every "+str(os.getenv('EVC_SELF_RUN_TIMER'))+"s")
selfRun[inv]=subprocess.Popen(["/usr/local/bin/python3",PATH+"/evc.py", "self_run2"])
if os.getenv('EVC_ENABLE')==True and not evcSelfRun.poll()==None:
logger.error("EVC Self Run loop process died. restarting...")
os.chdir(PATH)
logger.critical ("Restarting EVC read loop every "+str(os.getenv('EVC_SELF_RUN_TIMER'))+"s")
evcSelfRun=subprocess.Popen(["/usr/local/bin/python3",PATH+"/evc.py", "self_run2"])
if os.getenv('EVC_ENABLE')==True and not evcChargeModeLoop.poll()==None:
logger.error("EVC Self Run loop process died. restarting...")
os.chdir(PATH)
logger.critical ("Restarting EVC chargeMode loop every 60s")
evcChargeModeLoop=subprocess.Popen(["/usr/local/bin/python3",PATH+"/evc.py", "chargeMode"])

#Run jobs for smart target
schedule.run_pending()
Expand Down
4 changes: 2 additions & 2 deletions startup_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ def getInvDeets(HOST):
#rqdash=subprocess.Popen(["/usr/local/bin/rq-dashboard","-u redis://127.0.0.1:6379"])
#logger.critical("Running RQ Dashboard on port 9181")

#vueConfig=subprocess.Popen(["npm", "run", "dev","-- --host"],cwd="/app/config_frontend")
#logger.critical("Running Config Frontend")
vueConfig=subprocess.Popen(["npm", "run", "dev","-- --host"],cwd="/app/config_frontend")
logger.critical("Running Config Frontend")

##########################################################################################################
#
Expand Down

0 comments on commit 0518918

Please sign in to comment.