211 lines
9.1 KiB
Plaintext
Executable File
211 lines
9.1 KiB
Plaintext
Executable File
require "scripts/lua/functions"
|
|
|
|
commandArray = {}
|
|
|
|
--local switch = 'VoletCuisine'
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
--recupere les minutes
|
|
-- ------------------------------------------------------------------------------
|
|
time=os.time()
|
|
minutes=tonumber(os.date('%M',time))
|
|
jour=tonumber(os.date('%w',time))
|
|
heures=tonumber(os.date('%H',time))
|
|
heurmin= heures * 60 + minutes
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- Test temperature radiateur chambres
|
|
-- ------------------------------------------------------------------------------
|
|
function gestionRadiateur( switchTemp, switchRadiateur, consigne)
|
|
|
|
if (minutes % 10 ~= 5) then
|
|
return
|
|
end
|
|
|
|
local last = lastUpdateOfDevice(switchRadiateur)
|
|
debug("--------------"..switchRadiateur.."-----------------------------------")
|
|
debug("delai="..tostring(delai).." last="..tostring(last)..' Chauffage='..otherdevices[switchRadiateur])
|
|
debug("------------------------------------------------------------")
|
|
|
|
if (last < 600) then
|
|
debug("Aucune action. Mise à jour trop récente.".." last="..tostring(last).." temp="..tostring(currentTemp).." / Consigne="..tostring(consigne))
|
|
return
|
|
end
|
|
|
|
local delta = 0.2
|
|
|
|
local currentTemp = tonumber(otherdevices_svalues[switchTemp])
|
|
|
|
local tempAbsence = tonumber(otherdevices_svalues['ConsigneAbsence'])
|
|
|
|
local variation = variationTemp2(switchTemp, 10) -- variation des 10 dernières minutes
|
|
|
|
local variationExt = uservariables['AugmentationTempExterieure']
|
|
|
|
local augmentation = variation * 60 / 10 --time -- ° par heure
|
|
|
|
local ecart = consigne - currentTemp
|
|
|
|
local estimation = 0.0
|
|
if (augmentation > 0 and ecart > 0) then
|
|
estimation = 60 * ecart / augmentation
|
|
end
|
|
|
|
debug("Retour augmentation="..tostring(augmentation).." ecart="..tostring(ecart)..'°C Estimation='..tostring(estimation).." minutes variationExt="..tostring(variationExt).."°C / heure")
|
|
|
|
--2016-02-27 20:08:59.864 LUA: delai=180 last=37
|
|
--2016-02-27 20:08:59.918 LUA: Retour variation=0.3 switch=RadiateurManon
|
|
--2016-02-27 20:08:59.918 LUA: CHECK Temperature Variation=0.3 switch=RadiateurManon currentTemp=18.3 tempAbsence=16 consigne=18.5
|
|
|
|
debug("Retour variation="..tostring(variation).." switch="..switchRadiateur..' lastUpdate='..tostring(lastUpdateOfDevice(switchRadiateur)))
|
|
debug('CHECK Temperature Variation='..tostring(variation)..' switch='..switchRadiateur..' currentTemp='..tostring(currentTemp).. ' tempAbsence='..tostring(tempAbsence)..' consigne='..tostring(consigne))
|
|
|
|
if otherdevices['ChauffageGeneral'] == 'Off' then
|
|
if (minutes%30 == 0) then
|
|
switchOffRadiateur(switchRadiateur)
|
|
debug("ChauffageGeneral Eteint. Demande extinction.")
|
|
else
|
|
debug("Radiateur ="..switchRadiateur.." Retour sans rien faire. ChauffageGeneral Eteint.")
|
|
end
|
|
end
|
|
if lastUpdateOfDevice(switchRadiateur) < delai then
|
|
debug("Radiateur ="..switchRadiateur.." Retour sans rien faire. Delai non atteint.")
|
|
return
|
|
end
|
|
-- Periode de vacances ou absence ==> hors gel
|
|
if (otherdevices['Vacances'] == 'On' or otherdevices['AbsenceFamille'] == 'On') then
|
|
if (currentTemp > 14) then
|
|
switchOffRadiateur(switchRadiateur)
|
|
--commandArray[switchRadiateur]='Off'
|
|
else
|
|
if variation <= 0 then
|
|
--commandArray[switchRadiateur]='On'
|
|
switchOnRadiateur(switchRadiateur)
|
|
end
|
|
end
|
|
debug ('CHECK Temperature chambre : Vacances -> ' ..otherdevices_svalues[switchTemp]..' switch='..switchRadiateur)
|
|
else
|
|
debug ('CHECK Temperature: Presence -> ' ..otherdevices_svalues[switchTemp]..' '..josdGetJourSemaine(jour))
|
|
-- Température non atteinte
|
|
if (currentTemp < consigne) then
|
|
if variation <= 0.0 then
|
|
-- commandArray[switchRadiateur]='On'
|
|
switchOnRadiateur(switchRadiateur)
|
|
debug("Demande chauffe : "..tostring(currentTemp).." / "..tostring(consigne).." Variation="..tostring(variation))
|
|
else
|
|
--switchIfNeeded(switchRadiateur, 'On')
|
|
-- Dépassement prévu dans le delai on coupe
|
|
if (estimation > 0 and estimation <= delai / 60 ) then
|
|
--commandArray[switchRadiateur] = 'Off'
|
|
switchOffRadiateur(switchRadiateur)
|
|
debug("Arrêt chauffage : Température sera atteinte dans le delai "..tostring(estimation).." Minutes")
|
|
else
|
|
debug("Aucune action. Chauffage en-cours."..tostring(currentTemp).." / "..tostring(consigne).." Variation="..tostring(variation))
|
|
end
|
|
end
|
|
-- Température dépassée
|
|
else
|
|
-- Température supérieure
|
|
if (currentTemp >= consigne + delta or (estimation > 0 and estimation <= delai / 60 )) then
|
|
if (consigne == consigneAbsence) then
|
|
-- rien
|
|
switchIfNeeded(switchRadiateur,"Off")
|
|
else
|
|
if (variation > 0) then
|
|
if (variationExt <= 0) then
|
|
switchOffRadiateur(switchRadiateur)
|
|
debug("Demande arrêt. Température dépassée.")
|
|
else
|
|
switchIfNeeded(switchRadiateur,"Off")
|
|
debug("Aucune action. Augmentation due à température extérieure.")
|
|
end
|
|
end
|
|
end
|
|
else
|
|
-- Augmentation de la température non due à l'augmentation extérieure
|
|
if (variation > 0) then
|
|
-- Pas d'augmentation extérieure
|
|
if (variationExt <= 0) then
|
|
--commandArray[switchRadiateur]='Off'
|
|
switchOffRadiateur(switchRadiateur)
|
|
debug("Demande arrêt. Température atteinte et continue d'augmenter.")
|
|
else
|
|
switchIfNeeded(switchRadiateur,"Off")
|
|
debug("Aucune action. Augmentation due à température extérieure.")
|
|
end
|
|
else
|
|
-- Températue en baisse pas nécessaire d'envoyer
|
|
--switchOffRadiateur(switchRadiateur)
|
|
--commandArray[switchRadiateur]='Off'
|
|
--switchIfNeeded(switchRadiateur, 'Off')
|
|
switchIfNeeded(switchRadiateur,"Off")
|
|
debug("Aucune action. Temperature atteinte et pas d'augmentation. "..tostring(currentTemp).." / "..tostring(consigne).." Variation="..tostring(variation))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
debug("------------------------------------------------------------")
|
|
end
|
|
|
|
-- ------------------------------------------------------
|
|
-- Arrêt tous les radiateurs
|
|
-- ------------------------------------------------------
|
|
if devicechanged['ChauffageGeneral'] then
|
|
if otherdevices['ChauffageGeneral'] == 'Off' then
|
|
for i = 1, 7 do
|
|
print("Arrêt radiateur="..radiateurs[i])
|
|
commandArray[radiateurs[i]]='Off'
|
|
end
|
|
end
|
|
end
|
|
|
|
-- ------------------------------------------------------
|
|
-- Chambre de Manon
|
|
-- ------------------------------------------------------
|
|
if devicechanged['ChambreManon'] or devicechanged['ConsigneConfortManon'] or devicechanged['ChauffageGeneral'] then
|
|
local consigne = tonumber(otherdevices_svalues['ConsigneConfortManon'])
|
|
gestionRadiateur('ChambreManon', 'RadiateurManon', consigne)
|
|
end
|
|
|
|
-- ------------------------------------------------------
|
|
-- Chambre de Theo
|
|
-- ------------------------------------------------------
|
|
if devicechanged['ChambreTheo'] or devicechanged['ConsigneConfortTheo'] or devicechanged['ChauffageGeneral'] then
|
|
local consigne = tonumber(otherdevices_svalues['ConsigneConfortTheo'])
|
|
gestionRadiateur('ChambreTheo', 'RadiateurTheo', consigne)
|
|
end
|
|
-- ------------------------------------------------------
|
|
-- Chambre parents
|
|
-- ------------------------------------------------------
|
|
if devicechanged['Chambre'] or devicechanged['ConsigneConfortChambre'] or devicechanged['ChauffageGeneral'] then
|
|
local consigne = tonumber(otherdevices_svalues['ConsigneConfortChambre'])
|
|
gestionRadiateur('Chambre', 'RadiateurChambre', consigne)
|
|
end
|
|
-- ------------------------------------------------------
|
|
-- Radiateur cuisine
|
|
-- ------------------------------------------------------
|
|
if devicechanged['TemperatureBarometre'] or devicechanged['ConsigneConfortSalon'] or devicechanged['ChauffageGeneral'] then
|
|
local consigne = tonumber(otherdevices_svalues['ConsigneConfortSalon'])
|
|
gestionRadiateur('TemperatureBarometre', 'RadiateurCuisine', consigne)
|
|
end
|
|
-- ------------------------------------------------------
|
|
-- Radiateur Salon
|
|
-- ------------------------------------------------------
|
|
if devicechanged['TemperatureBarometre'] or devicechanged['ConsigneConfortSalon'] or devicechanged['ChauffageGeneral'] then
|
|
local consigne = tonumber(otherdevices_svalues['ConsigneConfortSalon'])
|
|
gestionRadiateur('TemperatureBarometre', 'RadiateurSalon1', consigne)
|
|
gestionRadiateur('TemperatureBarometre', 'RadiateurSalon2', consigne)
|
|
end
|
|
|
|
-- ------------------------------------------------------
|
|
-- Radiateur Bureau
|
|
-- ------------------------------------------------------
|
|
if devicechanged['Bureau'] or devicechanged['ConsigneConfortBureau'] or devicechanged['ChauffageGeneral'] then
|
|
local consigne = tonumber(otherdevices_svalues['ConsigneConfortBureau'])
|
|
gestionRadiateur('Bureau', 'RadiateurBureau', consigne)
|
|
--gestionRadiateur('TemperatureBarometre', 'RadiateurSalon2', consigne)
|
|
end
|
|
|
|
|
|
return commandArray
|