Testez moi ça, normalement si je ma pas gouré ça doit marcher. local Ville = "Lille" local dayofchange = 31 -- Jour du changement d'Année scolaire local monthofchange = 8 -- Mois du changement d'Année scolaire local Annee = "" local data = fibaro:getGlobal("VacancesScolaire") local i = 1 local now = os.time() local holiday = false local holidayd1 = false local vacance = {} -- -------------------------------------------------------------------------------------------------------------- -- Determine l'Année Scolaire par rapport aux paramètres monthofchange & dayofchange -- -------------------------------------------------------------------------------------------------------------- local dateofchange = os.time({day=dayofchange,month=monthofchange,year=os.date("%Y"),hour=0,min=0,sec=0}) if now > dateofchange then Annee = os.date("%Y").."-"..(os.date("%Y") + 1) else Annee = (os.date("%Y") -1).."-"..os.date("%Y") end -- -------------------------------------------------------------------------------------------------------------- -- Calcule le nombre de jours entre 2 dates -- -------------------------------------------------------------------------------------------------------------- function delai(dated, dateparam) diff = os.difftime(dated, dateparam) return math.floor(diff / (60*60*24)) end -- -------------------------------------------------------------------------------------------------------------- -- Transforme une date en string en date exploitable -- -------------------------------------------------------------------------------------------------------------- function getDateFormat(sdate) year,month,day = sdate:match("(%d+)-(%d+)-(%d+)") return os.time({day=day,month=month,year=year,hour=0,min=0,sec=0}) end local status, jsonTable = pcall(function() return json.decode(data) end) for j = 1, #jsonTable do if jsonTable[j].fields.location == Ville and jsonTable[j].fields.annee_scolaire == Annee then local Description = jsonTable[j].fields.description local Annee_Scolaire = jsonTable[j].fields.annee_scolaire local Start_date = tostring(jsonTable[j].fields.start_date) local End_date = tostring(jsonTable[j].fields.end_date) Zone = jsonTable[j].fields.zones --local Ville = jsonTable[j].fields.location if (now > getDateFormat(Start_date) and now < getDateFormat(End_date)) then holiday = true elseif ( getDateFormat(Start_date) > now and not holiday) then if nextholiday ~= nil then if getDateFormat(Start_date) < nextholiday then nextholiday = getDateFormat(Start_date) end else nextholiday = getDateFormat(Start_date) end end if (now+24*60*60 > getDateFormat(Start_date) and now+24*60*60 < getDateFormat(End_date)) then holidayd1 = true end table.insert(vacance, getDateFormat(Start_date).." - "..getDateFormat(End_date).." | "..Description) end end fibaro:call(fibaro:getSelfId(), "setProperty", "ui.ville.value", Ville) fibaro:call(fibaro:getSelfId(), "setProperty", "ui.zone.value", Zone) table.sort(vacance) for k, v in pairs(vacance) do local date1 = string.match(v, "(%d+)%s"); local date2 = string.match(v, "-%s(%d+)%s"); local libelle = string.match(v, "|%s(.+)"); fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label"..k..".value", os.date("%d.%m.%Y", date1) .. " - " .. os.date("%d.%m.%Y", date2) .. " | " .. libelle) end if holiday then fibaro:call(fibaro:getSelfId(), "setProperty", "ui.today.value", "Oui") else fibaro:call(fibaro:getSelfId(), "setProperty", "ui.today.value", "Non") fibaro:call(fibaro:getSelfId(), "setProperty", "ui.status.value", "Dans ".. delai(nextholiday, now) .. " Jours") end if holidayd1 then fibaro:call(fibaro:getSelfId(), "setProperty", "ui.tomorrow.value", "Oui") else fibaro:call(fibaro:getSelfId(), "setProperty", "ui.tomorrow.value", "Non") end