Re: [LUA] Script pour connaitre la couleur du jour pour Tempo d'EDF et script pour la couleur Tempo du lendemain
Publié : 15 mars 2023, 11:25
Visiblement, c'est bien autour de 11h. Ce matin au vu de mes logs cela a été fait entre 11h00 et 11h10:Keros a écrit : 13 mars 2023, 21:51 Il me semble que la mise à jour de l'info du lendemain se fait à 13h. Je fais tourner mon script à 13h05 : aucune erreur pour récupérer l'info.
Code : Tout sélectionner
2023-03-15 11:00:00.832 Status: LUA: TEMPO : Wednesday:BLEU - Thursday:NON_DEFINI
2023-03-15 11:10:00.862 Status: LUA: TEMPO : Wednesday:BLEU - Thursday:BLEU
2023-03-15 11:10:00.862 Status: LUA: TEMPO : Updated !
J'essaie donc désormais sur une plage de 3h entre 11h et 14h, toutes les 10mn, tant que la seconde chaîne n'indique pas encore la couleur du lendemain. Cela assure en même temps d'avoir l'info même si le site EDF a des vapeurs temporaires.
Cela donne désormais chez moi:
Code : Tout sélectionner
-- Script to get tempo coulours for current + next day and feed a dummy text device
-- that must be created from Domoticz interface.
--
-- User editable settings (tempoIdx/Name = virtual text switch IDX/Name),
-- updates check time range must not cross midnight and be ordered (hCheck1 < hCheck2).
jsonLibPath = '/home/pi/domoticz/scripts/lua/JSON.lua' -- UPDATE USER NAME IN PATH !!!
hCheck1 = 11 -- Begin hour for updates check (should be done ~11h00)
hCheck2 = 14 -- End hour for updates check
tempoIdx = 707
tempoName = 'Tempo'
--
-- Internal fct :
-- Get current script exec time & compute last 'device' or 'uservariable' update time.
--
local function timeLastUpdate(devOrVar, isUserVar)
t1 = os.time()
if (isUserVar == true) then
sT0 = uservariables_lastupdate[devOrVar]
else
sT0 = otherdevices_lastupdate[devOrVar]
end
-- Returns a date time like 2016-12-02 15:30:10
-- => Format as os.time & compute diff :
year = string.sub(sT0, 1, 4)
month = string.sub(sT0, 6, 7)
day = string.sub(sT0, 9, 10)
hour = string.sub(sT0, 12, 13)
minutes = string.sub(sT0, 15, 16)
seconds = string.sub(sT0, 18, 19)
t0 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
tDiff = os.difftime(t1, t0)
return(tDiff)
end
-- MAIN
commandArray = {}
time = os.date("*t")
-- Exec every 10mn in hereupper hours range until next day status is defined,
-- retrying while last update > range to handle tempory fails (EDF site unreachable...).
if ((time.min % 10 == 0) and (time.hour >= hCheck1) and (time.hour < hCheck2) and (timeLastUpdate(tempoName, false) > ((hCheck2 - hCheck1)*3600))) then
jsonLib = assert(loadfile(jsonLibPath))
json = (jsonLib)()
today = tostring(os.date("%Y-%m-%d"))
config = assert(io.popen('curl --retry 1 --connect-timeout 2 -m 4 \"https://particulier.edf.fr/services/rest/referentiel/searchTempoStore?dateRelevant='..today..'\"'))
tempo = config:read('*all')
-- Returned JSON format : {"couleurJourJ":"TEMPO_ROUGE","couleurJourJ1":"TEMPO_ROUGE"}
config:close()
jsonTempo = json:decode(tempo)
--print(jsonTempo.couleurJourJ)
--print(jsonTempo.couleurJourJ1)
tempoJ = string.gsub(jsonTempo.couleurJourJ, "TEMPO_", "")
tempoJ1 = string.gsub(jsonTempo.couleurJourJ1, "TEMPO_", "")
dateDay = tostring(os.date("%A"))
dateNextDay = tostring(os.date('%A', (os.time()+ 86400)))
tempoText = dateDay..":"..tempoJ.." - "..dateNextDay..":"..tempoJ1
print("TEMPO : "..tempoText)
-- Only update when next day "color" is defined.
if (tempoJ1 ~= "NON_DEFINI") then
commandArray['UpdateDevice'] = tempoIdx.."|0|"..tempoText
print("TEMPO : Updated !")
end
end
return commandArray