first commit
This commit is contained in:
245
lua/old/script_time_general.old
Executable file
245
lua/old/script_time_general.old
Executable file
@@ -0,0 +1,245 @@
|
||||
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))
|
||||
|
||||
|
||||
--Initialise la commande de retour finale
|
||||
commandArray={}
|
||||
|
||||
-- -----------------------------------------------------------------------
|
||||
-- Test la dernière réception d'un switch et déclenche une alerte
|
||||
-- Il faut une variable de la forme PILE_nowswitch pour mettre à jour le
|
||||
-- témoin de notification envoyée
|
||||
-- -----------------------------------------------------------------------
|
||||
function levelBattery( switch )
|
||||
if (lastUpdateOfDevice(switch) > 3600 ) then
|
||||
if (uservariables['Variable:PILE_'..switch] == 'Normal') then
|
||||
commandArray['SendNotification']='Alerte niveau pile#Attention plus de réception de température depuis '..switch..'#0'
|
||||
commandArray['Variable:PILE_'..switch]='Plus de réception'
|
||||
end
|
||||
else
|
||||
commandArray['Variable:PILE_'..switch]='Normal'
|
||||
end
|
||||
end
|
||||
-- -----------------------------------------------------------------------
|
||||
-- Test le nombre d'erreur dans le log toutes les heures
|
||||
-- -----------------------------------------------------------------------
|
||||
if (minutes == 0) then
|
||||
local var = os.capture("grep Error /var/log/syslog |wc -l")
|
||||
--print(var)
|
||||
|
||||
if (tonumber(var) > 0 and tonumber(uservariables['Variable:Erreurs']) == 0) then
|
||||
commandArray['SendNotification']='Alerte Erreur '..var..'#Attention Il y a des erreurs dans domoticz #0'
|
||||
|
||||
end
|
||||
commandArray['Variable:Erreurs']=var
|
||||
end
|
||||
|
||||
-- -----------------------------------------------------------------------
|
||||
-- Vérifie le nombre de sequences capturées par motion
|
||||
-- -----------------------------------------------------------------------
|
||||
if (minutes % 10 == 0) then
|
||||
local f = io.popen("ls /home/pi/motion/ |grep avi| cut -c 1-2 |uniq| wc -l") -- runs command
|
||||
local l = f:read("*a") -- read output of command
|
||||
debug("Nombre de detection "..l)
|
||||
f:close()
|
||||
commandArray['PhotoMotion']=tostring(l)
|
||||
commandArray['UpdateDevice']="136|0|"..l
|
||||
end
|
||||
|
||||
-- -----------------------------------------------------------------------
|
||||
--recupere les minutes
|
||||
-- -----------------------------------------------------------------------
|
||||
if (minutes % 10 == 0) then
|
||||
debug('####### Lancement du check Presence ' ..heures..'h'..minutes)
|
||||
if (otherdevices['Vacances'] == 'On') then
|
||||
switchIfNeeded('Presence','Off')
|
||||
else
|
||||
--commandArray['Presence']='Off'
|
||||
------------------------------------------------------------------------
|
||||
if (josdJourChome() or otherdevices['PresenceForcee'] == 'On') then
|
||||
debug(' Jour Chômé / Presence normale à la maison')
|
||||
switchIfNeeded('Presence','On')
|
||||
else
|
||||
local jourS=josdGetJourSemaine()
|
||||
debug("jour "..jourS)
|
||||
if otherdevices['AbsenceFamille'] == 'Off' then
|
||||
if ((jourS == "mercredi" and (heures >= 13 or (heures == 12 and minutes >= 30)))
|
||||
or heures >= 17 or heures < 8
|
||||
or (heures == 8 and minutes <= 30)
|
||||
or otherdevices["Zone B"] == 'On' ) then
|
||||
debug(' Jour non Chômé pas de vacances '..tostring(heures))
|
||||
switchIfNeeded('Presence','On')
|
||||
else
|
||||
switchIfNeeded('Presence','Off')
|
||||
end
|
||||
else
|
||||
if (((heures == 8 and minutes <= 15) or heures < 8) or heures >= 20 or otherdevices['moi'] == 'On' or otherdevices['Akhenaton'] == 'On') then
|
||||
switchIfNeeded('Presence','On')
|
||||
else
|
||||
switchIfNeeded('Presence','Off')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- --------------------------------------------------------------------------------
|
||||
-- Vérification des dernières mises à jour des températures
|
||||
-- --------------------------------------------------------------------------------
|
||||
if (minutes%10== 0) then
|
||||
levelBattery('Bureau')
|
||||
levelBattery('ChambreManon')
|
||||
levelBattery('ChambreTheo')
|
||||
levelBattery('Chambre')
|
||||
--levelBattery('ATMEGA_TEMP_1')
|
||||
levelBattery('TemperatureBarometre')
|
||||
end
|
||||
|
||||
|
||||
-- --------------------------------------------------------------------------------
|
||||
-- Function to update a switch
|
||||
-- --------------------------------------------------------------------------------
|
||||
function updateSunset(zone)
|
||||
local cmd = "curl http://domogeek.entropialux.com/sun/" .. zone .. "/sunset/now"
|
||||
local vac = os.capture(cmd, true)
|
||||
debug("Sunset" .. cmd .. ": " .. vac)
|
||||
commandArray['Variable:Couche']=vac
|
||||
local cmd = "curl http://domogeek.entropialux.com/sun/" .. zone .. "/sunrise/now"
|
||||
local vac = os.capture(cmd, true)
|
||||
debug("Sunrise" .. cmd .. ": " .. vac)
|
||||
commandArray['Variable:Lever']=vac
|
||||
end
|
||||
|
||||
-- --------------------------------------------------------------------------------
|
||||
-- Trigger at 0:03 every day
|
||||
-- --------------------------------------------------------------------------------
|
||||
if (minutes == 3 and (heures == 0 or heures == 8)) then
|
||||
updateSunset("redon")
|
||||
end
|
||||
|
||||
-- -------------------------------------------------------------------
|
||||
-- Performance ping
|
||||
-- -------------------------------------------------------------------
|
||||
if (minutes % 10 == 0 ) then
|
||||
local f = io.popen("ping -c 5 192.168.0.1 2>/dev/null |grep rtt |awk -F = '{print $2}'|awk -F / '{print $2}'") -- runs command
|
||||
local l = f:read("*a") -- read output of command
|
||||
debug("##### Perf ping : temps de ping "..l)
|
||||
f:close()
|
||||
-- Perf Reseau
|
||||
commandArray['UpdateDevice']="145|0|"..l
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------
|
||||
-- Lampes eteinte après 22 heures 30 / 23 heures si pas d'activite depuis 10 minutes
|
||||
-- ------------------------------------------------------------------------------
|
||||
-- Pas de traitement en cas d'alerte fumée
|
||||
if otherdevices['DétecteurFuméeCuisine'] == "Normal"
|
||||
-- Pas de traitement si lampe allumée il y a moins d'une heure
|
||||
and (lastUpdateOfDevice('Lampe_Buffet') > 3600 and otherdevices['Lampe_Buffet'] == 'On')
|
||||
then
|
||||
if ((heures >= 23 or (heures == 22 and minutes >= 30)) and (minutes%5==0)) then
|
||||
|
||||
t1 = os.time()
|
||||
s = uservariables_lastupdate['DerniereDetection'] --otherdevices_lastupdate['Detecteur Salon']
|
||||
-- returns a date time like 2013-07-11 17:23:12
|
||||
year = string.sub(s, 1, 4)
|
||||
month = string.sub(s, 6, 7)
|
||||
day = string.sub(s, 9, 10)
|
||||
hour = string.sub(s, 12, 13)
|
||||
minu = string.sub(s, 15, 16)
|
||||
seconds = string.sub(s, 18, 19)
|
||||
|
||||
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minu, sec=seconds}
|
||||
difference = (os.difftime (t1, t2))
|
||||
debug("Eteindre les lumieres, DerniereDetection="..tostring(difference))
|
||||
if (difference > 300 or heures >= 23) then
|
||||
|
||||
switchIfNeeded('Salon_Halogene', 'Off')
|
||||
switchIfNeeded('Lampe_Buffet', 'Off')
|
||||
switchIfNeeded('LumiereTele', 'Off')
|
||||
switchIfNeeded('SonoJasper', 'Off')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Variation de pression
|
||||
if minutes%10 == 0 then
|
||||
|
||||
local pressure = otherdevices_svalues['Pression']
|
||||
local variationPressure = variationPressure('Barometre',60)
|
||||
|
||||
print("variationPressure="..tostring(variationPressure)..' Pression='..tostring(pressure))
|
||||
|
||||
|
||||
end
|
||||
|
||||
-- ---------------------------------
|
||||
-- Réglage des consigne temperature
|
||||
-- ---------------------------------
|
||||
if minutes%10 == 0 then
|
||||
|
||||
debug('####### Lancement du calcul consigne ' ..heures..'h'..minutes)
|
||||
|
||||
--commandArray['UpdateDevice'] = '214|0|25.00'
|
||||
|
||||
if (otherdevices['Vacances'] == 'On') then
|
||||
commandArray['UpdateDevice'] = "213|0|16.5" -- Chambre
|
||||
commandArray['UpdateDevice'] = "211|0|16.5" -- ChambreTheo
|
||||
commandArray['UpdateDevice'] = "212|0|16.5" -- ChambreManon
|
||||
commandArray['UpdateDevice'] = "214|0|16.5" -- Bureau
|
||||
else
|
||||
--commandArray['Presence']='Off'
|
||||
------------------------------------------------------------------------
|
||||
if (josdJourChome() or otherdevices['PresenceForcee'] == 'On') then
|
||||
debug(' Jour Chômé / consigne temperature présence')
|
||||
commandArray['UpdateDevice'] = "213|0|18" -- Chambre
|
||||
commandArray['UpdateDevice'] = "211|0|18.5" -- ChambreTheo
|
||||
commandArray['UpdateDevice'] = "212|0|18.5" -- ChambreManon
|
||||
commandArray['UpdateDevice'] = "214|0|18" -- Bureau
|
||||
else
|
||||
local jourS=josdGetJourSemaine()
|
||||
debug("jour "..jourS)
|
||||
if otherdevices['AbsenceFamille'] == 'Off' then
|
||||
if ((jourS == "mercredi" and (heures >= 13 or (heures == 12 and minutes >= 30)))
|
||||
or heures >= 17 or heures < 8
|
||||
or (heures == 8 and minutes <= 30)
|
||||
or otherdevices["Zone B"] == 'On' ) then
|
||||
debug(' Jour non Chômé pas de vacances '..tostring(heures))
|
||||
commandArray['UpdateDevice'] = "213|0|18" -- Chambre
|
||||
commandArray['UpdateDevice'] = "211|0|18.5" -- ChambreTheo
|
||||
commandArray['UpdateDevice'] = "212|0|18.5" -- ChambreManon
|
||||
commandArray['UpdateDevice'] = "214|0|18" -- Bureau
|
||||
|
||||
else
|
||||
commandArray['UpdateDevice'] = "213|0|16.5" -- Chambre
|
||||
commandArray['UpdateDevice'] = "211|0|16.5" -- ChambreTheo
|
||||
commandArray['UpdateDevice'] = "212|0|16.5" -- ChambreManon
|
||||
commandArray['UpdateDevice'] = "214|0|16.5" -- Bureau
|
||||
end
|
||||
else
|
||||
if (((heures == 8 and minutes <= 15) or heures < 8) or heures >= 20 or otherdevices['moi'] == 'On'
|
||||
or otherdevices['Akhenaton'] == 'On') then
|
||||
commandArray['UpdateDevice'] = "213|0|18" -- Chambre
|
||||
commandArray['UpdateDevice'] = "211|0|18.5" -- ChambreTheo
|
||||
commandArray['UpdateDevice'] = "212|0|18.5" -- ChambreManon
|
||||
commandArray['UpdateDevice'] = "214|0|18" -- Bureau
|
||||
else
|
||||
commandArray['UpdateDevice'] = "213|0|16.5" -- Chambre
|
||||
commandArray['UpdateDevice'] = "211|0|16.5" -- ChambreTheo
|
||||
commandArray['UpdateDevice'] = "212|0|16.5" -- ChambreManon
|
||||
commandArray['UpdateDevice'] = "214|0|16.5" -- Bureau
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- return commandArray
|
||||
Reference in New Issue
Block a user