first commit
This commit is contained in:
119
lua/script_time_gestion_batterie.OLD
Executable file
119
lua/script_time_gestion_batterie.OLD
Executable file
@@ -0,0 +1,119 @@
|
||||
require "scripts/lua/functions"
|
||||
|
||||
--recupere les minutes
|
||||
time=os.time()
|
||||
seconds=tonumber(os.date('%S',time))
|
||||
minutes=tonumber(os.date('%M',time))
|
||||
heures=tonumber(os.date('%H',time))
|
||||
jour=tonumber(os.date('%w',time))
|
||||
mois=tonumber(os.date('%M',time))
|
||||
|
||||
capacite=76 * 12 --Wh
|
||||
charge=200 --Wh
|
||||
decharge=50 --Wh
|
||||
tension_charge_max_off=13.3
|
||||
tension_charge_max_on=13.8
|
||||
tension_injection_min=11.2
|
||||
tension_force_charge=10.8
|
||||
|
||||
--Initialise la commande de retour finale
|
||||
commandArray={}
|
||||
|
||||
|
||||
-- Tension repos V Conso charge W
|
||||
-- 11.35 330
|
||||
-- 12.35 270
|
||||
-- 12.8 233
|
||||
-- 12.67 190
|
||||
-- 13.33 66
|
||||
|
||||
-- --------------------------------------------------------------------------------
|
||||
-- --------------------------------------------------------------------------------
|
||||
|
||||
if false and (seconds % 5 == 0 ) then
|
||||
url = "http://192.168.1.40/getData"
|
||||
|
||||
--result = os.execute(curl..'"'..url..'"')
|
||||
local jsonContent = getJSONContent(url)
|
||||
--print(cmd)
|
||||
|
||||
local statuses = decodeJSON(jsonContent)
|
||||
--printTableAsTree(statuses)
|
||||
|
||||
if isempty(statuses) then
|
||||
print("BAT ERROR getData")
|
||||
return commandArray
|
||||
end
|
||||
if (otherdevices['ForceChargeBatterie'] == 'On' and
|
||||
((tonumber(lastUpdateOfDevice('ForceChargeBatterie')) > 3 * 3600) or tension > tension_charge_max_on))
|
||||
then
|
||||
--commandArray['ForceChargeBatterie'] = "Off"
|
||||
switchOff("ForceChargeBatterie")
|
||||
end
|
||||
|
||||
local tension = round(tonumber(statuses['VOLTAGE']) / 55,2) -- tonumber(otherdevices['BatterieTension'])
|
||||
local power_theorique = -131.71 * tension + 1850.45
|
||||
charge=power_theorique
|
||||
print("BAT Power theorique"..tostring(power_theorique))
|
||||
updatenum("BatterieTension", tension)
|
||||
updatenum("TemperatureBatterie", temperature)
|
||||
--commandArray['Batterie'] = ternary(statuses['PIN_POWER'] == 0, 'On', 'Off')
|
||||
--commandArray['InjectionBatterie'] = ternary(statuses['PIN_INJECTION'] == 0, 'On', 'Off')
|
||||
--commandArray['ChargeBatterie'] = ternary(statuses['PIN_CHARGE'] == 0, 'On', 'Off')
|
||||
|
||||
production = tonumber(split(otherdevices['SolaireProduction'], ";")[1])
|
||||
injection = tonumber(split(otherdevices['Injection_Radiateur'], ";")[1])
|
||||
chauffe = tonumber(split(otherdevices['Chauffe_Eau'], ";")[1])
|
||||
conso = tonumber(split(otherdevices['Consommation_Apparente'], ";")[1])
|
||||
print("BAT injection="..tostring(injection)
|
||||
..' chauffe='..tostring(chauffe)
|
||||
..' charge='..tostring(charge)
|
||||
..' conso='..tostring(conso)
|
||||
.. ' voltage='..tostring(round(tonumber(statuses['VOLTAGE']) / 55,2))
|
||||
..' tension='..tostring(tension)
|
||||
)
|
||||
print("BAT PIN_POWER="..statuses['PIN_POWER'].." PIN_CHARGE="..statuses['PIN_CHARGE'].." PIN_INJECTION="..statuses['PIN_INJECTION'].." PIN_BATTERIE="..statuses['PIN_BATTERIE'])
|
||||
-- status 0 = ON / 1 = OFF
|
||||
|
||||
if (statuses['PIN_CHARGE'] == 1) then --(otherdevices['ChargeBatterie'] == 'Off') then
|
||||
if (uservariables['Dark'] == "False"
|
||||
and (conso < - charge or injection > charge or (injection - conso > charge) or otherdevices['ForceChargeBatterie'] == 'On')
|
||||
and tension <= tension_charge_max_off
|
||||
)
|
||||
then
|
||||
print("BAT charge batterie / arret injection")
|
||||
switchOff("InjectionBatterie")
|
||||
switchOn("ChargeBatterie")
|
||||
else
|
||||
if tension <= tension_force_charge then
|
||||
switchOn("ForceChargeBatterie")
|
||||
else
|
||||
if (statuses['PIN_INJECTION'] == 1) then --(otherdevices['InjectionBatterie'] == 'Off') then
|
||||
if (conso > decharge and injection < decharge and tension >= tension_injection_min) then
|
||||
print("BAT Injection batterie / arret charge")
|
||||
switchOff("ChargeBatterie")
|
||||
switchOn("InjectionBatterie")
|
||||
end
|
||||
else
|
||||
if (injection > decharge / 2 or conso < - decharge / 2 or tension < tension_injection_min) then -- or (production <= 100 and heures < 23 and heures > 7)) then
|
||||
print("BAT arret injection batterie")
|
||||
switchOff("InjectionBatterie")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
-- test sur statuses pour eviter les valeurs nulles
|
||||
if (conso - injection > 14 or tension > tension_charge_max_on) then
|
||||
print("BAT arret charge batterie")
|
||||
switchOff("ChargeBatterie")
|
||||
--switchOn("InjectionBatterie")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--if heures == 4 and minutes <= 2 then
|
||||
-- switchOff("InjectionBatterie")
|
||||
--end
|
||||
|
||||
return commandArray
|
||||
Reference in New Issue
Block a user