Added (trial) syslog info
This commit is contained in:
@ -4,6 +4,7 @@ import urllib3
|
|||||||
import json
|
import json
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
import time
|
import time
|
||||||
|
import syslog
|
||||||
|
|
||||||
# Settings
|
# Settings
|
||||||
from secret import ecodevice,gx,gxsn,chgbleu,chgblanc,chgrouge,minbleu,minblanc,minrouge
|
from secret import ecodevice,gx,gxsn,chgbleu,chgblanc,chgrouge,minbleu,minblanc,minrouge
|
||||||
@ -16,6 +17,10 @@ from secret import ecodevice,gx,gxsn,chgbleu,chgblanc,chgrouge,minbleu,minblanc,
|
|||||||
ESSwBL = 1 # ESS "Optimized with BatteryLife)
|
ESSwBL = 1 # ESS "Optimized with BatteryLife)
|
||||||
ESSwoBL = 10 # ESS "Optimized without BatteryLife)
|
ESSwoBL = 10 # ESS "Optimized without BatteryLife)
|
||||||
|
|
||||||
|
def loggerinfo(foo):
|
||||||
|
syslog.syslog(foo)
|
||||||
|
print(foo)
|
||||||
|
|
||||||
# Setup MQTT Client
|
# Setup MQTT Client
|
||||||
global client
|
global client
|
||||||
|
|
||||||
@ -23,21 +28,18 @@ def on_connect(client, userdata, flags, rc):
|
|||||||
client.subscribe("$SYS/#")
|
client.subscribe("$SYS/#")
|
||||||
global flagConntected
|
global flagConntected
|
||||||
flagConntected = 1
|
flagConntected = 1
|
||||||
#logger.info("Broker connected.")
|
loggerinfo("Broker connected.")
|
||||||
print("Broker connected.")
|
|
||||||
|
|
||||||
def on_message(client, userdata, msg):
|
def on_message(client, userdata, msg):
|
||||||
print(msg.topic+" "+str(msg.payload))
|
loggerinfo(msg.topic+" "+str(msg.payload))
|
||||||
|
|
||||||
def on_publish(client, userdata, mid):
|
def on_publish(client, userdata, mid):
|
||||||
#logger.info("Message Published.")
|
loggerinfo("Message Published.")
|
||||||
print("Message Published.")
|
|
||||||
|
|
||||||
def on_disconnect(client, userdata, rc):
|
def on_disconnect(client, userdata, rc):
|
||||||
global flagConntected
|
global flagConntected
|
||||||
flagConntected = 0
|
flagConntected = 0
|
||||||
#logger.info("Broker disconnected.")
|
loggerinfo("Broker disconnected.")
|
||||||
print("Broker disconnected.")
|
|
||||||
|
|
||||||
client = mqtt.Client("clientdynTEMPO")
|
client = mqtt.Client("clientdynTEMPO")
|
||||||
flagConntected = 0
|
flagConntected = 0
|
||||||
@ -48,16 +50,11 @@ client.on_disconnect = on_disconnect
|
|||||||
#client.tls_set("venus-ca.crt")
|
#client.tls_set("venus-ca.crt")
|
||||||
#client.username_pw_set(username, password)
|
#client.username_pw_set(username, password)
|
||||||
|
|
||||||
# Setup logfile
|
|
||||||
#logzero.logfile("log.log", maxBytes=1e6, backupCount=3)
|
|
||||||
|
|
||||||
# Set the Maxmium SOC when schedule Charge
|
# Set the Maxmium SOC when schedule Charge
|
||||||
def setChargeSetpoint(chargepoint):
|
def setChargeSetpoint(chargepoint):
|
||||||
#logger.info("Set charge setpoint: " + str(chargepoint) + " %")
|
loggerinfo("Set charge setpoint: " + str(chargepoint) + " %")
|
||||||
print("Set charge setpoint: " + str(chargepoint) + " %")
|
|
||||||
if (chargepoint < 50) or (chargepoint > 100):
|
if (chargepoint < 50) or (chargepoint > 100):
|
||||||
#logger.info("Chargepoint should be between 50 to 100%")
|
loggerinfo("Chargepoint should be between 50 to 100%")
|
||||||
print("Chargepoint should be between 50 to 100%")
|
|
||||||
else:
|
else:
|
||||||
# Control ESS over MQTT
|
# Control ESS over MQTT
|
||||||
client.connect(gx, 1883, keepalive=60)
|
client.connect(gx, 1883, keepalive=60)
|
||||||
@ -70,11 +67,9 @@ def setChargeSetpoint(chargepoint):
|
|||||||
|
|
||||||
# Set the Minimum Soc Limit
|
# Set the Minimum Soc Limit
|
||||||
def setMinSocSetpoint(chargepoint):
|
def setMinSocSetpoint(chargepoint):
|
||||||
#logger.info("Set MinSoc setpoint: " + str(chargepoint) + " %")
|
loggerinfo("Set MinSoc setpoint: " + str(chargepoint) + " %")
|
||||||
print("Set MinSoc setpoint: " + str(chargepoint) + " %")
|
|
||||||
if (chargepoint < 10) or (chargepoint > 40):
|
if (chargepoint < 10) or (chargepoint > 40):
|
||||||
#logger.info("Chargepoint should be between 50 to 100%")
|
loggerinfo("Chargepoint should be between 50 to 100%")
|
||||||
print("Chargepoint should be between 10 to 40%")
|
|
||||||
else:
|
else:
|
||||||
# Control ESS over MQTT
|
# Control ESS over MQTT
|
||||||
client.connect(gx, 1883, keepalive=60)
|
client.connect(gx, 1883, keepalive=60)
|
||||||
@ -90,8 +85,7 @@ def setMinSocSetpoint(chargepoint):
|
|||||||
# 10 = Optimized without battery life
|
# 10 = Optimized without battery life
|
||||||
# See https://github.com/victronenergy/venus/wiki/dbus#settings
|
# See https://github.com/victronenergy/venus/wiki/dbus#settings
|
||||||
def setESSstate(state):
|
def setESSstate(state):
|
||||||
#logger.info("Set ESS State: " + str(state) )
|
loggerinfo("Set ESS State: " + str(state) )
|
||||||
print("Set ESS State: " + str(state) )
|
|
||||||
# Security Checks
|
# Security Checks
|
||||||
if (state == 1 or state == 10):
|
if (state == 1 or state == 10):
|
||||||
# Control ESS over MQTT
|
# Control ESS over MQTT
|
||||||
@ -104,20 +98,15 @@ def setESSstate(state):
|
|||||||
lastChargeCondition = 1
|
lastChargeCondition = 1
|
||||||
client.loop_stop()
|
client.loop_stop()
|
||||||
else:
|
else:
|
||||||
#logger.info(" -> not published")
|
loggerinfo(" -> not published")
|
||||||
print(" -> not published")
|
|
||||||
|
|
||||||
# Setup EcoDevice
|
# Setup EcoDevice
|
||||||
http = urllib3.PoolManager()
|
http = urllib3.PoolManager()
|
||||||
resp = http.request("GET", "http://"+ecodevice+"/api/xdevices.json?cmd=10")
|
resp = http.request("GET", "http://"+ecodevice+"/api/xdevices.json?cmd=10")
|
||||||
|
|
||||||
#print("resp.status = "+str(resp.status))
|
|
||||||
if resp.status == 200:
|
if resp.status == 200:
|
||||||
#print("Having data -> decode")
|
|
||||||
teleinfo = json.loads(resp.data)
|
teleinfo = json.loads(resp.data)
|
||||||
|
|
||||||
#print(json.dumps(teleinfo, sort_keys=True, indent=4))
|
|
||||||
|
|
||||||
# Value of var today daynight
|
# Value of var today daynight
|
||||||
# HPJB = Bleu 0 1
|
# HPJB = Bleu 0 1
|
||||||
# HCJB = Bleu 0 0
|
# HCJB = Bleu 0 0
|
||||||
@ -166,8 +155,8 @@ if resp.status == 200:
|
|||||||
tomorrow=0
|
tomorrow=0
|
||||||
|
|
||||||
|
|
||||||
print("Current tarif: " + curtarif + " ("+str(today)+" / "+str(daynight) + ")")
|
loggerinfo("Current tarif: " + curtarif + " ("+str(today)+" / "+str(daynight) + ")")
|
||||||
print("Demain tarif: " + demaintarif + " ("+str(tomorrow)+")")
|
loggerinfo("Demain tarif: " + demaintarif + " ("+str(tomorrow)+")")
|
||||||
|
|
||||||
# daynight : 1 = jour / 0 nuit
|
# daynight : 1 = jour / 0 nuit
|
||||||
# Today Tomorrow Daynight Action
|
# Today Tomorrow Daynight Action
|
||||||
@ -193,56 +182,56 @@ if resp.status == 200:
|
|||||||
#tomorrow = 0
|
#tomorrow = 0
|
||||||
#daynight = 0
|
#daynight = 0
|
||||||
if today == tomorrow:
|
if today == tomorrow:
|
||||||
print ("Rien a faire on sort")
|
loggerinfo ("Rien a faire on sort")
|
||||||
elif today == 0: # Bleu
|
elif today == 0: # Bleu
|
||||||
if tomorrow == 1: # Blanc
|
if tomorrow == 1: # Blanc
|
||||||
if daynight == 1:
|
if daynight == 1:
|
||||||
print ("Charge 90%")
|
loggerinfo ("Charge 90%")
|
||||||
setChargeSetpoint(chgblanc)
|
setChargeSetpoint(chgblanc)
|
||||||
elif tomorrow == 2: # Rouge
|
elif tomorrow == 2: # Rouge
|
||||||
if daynight == 1:
|
if daynight == 1:
|
||||||
print ("Charge 95%")
|
loggerinfo ("Charge 95%")
|
||||||
setChargeSetpoint(chgrouge)
|
setChargeSetpoint(chgrouge)
|
||||||
else:
|
else:
|
||||||
print ("SocMin 25%")
|
loggerinfo ("SocMin 25%")
|
||||||
setMinSocSetpoint(minrouge)
|
setMinSocSetpoint(minrouge)
|
||||||
print ("Battery life OFF")
|
loggerinfo ("Battery life OFF")
|
||||||
setESSstate(ESSwoBL)
|
setESSstate(ESSwoBL)
|
||||||
elif today == 1: # Blanc
|
elif today == 1: # Blanc
|
||||||
if tomorrow == 0: # Bleu
|
if tomorrow == 0: # Bleu
|
||||||
if daynight == 1:
|
if daynight == 1:
|
||||||
print ("Charge 80%")
|
loggerinfo ("Charge 80%")
|
||||||
setChargeSetpoint(chgbleu)
|
setChargeSetpoint(chgbleu)
|
||||||
else:
|
else:
|
||||||
print ("SocMin 30%")
|
loggerinfo ("SocMin 30%")
|
||||||
setMinSocSetpoint(minbleu)
|
setMinSocSetpoint(minbleu)
|
||||||
elif tomorrow == 2: # Rouge
|
elif tomorrow == 2: # Rouge
|
||||||
if daynight == 1:
|
if daynight == 1:
|
||||||
print ("Charge 95%")
|
loggerinfo ("Charge 95%")
|
||||||
setChargeSetpoint(chgrouge)
|
setChargeSetpoint(chgrouge)
|
||||||
else:
|
else:
|
||||||
print ("SocMin 25%")
|
loggerinfo ("SocMin 25%")
|
||||||
setMinSocSetpoint(minrouge)
|
setMinSocSetpoint(minrouge)
|
||||||
print ("Battery life OFF")
|
loggerinfo ("Battery life OFF")
|
||||||
setESSstate(ESSwoBL)
|
setESSstate(ESSwoBL)
|
||||||
elif today == 2: # Rouge
|
elif today == 2: # Rouge
|
||||||
if tomorrow == 0: # Bleu
|
if tomorrow == 0: # Bleu
|
||||||
if daynight == 1:
|
if daynight == 1:
|
||||||
print ("Charge 80%")
|
loggerinfo ("Charge 80%")
|
||||||
setChargeSetpoint(chgbleu)
|
setChargeSetpoint(chgbleu)
|
||||||
else:
|
else:
|
||||||
print ("SocMin 30%")
|
loggerinfo ("SocMin 30%")
|
||||||
setChargeSetpoint(chgbleu)
|
setChargeSetpoint(chgbleu)
|
||||||
print ("Battery life ON")
|
loggerinfo ("Battery life ON")
|
||||||
setESSstate(ESSwBL)
|
setESSstate(ESSwBL)
|
||||||
elif tomorrow == 1: # Blanc
|
elif tomorrow == 1: # Blanc
|
||||||
if daynight == 1:
|
if daynight == 1:
|
||||||
print ("Charge 90%")
|
loggerinfo ("Charge 90%")
|
||||||
setChargeSetpoint(chgblanc)
|
setChargeSetpoint(chgblanc)
|
||||||
else:
|
else:
|
||||||
print ("SocMin 30%")
|
loggerinfo ("SocMin 30%")
|
||||||
setMinSocSetpoint(minblanc)
|
setMinSocSetpoint(minblanc)
|
||||||
print ("Battery life ON")
|
loggerinfo ("Battery life ON")
|
||||||
setESSstate(ESSwBL)
|
setESSstate(ESSwBL)
|
||||||
|
|
||||||
# Voir code : https://github.com/xbeaudouin/dynamic-ess
|
# Voir code : https://github.com/xbeaudouin/dynamic-ess
|
||||||
|
|||||||
Reference in New Issue
Block a user