Code : Tout sélectionner
return {
on = {
timer = {"at 10:45"}
},
execute = function(domoticz, timer)
-- import des fontions pour lire le JSON
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
url = "https://www.api-couleur-tempo.fr/api/joursTempo?periode=2024-2025"
command = "curl -A 'Wget/1.20.3 (linux-gnu)' " .. '"' .. url .. '"'
f = assert(io.popen(command, "r"))
blocjson = f:read("*a")
f:close()
jsonTable = json:decode(blocjson)
reste_bleu = 300
reste_blanc = 43
reste_rouge = 22
for i, t in pairs(jsonTable) do
if type(t) == "table" then
for k, v in pairs(t) do
if k == "codeJour" then
if v == 1 then
reste_bleu = reste_bleu - 1
elseif v == 2 then
reste_blanc = reste_blanc - 1
elseif v == 3 then
reste_rouge = reste_rouge - 1
end -- if v
end -- if k
end -- for
end -- if type(t)
end
domoticz.log("Reste " .. tostring(reste_bleu) .. " jours BLEU", domoticz.LOG_INFO)
domoticz.log("Reste " .. tostring(reste_blanc) .. " jours BLANC", domoticz.LOG_INFO)
domoticz.log("Reste " .. tostring(reste_rouge) .. " jours ROUGE", domoticz.LOG_INFO)
end -- execute function
}