163 lines
5.4 KiB
Lua
Executable File
163 lines
5.4 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))
|
|
day=tonumber(os.date('%d',time))
|
|
|
|
heures=tonumber(os.date('%H',time))
|
|
heurmin= heures * 60 + minutes
|
|
mois=tonumber(os.date('%m',time))
|
|
|
|
extinction = uservariables['HEURE_EXTINCTION_FEUX']
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- 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
|
|
|
|
-- Quelqu'un est reveillé on ouvre les volets
|
|
if devicechanged['Detecteur Bureau'] or devicechanged['Detecteur Salon'] then
|
|
if ((heures >= 6) and (heures <= 9))
|
|
and otherdevices['VoletPorteSalon'] == 'Closed'
|
|
and lastUpdateOfDevice('VoletPorteSalon') > 120
|
|
then
|
|
os.execute("/opt/domoticz/scripts/volets3.sh Off &")
|
|
end
|
|
if (heures >= 23)
|
|
and otherdevices['VoletPorteSalon'] == 'Open'
|
|
then
|
|
-- os.execute("/opt/domoticz/scripts/volets2.sh On &")
|
|
end
|
|
end
|
|
|
|
-- Volets
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- Lampes allumees si presence détéctée
|
|
-- ------------------------------------------------------------------------------
|
|
if devicechanged['Detecteur Bureau'] or devicechanged['Detecteur Salon']
|
|
--or devicechanged['Lux']
|
|
or devicechanged['Presence'] or
|
|
devicechanged['Philae'] or devicechanged['Akhesa'] or
|
|
devicechanged['Moi'] or devicechanged['Domi'] or
|
|
devicechanged['Theo'] or devicechanged['Manon'] or
|
|
devicechanged['DetectionCamera1']
|
|
--or true
|
|
then
|
|
print("LAMPE : test allumage lampes")
|
|
local sunriseMin = heureEnMinute(uservariables["Lever"])
|
|
local now = 60 * heures + minutes
|
|
|
|
if (otherdevices['Vacances'] == 'On' or otherdevices['Presence'] == 'Off'
|
|
or ((mois >= 6 and mois <= 7) or (mois == 8 and day < 15))) then
|
|
print("LAMPE : desactivation"..tostring(mois)..' '..tostring(day))
|
|
|
|
switchLightsIfNeeded('Off')
|
|
elseif (otherdevices['Vacances'] == 'Off' and otherdevices['Presence'] == 'On') then
|
|
|
|
if (whenDark() <= 15) then -- and otherdevices['VoletPorteSalon'] == 'Open') then
|
|
if (
|
|
(heures >= 7 and heures <= 10 and not josdJourChome())
|
|
or (heures >= 14 and
|
|
(
|
|
(heures < 22) --or (heures == 22 and minutes < 30)
|
|
)
|
|
)
|
|
) then
|
|
print("LAMPE Allumer les lampes")
|
|
switchLightsIfNeeded('On')
|
|
else
|
|
if (heures > 22) or heures < 7 then
|
|
switchLightsIfNeeded('Off')
|
|
print("LAMPE Eteindre les lampes")
|
|
end
|
|
end
|
|
else
|
|
if (now > sunriseMin) then -- and lum > luxMini) then
|
|
switchLightsIfNeeded('Off')
|
|
print("LAMPE Eteindre les lampes")
|
|
elseif (heures >= 22) or heures < 7 then
|
|
switchLightsIfNeeded('Off')
|
|
print("LAMPE Eteindre les lampes")
|
|
end
|
|
end
|
|
else
|
|
print("LAMPE Dans le else "..tostring(heures))
|
|
end
|
|
end
|
|
|
|
--end
|
|
|
|
-- ------------------------------------------------------------------------------
|
|
-- Envoi de notification si detection en absence
|
|
-- ------------------------------------------------------------------------------
|
|
-- Vacances
|
|
if devicechanged['Detecteur Salon'] and (otherdevices['Vacances'] == 'On' or otherdevices['Presence'] == 'Off') then
|
|
debug("Detection en absence")
|
|
commandArray['SendNotification']='Mode absence#Une presence a ete detectee pres de la tele.#0'
|
|
end
|
|
-- Vacances
|
|
if devicechanged['Detecteur Bureau'] and (otherdevices['Vacances'] == 'On' or otherdevices['Presence'] == 'Off') then
|
|
debug("Detection en absence")
|
|
commandArray['SendNotification']='Mode absence#Une presence a ete detectee dans le bureau.#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
|
|
|
|
-- Quelqu'un est reveillé on ouvre les volets
|
|
if false and devicechanged['Detection_Tennis'] then
|
|
value = tonumber(otherdevices['Detection_Tennis'])
|
|
print("nombre de Detection_Tennis="..tostring(value).." jour="..jour)
|
|
|
|
|
|
heure_debut = 21
|
|
heure_fin = 8
|
|
if jour == 1 then
|
|
heure_debut = 8
|
|
end
|
|
if jour == 2 then
|
|
heure_debut = 21
|
|
end
|
|
-- Jour 3 = Mercredi
|
|
if jour == 3 then
|
|
heure_debut = 23
|
|
end
|
|
if jour == 4 then
|
|
heure_debut = 20
|
|
end
|
|
if jour == 5 then
|
|
heure_debut = 20
|
|
end
|
|
if jour == 6 then
|
|
heure_debut = 19
|
|
end
|
|
if jour == 7 then
|
|
heure_debut = 20
|
|
end
|
|
|
|
|
|
if (((heures >= heure_debut) or (heures <= 8)) and value > 0)
|
|
then
|
|
commandArray['SendNotification']='Detection présence au tennis club après 23h#Une presence a ete detectee dans le bureau http://souti56.ddns.net:8081/.#0'
|
|
end
|
|
|
|
end
|
|
|
|
return commandArray
|