j'ai mis à jour mon script pour ajouter un dummy sensor pour le prix associé au code couleur et HC/HP pour que Domoticz puisse calculer le cout à la journée correctement. Il faut donc choisir le capteur dans les paramètres aussi ! (meter/counter => Electricity Price device )
Code : Tout sélectionner
commandArray = {}
alert = {}
tarif_HP = {}
tarif_HC = {}
code_couleur = {}
local debug = false --quand true: active mise à jour toutes les minutes
local heure_execution = 8
local minute_execution = 01
local minute_execution2 = 59
local id_device_text = 816 --device id ou est stocké l'info des jours Tempo
local nom_device_text = "Tempo" --nom device ou est stocké l'info des jours Tempo
local Text_sensor_update = ""
alert[1] = false --alerte jour bleu
alert[2] = true --alerte jour blanc
alert[3] = true --alerte jour rouge
local id_tarif_tempo = 885 --device id capteur dummy recevant le prix du kwh "Tarif Tempo" - Mette nil pour désactiver
tarif_HP[1] = 0.1609 --tarif HP bleu
tarif_HP[2] = 0.1894 --tarif HP blanc
tarif_HP[3] = 0.7562 --tarif HP rouge
tarif_HC[1] = 0.1296 --tarif HC bleu
tarif_HC[2] = 0.1486 --tarif HC blanc
tarif_HC[3] = 0.1568 --tarif HC rouge
code_couleur[0] = "NON_DEFINI" -- 0, 1, 2, 3 valeur retournée par l'API
code_couleur[1] = "BLEU"
code_couleur[2] ="BLANC"
code_couleur[3] = "ROUGE"
daysFr = {Monday = "Lundi", Tuesday = "Mardi", Wednesday = "Mercredi", Thursday = "Jeudi", Friday = "Vendredi", Saturday = "Samedi", Sunday = "Dimanche"}
if debug then print ('Valeur actuelle: '..otherdevices_svalues[nom_device_text]) end
local t1 = os.time()
local s = otherdevices_lastupdate[nom_device_text]
local year = string.sub(s, 1, 4)
local month = string.sub(s, 6, 7)
local day = string.sub(s, 9, 10)
local hour = string.sub(s, 12, 13)
local minutes = string.sub(s, 15, 16)
local seconds = string.sub(s, 18, 19)
local t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
local difference = (os.difftime (t1, t2))
if debug then print(difference) end
time = os.date("*t") -- put the time/date table in variable time
function recup_codejour_tempo(jour)
json = (loadfile "scripts/lua/JSON.lua")()
local config=assert(io.popen('curl -X \'GET\' \'https://www.api-couleur-tempo.fr/api/jourTempo/'..jour..'\' -H \'accept: application/json\''))
local tempo = config:read('*all')
config:close()
if debug then print (tempo) end
local jsonTempo = json:decode(tempo)
if debug then print (jsonTempo.codeJour) end
return jsonTempo.codeJour
end
--update custom sensor tarif tempo
if ((((time.hour==6 or time.hour==22) and time.min==01) or debug == true) and id_tarif_tempo ~= nil) then
couleurJourJ = recup_codejour_tempo("today")
if (time.hour>5 and time.hour<22) then commandArray['UpdateDevice'] = id_tarif_tempo .. '|0|' .. tarif_HP[couleurJourJ]
else commandArray['UpdateDevice'] = id_tarif_tempo .. '|0|' .. tarif_HC[couleurJourJ] end
end
--update custom sensor couleur jour tempo
if ((time.hour==heure_execution and (time.min==minute_execution or time.min==minute_execution2)) or (difference > 88200 and time.min==30) or (string.find(otherdevices_svalues[nom_device_text], "NON_DEFINI") and time.min==30) or debug == true) then
if debug then print ("Récupération jour Tempo") end
couleurJourJ = recup_codejour_tempo("today")
couleurJourJ1 = recup_codejour_tempo("tomorrow")
DateJour=tostring(os.date("%A"))
DateJourPlus1 = tostring(os.date('%A', (os.time()+ 60*60*24)))
Text_sensor_update = daysFr[DateJour]..":"..code_couleur[couleurJourJ].." - "..daysFr[DateJourPlus1]..":"..code_couleur[couleurJourJ1]
if debug then print (Text_sensor_update) end
if(otherdevices_svalues[nom_device_text] ~= Text_sensor_update) then
commandArray['UpdateDevice'] = id_device_text.."|0|"..Text_sensor_update
if alert[couleurJourJ1] == true then
commandArray['SendNotification']='Tempo: Demain '..code_couleur[couleurJourJ1]..'#Demain '..daysFr[DateJourPlus1]..' (à partir de 6h du matin) est annoncé comme un jour tempo '..code_couleur[couleurJourJ1]..' !'
end
end
end
return commandArray