———————————————————————————————————-
— Script : script_device_time_blinds_openclosed.lua

— Objectif : Update time Open Closed ouverture fermeture des volets
—            Permet d’ <<<< AFFICHER >>>> l’heure d’ouverture et de fermeture des volets si le DEVICE « Etat_Presence » change

— Auteur : Raphael
— Date : 19/03/2017
— Révision 2.0: Ajout de variables
— Version : 2.0
———————————————————————————————————-
— Script functions
———————————————————————————————————-
local function Mn_To_Hour(Heure_en_mn) — Conversion Mn en Heure HH:mn
    local mn=math.floor(Heure_en_mn%60)         — math.floor(x) pour retirer les décimals
    local hh=math.floor((Heure_en_mn-mn)/60)    — math.floor(x) pour retirer les décimals
    if mn<10 then mn= »0″..mn end    
    if hh<10 then hh= »0″..hh end
    return (hh.. »: »..mn)                       
end

local function Hour_To_Mn(Heure_str) — Conversion Heure en Mn
    _, _, hh, mn = string.find(Heure_str, « (%d+):(%d+) »)
    return hh*60+mn
end
———————————————————————————————————-
— Script parameters
———————————————————————————————————-
Debug = « YES »                    — Turn debugging on (« YES ») or off (« NO »)

— Les variables de seuil
local Offset_couche_soleil =5
local Heure_LEVER_soleil = timeofday[‘SunriseInMinutes’]
local Heure_COUCHER_soleil = timeofday[‘SunsetInMinutes’]
local Jour_de_semaine=tonumber(os.date(‘%w’)) — [0-6 = Sunday-Saturday]
———————————————————————————————————-
— CommandArray
———————————————————————————————————-
commandArray = {}
    if (devicechanged[‘Etat_Presence’])then — Pour affichage
        local Seuil_Heure_Open_Mini_Present_RDC=Hour_To_Mn(uservariables[‘Seuil_Heure_Open_Mini_Pres_RDC’])     — « 06:50″=410 Present RDC      « 05:50=350
        local Seuil_Heure_Closed_Maxi_Present_RDC=Hour_To_Mn(uservariables[‘Seuil_Heure_Closed_Maxi_Pres_RDC’]) — « 21:00 » Present RDC
        local Seuil_Heure_Open_Mini_Absent=Hour_To_Mn(uservariables[‘Seuil_Heure_Open_Mini_Abs’])               — « 07:45″=465 Absent ou week end RDC & SDB
        local Seuil_Heure_Closed_Maxi_Absent=Hour_To_Mn(uservariables[‘Seuil_Heure_Closed_Maxi_Abs’])           — « 20:45″=1245  Absent ou week end RDC & SDB
        local Time_Ouverture= »00:00″
        local Time_Fermeture= »00:00″       

        if(otherdevices[‘Etat_Presence’]== »PRESENT » or otherdevices[‘Etat_Presence’]== »PRES ETAGE OPEN HS »)and Jour_de_semaine>=1 and Jour_de_semaine<=5 then
            if Heure_LEVER_soleil>Seuil_Heure_Open_Mini_Present_RDC then
                Time_Ouverture=Mn_To_Hour(Heure_LEVER_soleil)
            else Time_Ouverture=Mn_To_Hour(Seuil_Heure_Open_Mini_Present_RDC)
            end
            if Heure_COUCHER_soleil+Offset_couche_soleil<Seuil_Heure_Closed_Maxi_Present_RDC then
                Time_Fermeture=Mn_To_Hour(Heure_COUCHER_soleil+Offset_couche_soleil)
            else Time_Fermeture=Mn_To_Hour(Seuil_Heure_Closed_Maxi_Present_RDC)
            end
        elseif otherdevices[‘Etat_Presence’]~= »Pilotage OFF » then
            if Heure_LEVER_soleil>Seuil_Heure_Open_Mini_Absent then
                Time_Ouverture=Mn_To_Hour(Heure_LEVER_soleil)
            else Time_Ouverture=Mn_To_Hour(Seuil_Heure_Open_Mini_Absent)
            end

            if Heure_COUCHER_soleil+Offset_couche_soleil<Seuil_Heure_Closed_Maxi_Absent then
                Time_Fermeture=Mn_To_Hour(Heure_COUCHER_soleil+Offset_couche_soleil)
            else Time_Fermeture=Mn_To_Hour(Seuil_Heure_Closed_Maxi_Absent)
            end
        else
            Time_Ouverture= »00:00″
            Time_Fermeture= »00:00″
        end

        commandArray[‘Variable:Info_Ouverture_mini_volet’]=Time_Ouverture
        commandArray[‘Variable:Info_Fermeture_maxi_volet’]=Time_Fermeture
        commandArray[1] = { [‘UpdateDevice’] = 18 .. ‘|0|’ .. Time_Ouverture} — Pour afficher Heure ouverture volet
        commandArray[2] = { [‘UpdateDevice’] = 19 .. ‘|0|’ .. Time_Fermeture} — Pour afficher Heure fermeture volet

        if Debug== »YES » then —  Pour affichage en LOG
            print(« <font color=’#fb8a21′> ».. otherdevices[‘Etat_Presence’].. »</font> »)
            print (« <font color=’#fb8a21′>Heure ouverture volets: « ..Time_Ouverture.. »</font> »)
            print (« <font color=’#fb8a21′>Heure fermeture volets: « ..Time_Fermeture.. »</font> »)
        end
    end

return commandArray
————————————————–    Fin    ———————————————
——————————————————————————————————–