230 lines
8.9 KiB
Lua
Executable File
230 lines
8.9 KiB
Lua
Executable File
require "scripts/lua/functions"
|
|
|
|
commandArray = {}
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
--recupere les minutes
|
|
-- ------------------------------------------------------------------------------
|
|
time=os.time()
|
|
minutes=tonumber(os.date('%M',time))
|
|
jour=tonumber(os.date('%w',time))
|
|
quantieme=tonumber(os.date('%j',time))
|
|
heures=tonumber(os.date('%H',time))
|
|
heurmin= heures * 60 + minutes
|
|
|
|
extinction = uservariables['HEURE_EXTINCTION_FEUX']
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- Test check
|
|
-- ------------------------------------------------------------------------------
|
|
-- List all otherdevices states for debugging:
|
|
-- for i, v in pairs(otherdevices) do debug(i..' '..v) end
|
|
-- List all otherdevices svalues for debugging:
|
|
-- for i, v in pairs(otherdevices_svalues) do debug('svalues '..i..' '..v) end
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- Pollens tous les lundis
|
|
-- ------------------------------------------------------------------------------
|
|
if (jour == 1 and devicechanged['Pollens']) then
|
|
debug("Nouveau bulletin pollens")
|
|
|
|
commandArray['SendNotification']='Pollens#Nouveau bulletin pollen http://www.pollens.fr/docs/vigilance.html#0'
|
|
end
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- Derniere détection
|
|
-- ------------------------------------------------------------------------------
|
|
if devicechanged['Detecteur Salon'] or devicechanged['Detecteur Bureau'] then
|
|
commandArray['Variable:DerniereDetection'] = tostring(heures)..":"..tostring(minutes)
|
|
debug("DerniereDetection"..tostring(heures)..":"..tostring(minutes))
|
|
end
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- Température extérieure a changé, mise à jour du chauffage central
|
|
-- ------------------------------------------------------------------------------
|
|
if devicechanged['BarometreLaGacilly'] then
|
|
local variation = variationTemp('BarometreLaGacilly')
|
|
|
|
--if (minutes%30==0) then
|
|
--local variationBarometer = variationPressure('BarometreLaGacilly', 30)
|
|
--print("variationBarometer="..tostring(variationBarometer))
|
|
local tempExt = getTemperatureFromDevice('BarometreLaGacilly')
|
|
local humidityExt = getHumidityFromDevice('BarometreLaGacilly')
|
|
--print(split(otherdevices_svalues['BarometreLaGacilly'],";")[1]);
|
|
local consigne = 13 -- tonumber(otherdevices_svalues['ConsigneChauffageGeneral'])
|
|
debug (otherdevices_svalues['BarometreLaGacilly']..' Consigne='..otherdevices_svalues['ConsigneChauffageGeneral']..' TempExt='..tostring(tempExt)..' humidityExt='..tostring(humidityExt))
|
|
|
|
if heures == 23 and minutes == 00 then
|
|
if tempExt < consigne and (quantieme < 92 or quantieme > 275) then
|
|
switchIfNeeded('ChauffageGeneral','On')
|
|
end
|
|
if tempExt >= consigne then
|
|
switchIfNeeded('ChauffageGeneral','Off')
|
|
end
|
|
end
|
|
|
|
if humidityExt > 65 then
|
|
switchIfNeeded('Deshumidificateur','On')
|
|
else
|
|
if humidityExt < 60 then
|
|
switchIfNeeded('Deshumidificateur','Off')
|
|
end
|
|
end
|
|
|
|
debug("Retour variation="..tostring(variation).." switch="..'BarometreLaGacilly tempExt='..tostring(tempExt))
|
|
--end
|
|
|
|
end
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- Test suivi consommation électrique
|
|
-- ------------------------------------------------------------------------------
|
|
--debug(otherdevices['ConsoCapteurHC'])
|
|
--debug("ConsocapteurHP="..otherdevices_svalues['ConsoCapteurHP'])
|
|
|
|
if devicechanged['Capteur électricité'] then
|
|
debug("Electricité a changé")
|
|
|
|
local val
|
|
local val2
|
|
val, val2 = otherdevices_svalues['Capteur électricité']:match("([^;]+);([^;]+)")
|
|
val = tonumber(val)
|
|
debug(val)
|
|
--debug('#### HC '..otherdevices['ConsoCapteurHC'])
|
|
--debug('#### HP '..otherdevices['ConsoCapteurHP'])
|
|
if val > 2200 or val == nil then
|
|
debug("Reception de données incohérentes pour la consommation électrique "..tostring(val))
|
|
else
|
|
val = val - 50
|
|
if uservariables['HeuresCreuses'] == 'On' then
|
|
|
|
-- Recuperation des valeurs du compteur global
|
|
local consoCumule
|
|
local consoInstant
|
|
consoInstant, consoCumule = otherdevices_svalues['ConsoCapteurHC']:match("([^;]+);([^;]+)")
|
|
consoInstant = tonumber(consoInstant)
|
|
consoCumule = tonumber(consoCumule)
|
|
|
|
debug('Conso Instant = '..tostring(consoInstant)..' / Conso Cumule = '..tostring(consoCumule)..' ')
|
|
|
|
local timeLast = lastUpdateOfDevice('ConsoCapteurHC')
|
|
|
|
local joules = val * timeLast -- Puissance en W * second = Joule
|
|
|
|
local wattH = joules / 3600
|
|
|
|
if (consoCumule == nil) then consoCumule = 0 end
|
|
if (val < 0) then wattH = 0 end
|
|
commandArray['UpdateDevice'] = '197|0|'..tostring(wattH)..';'..tostring(consoCumule + wattH)
|
|
|
|
debug("Ajout en heures creuses wattH "..tostring(wattH)..'; total '..tostring(consoCumule + wattH))
|
|
else
|
|
-- Recuperation des valeurs du compteur global
|
|
local consoCumule
|
|
local consoInstant
|
|
consoInstant, consoCumule = otherdevices_svalues['ConsoCapteurHP']:match("([^;]+);([^;]+)")
|
|
consoInstant = tonumber(consoInstant)
|
|
consoCumule = tonumber(consoCumule)
|
|
|
|
debug('Conso Instant = '..tostring(consoInstant)..' / Conso Cumule = '..tostring(consoCumule)..' ')
|
|
|
|
--local current = tonumber(otherdevices_svalues['ConsoCapteurHP'])
|
|
--if current == nil then current = 0 end
|
|
|
|
local timeLast = lastUpdateOfDevice('ConsoCapteurHP')
|
|
|
|
local joules = val * timeLast -- Puissance en W * second = Joule
|
|
|
|
local wattH = joules / 3600
|
|
if (val < 0) then wattH = 0 end
|
|
commandArray['UpdateDevice'] = '196|0|'..tostring(wattH)..';'..tostring(consoCumule + wattH)
|
|
|
|
debug("Ajout en heures pleines wattH "..tostring(wattH)..'; total '..tostring(consoCumule + wattH))
|
|
end
|
|
end
|
|
end
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- Mode vacances
|
|
-- ------------------------------------------------------------------------------
|
|
-- ------------------------------------------------------------------------------
|
|
-- Envoi de notification
|
|
-- ------------------------------------------------------------------------------
|
|
-- Vacances
|
|
if devicechanged['Vacances'] then
|
|
debug("Mode vacances a change")
|
|
commandArray['SendNotification']='Mode vacances#Le mode vacances a ete modifie#0'
|
|
|
|
if otherdevices['Vacances'] == 'On' then
|
|
-- non on conserve internet switchIfNeeded('PriseInternet', 'Off')
|
|
switchIfNeeded('Lampe_Halogene', 'Off')
|
|
switchIfNeeded('Lampe_Buffet', 'Off')
|
|
switchIfNeeded('Lampe_Tele', 'Off')
|
|
switchIfNeeded('SonoJasper', 'Off')
|
|
|
|
switchOffRadiateur('RadiateurManon')
|
|
switchOffRadiateur('RadiateurTheo')
|
|
switchOffRadiateur('RadiateurBureau')
|
|
switchOffRadiateur('RadiateurChambre')
|
|
switchOffRadiateur('RadiateurCuisine')
|
|
switchOffRadiateur('RadiateurMilieu')
|
|
switchOffRadiateur('RadiateurCheminee')
|
|
end
|
|
end
|
|
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- Plus d'internet on redémarre
|
|
-- ------------------------------------------------------------------------------
|
|
if --otherdevices['Vacances'] == 'Off' and
|
|
devicechanged['Internet'] and otherdevices['Internet'] == 'Off' then
|
|
commandArray['PriseInternet'] = 'Off'
|
|
sleep(10)
|
|
commandArray['PriseInternet'] = 'On'
|
|
end
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- Absence famille mais présence moi
|
|
-- ------------------------------------------------------------------------------
|
|
if otherdevices['Vacances'] == 'Off' and devicechanged['AbsenceFamille'] then
|
|
if otherdevices['AbsenceFamille'] == 'Off' then
|
|
switchOffRadiateur('RadiateurTheo')
|
|
switchOffRadiateur('RadiateurChambre')
|
|
else
|
|
switchOnRadiateur('RadiateurTheo')
|
|
switchOnRadiateur('RadiateurChambre')
|
|
end
|
|
end
|
|
-- ------------------------------------------------------------------------------
|
|
-- Determination de l'augmentation de la temperature exterieure
|
|
-- ------------------------------------------------------------------------------
|
|
if devicechanged['BarometreLaGacilly'] then
|
|
print("--------------TemperatureLaGacilly--------------------------------")
|
|
|
|
local variation, time = getVariation('BarometreLaGacilly')
|
|
|
|
local augmentation = variation * 60 / time -- ° par heure
|
|
|
|
print("Retour augmentation="..tostring(augmentation))
|
|
|
|
commandArray['Variable:AugmentationTempExterieure'] = tostring(augmentation)
|
|
|
|
print("------------------------------------------------------------------")
|
|
|
|
--local currentTemp = tonumber(otherdevices_svalues['Bureau']
|
|
local tempExt = getTemperatureFromDevice('BarometreLaGacilly')
|
|
|
|
debug("-------------- Ventilo Bureau------------------- "..tostring(tempExt))
|
|
|
|
|
|
if (tempExt < 8.5) then
|
|
switchOn('VentilateurBureau')
|
|
else
|
|
switchOff('VentilateurBureau')
|
|
end
|
|
|
|
end
|
|
|
|
|
|
return commandArray
|