first commit

This commit is contained in:
Souti
2025-03-06 11:09:58 +01:00
commit 11f7d440ff
330 changed files with 38306 additions and 0 deletions

485
lua/script_device_Radiateur.lua Executable file
View File

@@ -0,0 +1,485 @@
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
function callExternal(command)
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()
--debug("Commande = "..command.." "..result)
return result
end
-- ------------------------------------------------------------------------------
-- Test temperature radiateur chambres
-- ------------------------------------------------------------------------------
function gestionRadiateurInv( switchTemp, switchRadiateur, consigne)
local intervalle = tonumber(uservariables['Intervalle_Chauffe'])
--if (minutes % intervalle ~= 0) then
--return
--end
local last = lastUpdateOfDevice(switchRadiateur)
local local_delai = delai
debug("--------------"..switchRadiateur.."-----------------------------------")
debug(tostring(switchRadiateur).." local_delai="..tostring(local_delai).." last="..tostring(last)..' Chauffage='..otherdevices[switchRadiateur])
debug("------------------------------------------------------------")
local currentTemp = tonumber(otherdevices_svalues[switchTemp])
local delta = 0.2
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
print("GR 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: local_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
print("GR Retour variation="..tostring(variation).." switch="..switchRadiateur..' lastUpdate='..tostring(last))
debug('CHECK Temperature Variation='..tostring(variation)..' switch='..switchRadiateur..' currentTemp='..tostring(currentTemp).. ' tempAbsence='..tostring(tempAbsence)..' consigne='..tostring(consigne))
-- if otherdevices['ChauffageGeneral'] == 'Off' then
-- if (minutes%5 == 0) then
-- if (currentTemp >= consigne + delta) then
-- switchOn(switchRadiateur)
-- end
-- debug("Radiateur ="..switchRadiateur.." Retour sans rien faire. ChauffageGeneral Eteint.")
-- end
-- return
-- end
if last < local_delai then
debug("Radiateur ="..switchRadiateur.." Retour sans rien faire. local_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
switchIfNeeded(switchRadiateur,"On")
--commandArray[switchRadiateur]='Off'
else
if variation <= 0 then
--commandArray[switchRadiateur]='On'
switchIfNeeded(switchRadiateur,"Off")
end
end
print("GR "..tostring(switchRadiateur)..' Temperature chambre : Vacances -> ' ..otherdevices_svalues[switchTemp]..' switch='..switchRadiateur)
else
print("GR "..tostring(switchRadiateur)..' Temperature: Presence -> ' ..otherdevices_svalues[switchTemp]..' '..josdGetJourSemaine(jour))
-- Température non atteinte
if (currentTemp < consigne) then
if variation <= 0.0 then
switchIfNeeded(switchRadiateur,"Off")
debug("Demande chauffe : "..tostring(currentTemp).." / "..tostring(consigne).." Variation="..tostring(variation))
else
-- Dépassement prévu dans le local_delai on coupe
if (estimation > 0 and estimation <= local_delai / 60 ) then
switchIfNeeded(switchRadiateur,"On")
debug("Arrêt chauffage : Température sera atteinte dans le local_delai "..tostring(estimation).." Minutes")
else
if estimation > 60 then
switchIfNeeded(switchRadiateur,"Off")
debug("Demande chauffe dela trop long : "..tostring(currentTemp).." / "..tostring(consigne).." Variation="..tostring(variation))
else
debug("Aucune action. Chauffage en-cours."..tostring(currentTemp).." / "..tostring(consigne).." Variation="..tostring(variation))
end
end
end
-- Température dépassée
else
-- Température supérieure
if (currentTemp >= consigne + delta or (estimation > 0 and estimation <= local_delai / 60 )) then
if (consigne == consigneAbsence) then
-- rien
if (variation > 0) then
switchIfNeeded(switchRadiateur,"On")
debug("Demande arrêt. Température dépassée et augmente.")
else
debug("Aucune consigne. Température dépassée et diminue.")
end
else
if (variation > 0) then
if (variationExt <= 0) then
switchIfNeeded(switchRadiateur,"On")
debug("Demande arrêt. Température dépassée.")
else
switchIfNeeded(switchRadiateur,"On")
debug("Aucune action. Augmentation due à température extérieure.")
end
else
-- switchIfNeeded(switchRadiateur,"On")
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
switchIfNeeded(switchRadiateur,"On")
debug("Demande arrêt. Température atteinte et continue d'augmenter.")
else
switchIfNeeded(switchRadiateur,"On")
debug("Aucune action. Augmentation due à température extérieure.")
end
else
-- Températue en baisse pas nécessaire d'envoyer
switchIfNeeded(switchRadiateur,"On")
debug("Aucune action. Temperature atteinte et pas d'augmentation. "..tostring(currentTemp).." / "..tostring(consigne).." Variation="..tostring(variation))
end
end
end
end
debug("------------------------------------------------------------")
end
-- ------------------------------------------------------------------------------
-- Test temperature radiateur chambres
-- ------------------------------------------------------------------------------
function gestionRadiateur( switchTemp, switchRadiateur, consigne)
local intervalle = tonumber(uservariables['Intervalle_Chauffe'])
-- if (minutes % intervalle ~= 0) or switchRadiateur == "RadiateurGrenier" then
-- return
-- end
local chauffe_eau = tonumber(split(otherdevices['Chauffe_Eau'], ";")[1])
local currentTemp = getTemperatureFromDevice(switchTemp)
local last = lastUpdateOfDevice(switchRadiateur)
local local_delai = delai
if switchRadiateur == "RadiateurGrenier" then
local_delai = 60
end
print("GR --------------"..switchRadiateur.."-----------------------------------")
values2 = split(otherdevices['CONSOMMATION_GENERALE'], ";")
print("GR Dans Radiateur CONSOMMATION_GENERALE tabs "..otherdevices['CONSOMMATION_GENERALE'])
print("GR "..tostring(switchRadiateur).." local_delai="..tostring(local_delai).." last="..tostring(last)..' Chauffage='..otherdevices[switchRadiateur] .. " currentTemp="..tostring(currentTemp) )
if last < local_delai then
print("GR Radiateur ="..switchRadiateur.." Retour sans rien faire. local_delai non atteint.")
return
end
watt = tonumber(values2[1])
if watt > 8000 then
if otherdevices["RadiateurBureau"] == 'On' then
print("GR "..tostring(switchRadiateur).." Dans Radiateur Haute consommation arrêt bureau")
switchOffRadiateur("RadiateurBureau")
elseif otherdevices["RadiateurBureau"] == 'On' then
print("GR "..tostring(switchRadiateur).." Dans Radiateur Haute consommation arrêt porte salon")
switchOffRadiateur("RadiateurPorteSalon")
elseif otherdevices["RadiateurCuisine"] == 'On' then
print("GR "..tostring(switchRadiateur).." Dans Radiateur Haute consommation arrêt cuisine")
switchOffRadiateur("RadiateurCuisine")
elseif otherdevices["RadiateurCheminee"] == 'On' then
print("GR "..tostring(switchRadiateur).." Dans Radiateur Haute consommation arrêt Cheminee")
switchOffRadiateur("RadiateurCheminee")
elseif otherdevices["RadiateurMilieu"] == 'On' then
print("GR "..tostring(switchRadiateur).." Dans Radiateur Haute consommation arrêt milieu")
switchOffRadiateur("RadiateurMilieu")
end
end
--print("GR ------------------------------------------------------------")
--debug(getTemperatureFromDevice(switchTemp));
--local currentTemp = tonumber(otherdevices_svalues[switchTemp])
local time_variation = 30
local delta = 0.2
local tempAbsence = tonumber(otherdevices_svalues['ConsigneAbsence'])
local variation = variationTemp2(switchTemp, time_variation) -- variation des 10 dernières minutes
local variationExt = uservariables['AugmentationTempExterieure']
local augmentation = variation * 60 / time_variation --time -- ° par heure
local ecart = consigne - currentTemp
local estimation = 0.0
if (augmentation > 0 and ecart > 0) then
estimation = 60 * ecart / augmentation
end
--if (switchRadiateur=="RadiateurCheminee" and augmentation > 1) then
-- arretRadiateursSalon('ChauffageGeneral')
--end
print("GR "..tostring(switchRadiateur).." 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: local_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
print("GR "..tostring(switchRadiateur).." Retour variation="..tostring(variation).." switch="..switchRadiateur..' lastUpdate='..tostring(last))
print("GR "..tostring(switchRadiateur).." Temperature Variation="..tostring(variation)..' switch='..switchRadiateur..' currentTemp='..tostring(currentTemp).. ' tempAbsence='..tostring(tempAbsence)..' consigne='..tostring(consigne))
if otherdevices['ChauffageGeneral'] == 'Off' then
if (minutes%5 == 0) then
if (currentTemp >= consigne + delta) then
switchOff(switchRadiateur)
end
debug("ChauffageGeneral Eteint. Demande extinction.")
else
debug("Radiateur ="..switchRadiateur.." Retour sans rien faire. ChauffageGeneral Eteint.")
end
return
end
if (currentTemp >= consigne + 2 * delta) then
print("GR Radiateur ="..switchRadiateur.." arret immediat température > consigne + 2 * delta.")
switchIfNeeded(switchRadiateur,"Off")
return
end
-- Periode de vacances ou absence ==> hors gel
if (otherdevices['Vacances'] == 'On' or otherdevices['AbsenceFamille'] == 'On') then
if (currentTemp > 14) then
switchIfNeeded(switchRadiateur,"Off")
--commandArray[switchRadiateur]='Off'
else
if variation <= 0 then
--commandArray[switchRadiateur]='On'
switchIfNeeded(switchRadiateur,"On")
end
end
print("GR "..tostring(switchRadiateur)..' Temperature chambre : Vacances -> ' ..otherdevices_svalues[switchTemp]..' switch='..switchRadiateur)
else
print("GR "..tostring(switchRadiateur)..' Temperature: Presence -> ' ..otherdevices_svalues[switchTemp]..' '..josdGetJourSemaine(jour))
-- Température non atteinte
if (currentTemp < consigne - delta) then
debug('Temperature non atteinte')
if variation <= 0.0 then
-- commandArray[switchRadiateur]='On'
switchIfNeeded(switchRadiateur,"On")
print("GR "..tostring(switchRadiateur).."Demande chauffe : "..tostring(currentTemp).." / "..tostring(consigne).." Variation="..tostring(variation))
else
--switchIfNeeded(switchRadiateur, 'On')
-- Dépassement prévu dans le local_delai on coupe
if (estimation > 0 and estimation <= local_delai / 60 ) then
--commandArray[switchRadiateur] = 'Off'
switchIfNeeded(switchRadiateur,"Off")
print("GR "..tostring(switchRadiateur).." Arrêt chauffage : Température sera atteinte dans le local_delai "..tostring(estimation).." Minutes")
else
if estimation > 60 then
switchIfNeeded(switchRadiateur,"On")
debug("Demande chauffe dela trop long : "..tostring(currentTemp).." / "..tostring(consigne).." Variation="..tostring(variation))
else
debug("Aucune action. Chauffage en-cours."..tostring(currentTemp).." / "..tostring(consigne).." Variation="..tostring(variation))
end
end
end
-- Température dépassée
else
debug('Temperature supérieure')
-- Température supérieure
if (currentTemp >= consigne + delta or (estimation > 0 and estimation <= local_delai / 60 )) then
if (consigne == consigneAbsence) then
switchIfNeeded(switchRadiateur,"Off")
else
if (variation > 0) then
if (variationExt <= 0) then
switchIfNeeded(switchRadiateur,"Off")
debug("Demande arrêt. Température dépassée.")
else
switchIfNeeded(switchRadiateur,"Off")
debug("Aucune action. Augmentation due à température extérieure.")
end
else
debug('Aucune variation')
switchIfNeeded(switchRadiateur,"Off")
end
end
else if (currentTemp <= consigne - delta) then
-- Augmentation de la température non due à l'augmentation extérieure
if (variation > 0) then
-- Pas d'augmentation extérieure
if (variationExt <= 0) then
switchIfNeeded(switchRadiateur,"Off")
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
switchIfNeeded(switchRadiateur,"Off")
debug("Aucune action. Temperature atteinte et pas d'augmentation. "..tostring(currentTemp).." / "..tostring(consigne).." Variation="..tostring(variation))
end
end
end
end
end
debug("------------------------------------------------------------")
end
-- ------------------------------------------------------------------------------
-- Test temperature radiateur salon et cuisine
-- ------------------------------------------------------------------------------
function gestionRadiateurSalon( switchTemp, switchRadiateur, consigne)
local currentTemp = tonumber(otherdevices_svalues[switchTemp])
local tempAbsence = tonumber(otherdevices_svalues['ConsigneAbsence'])
if otherdevices['ChauffageGeneral'] == 'Off' then
if (minutes%30 == 0) then
switchOffRadiateur(switchRadiateur)
else
debug("Radiateur ="..switchRadiateur.." Retour sans rien faire. ChauffageGeneral Eteint.")
end
end
-- Periode de vacances ou absence ==> hors gel
if (otherdevices['Vacances'] == 'On' or otherdevices['Presence'] == 'Off') then
if (currentTemp > tempAbsence) then
switchOffRadiateur(switchRadiateur)
else
switchOnRadiateur(switchRadiateur)
end
print("GR "..tostring(switchRadiateur)..' Temperature Salon: Vacances -> ' ..otherdevices_svalues[switchTemp]..' switch='..switchRadiateur)
else
-- Samedi Dimanche ou jour férié ou mercredi
if (jour == 0 or jour == 6 or josdJourChome() or jour == 3) then
print("GR "..tostring(switchRadiateur)..' Temperature: Presence -> ' ..otherdevices_svalues[switchTemp]..' '..josdGetJourSemaine(jour))
if (currentTemp < tempAbsence
or (currentTemp <= consigne and heures >= 08 and heures <= 24)) then
switchOnRadiateur(switchRadiateur)
else
switchOffRadiateur(switchRadiateur)
end
else
print("GR "..tostring(switchRadiateur)..' Temperature: Travail -> ' ..otherdevices_svalues[switchTemp]..' '..josdGetJourSemaine(jour))
if (currentTemp < tempAbsence
or (currentTemp <= (consigne - 1) and heures >= 17)
or (currentTemp <= consigne and heures >= 19 and heures < 23)) then
switchOnRadiateur(switchRadiateur)
else
switchOffRadiateur(switchRadiateur)
end
end
end
end
-- ------------------------------------------------------
-- Arrêt tous les radiateurs
-- ------------------------------------------------------
if devicechanged['ChauffageGeneral'] then
print("Chauffage General "..otherdevices['ChauffageGeneral'])
if otherdevices['ChauffageGeneral'] == 'Off' then
-- for i = 1, 7 do
for i,radiateur in ipairs(radiateurs) do
print("Chauffage General Arrêt radiateur="..radiateur)
commandArray[radiateur]='Off'
end
end
end
local saison = uservariables["Saison"]
if otherdevices['ChauffageGeneral'] == 'On' then
-- ----------------------------------------------------
-- Chambre de Manon
-- ------------------------------------------------------
if devicechanged['ChambreManon'] or devicechanged['ConsigneConfortManon'] or devicechanged['ChauffageGeneral']
then --or tonumber(lastUpdateOfDevice('ChambreManon')) > 2 * delai 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 -- or tonumber(lastUpdateOfDevice('ChambreTheo')) > 2 * delai then
local consigne = tonumber(otherdevices_svalues['ConsigneConfortTheo'])
gestionRadiateur('ChambreTheo', 'RadiateurTheo', consigne)
end
-- ------------------------------------------------------
-- Chambre parents
-- ------------------------------------------------------
if devicechanged['Chambre'] or devicechanged['ConsigneConfortChambre'] or devicechanged['ChauffageGeneral']
then --or tonumber(lastUpdateOfDevice('Chambre')) > 2 * delai then
local consigne = tonumber(otherdevices_svalues['ConsigneConfortChambre'])
gestionRadiateur('Chambre', 'RadiateurChambre', consigne)
end
-- ------------------------------------------------------
-- Radiateur cuisine
-- ------------------------------------------------------
if devicechanged['TemperatureCuisine'] or devicechanged['ConsigneConfortSalon'] or devicechanged['ChauffageGeneral']
then -- or tonumber(lastUpdateOfDevice('TemperatureCuisine')) > 2 * delai then
local consigne = tonumber(otherdevices_svalues['ConsigneConfortSalon'])
gestionRadiateur('TemperatureCuisine', 'RadiateurCuisine', consigne)
end
-- ------------------------------------------------------
-- Radiateur Cheminee
-- ------------------------------------------------------
if devicechanged['Cheminee'] or devicechanged['ConsigneConfortSalon'] or devicechanged['ChauffageGeneral']
then -- or tonumber(lastUpdateOfDevice('Cheminee')) > 2 * delai then
local consigne = tonumber(otherdevices_svalues['ConsigneConfortSalon']) - 1 --0.2
gestionRadiateur('Cheminee', 'RadiateurCheminee', consigne)
end
-- ------------------------------------------------------
-- Radiateur Salon
-- ------------------------------------------------------
if devicechanged['TemperatureSalon'] or devicechanged['ConsigneConfortSalon'] or devicechanged['ChauffageGeneral']
then -- or tonumber(lastUpdateOfDevice('TemperatureSalon')) > 2 * delai then
local consigne = tonumber(otherdevices_svalues['ConsigneConfortSalon'])
gestionRadiateur('TemperatureSalon', 'RadiateurPorteSalon', consigne)
gestionRadiateur('TemperatureSalon', 'RadiateurMilieu', consigne)
end
-- ------------------------------------------------------
-- Radiateur Bureau
-- ------------------------------------------------------
if devicechanged['Bureau'] or devicechanged['ConsigneConfortBureau'] or devicechanged['ChauffageGeneral']
then -- or tonumber(lastUpdateOfDevice('Bureau')) > 2 * delai then
local consigne = tonumber(otherdevices_svalues['ConsigneConfortBureau'])
gestionRadiateur('Bureau', 'RadiateurBureau', consigne)
--gestionRadiateur('TemperatureBarometre', 'RadiateurCheminee', consigne)
end
-- ------------------------------------------------------
-- Radiateur Grenier
-- ------------------------------------------------------
if (devicechanged['TemperatureGrenier'] or devicechanged['ConsigneConfortGrenier'] or devicechanged['ChauffageGeneral'] or devicechanged['Force_Grenier'])
then -- or tonumber(lastUpdateOfDevice('TemperatureGrenier')) > 2 * delai then
local consigne = tonumber(otherdevices_svalues['ConsigneConfortGrenier'])
gestionRadiateur('TemperatureGrenier', 'RadiateurGrenierAcova', consigne)
--gestionRadiateur('TemperatureBarometre', 'RadiateurCheminee', consigne)
end
end
return commandArray