-- School Holiday Status Request from Domogeek API
-- http://api.domogeek.fr/static/doc/index.html#api-Domogeek-GetSchoolHoliday
-- Prerequis: 3 switch On/Off: "Zone A", "Zone B", "Zone C"

--curl  http://domogeek.entropialux.com/sun/brest/all/now
--{"dayduration": "9:51", "sunset": "18:28", "zenith": "13:32", "sunrise": "8:37"}

require "scripts/lua/functions"

--recupere les minutes
time=os.time()
minutes=tonumber(os.date('%M',time))
heures=tonumber(os.date('%H',time))

commandArray = {}
time = os.date("*t")

-- Trigger at 0:03 every day
if (time.min == 3 and (time.hour == 0 or time.hour == 8)) then

  -- retourne l'heure du lever de soleil ex: "06:41"
  leverSoleil = string.sub(os.date("!%X",60*timeofday['SunriseInMinutes']), 1, 5)

  -- retourne l'heure du coucher de soleil ex: "22:15"
  coucherSoleil = string.sub(os.date("!%X",60*timeofday['SunsetInMinutes']), 1, 5)

  print("Lever/Coucher "..leverSoleil..'-'..coucherSoleil)
  
  commandArray['Variable:Couche']=coucherSoleil
  commandArray['Variable:Lever']=leverSoleil

  --updateSunset("redon")
end

return commandArray
