Voyant certains galérer avec la récupération des couleurs des jours TEMPO, je me suis penché sur l'API RTE.
Déjà en fonction avec EcoWatt, il faut s'inscrire sur le site, créer une application, s'abonner à l'API et récupérer une clé.
Voici le script dzVents:
Code : Tout sélectionner
local scriptName = 'tempo'
local scriptVersion = '1.0'
--[[
- Créez un compte sur le site de RTE (https://data.rte-france.com/web/guest)
- Allez sur l'API Tempo Like Supply Contract (https://data.rte-france.com/catalog/-/api/consumption/Tempo-Like-Supply-Contract/v1.1)
- Cliquez sur "Abonnez-vous à l'API", créez une nouvelle application
- Récuperez votre clé en cliquant sur "Copier en base 64"
]]
-- Dummy à créer :
local TempoJ = "Tempo" -- Text device J
local TempoJ1 = "Tempo Demain" -- Text device J+1
local cleAPI = "VW5lIGJpw6hyZSBnYWduw6llIHBvdXIgbGUgcHJlbWllciBxdWkgdHJvdXZlIMOnYQ=="
return {
--active = false,
active = true,
logging = {
level = domoticz.LOG_DEBUG, -- Uncomment to override the dzVents global logging setting
marker = scriptName..' '..scriptVersion
},
on = {
timer = {'at 01:40'},
--timer = {'every 1 minutes'},
httpResponses = {
scriptName,
scriptName..'at',
},
},
data = {
--access_token = {}
access_token = { history = true, maxItems = 1, maxMinutes = 110 }
},
execute = function(domoticz, item)
if item.isTimer then
if domoticz.data.access_token.size == 0 then
--or domoticz.data.access_token.get(1).time.secondsAgo > 6000 then
local url = "https://digital.iservices.rte-france.com/token/oauth/"
domoticz.log('Requesting data from RTE', domoticz.LOG_DEBUG)
domoticz.openURL({
url = url,
method = 'POST',
headers = { ['Content-Type'] = 'application/x-www-form-urlencoded',
['Authorization'] = 'Basic '..cleAPI},
callback = scriptName..'at',
})
else
domoticz.log('access_token age: '..domoticz.data.access_token.get(1).time.secondsAgo, domoticz.LOG_DEBUG)
domoticz.log('access_token : '..domoticz.data.access_token.get(1).data, domoticz.LOG_DEBUG)
--local url = "https://digital.iservices.rte-france.com/open_api/ecowatt/v4/sandbox/signals"
local Time = require('Time')
local now = Time() -- current time
local demain = now.addDays(2)
local url = "https://digital.iservices.rte-france.com/open_api/tempo_like_supply_contract/v1/tempo_like_calendars"
url = url .. "?start_date="..domoticz.time.rawDate..
"T00:00:00%2B01:00&end_date="..demain.rawDate.."T00:00:00%2B01:00&fallback_status=true"
domoticz.log('Requesting data from RTE', domoticz.LOG_DEBUG)
domoticz.openURL({
url = url,
method = 'GET',
headers = { ['Content-Type'] = 'application/json;charset=UTF-8',
['Authorization'] = 'Bearer '..domoticz.data.access_token.get(1).data},
callback = scriptName,
})
end
end
if not item.isHTTPResponse then
--domoticz.log("Erreur HTTP",domoticz.LOG_ERROR)
return
end
local response = item
if response.trigger == scriptName..'at' then
local contents = response.json
domoticz.data.access_token.add(contents.access_token)
domoticz.log('access_token : '..domoticz.data.access_token.getLatest().data, domoticz.LOG_DEBUG)
elseif response.trigger == scriptName then
domoticz.log(response.data, domoticz.LOG_DEBUG)
local contents = response.json.tempo_like_calendars
if contents.values[1].start_date:match(domoticz.time.rawDate) then
domoticz.log("Aujourd'hui "..contents.values[1].value)
domoticz.log("Demain "..contents.values[2].value)
TempoJ.updateText(contents.values[1].value)
TempoJ1.updateText(contents.values[2].value)
else
domoticz.log("Aujourd'hui "..contents.values[2].value)
domoticz.log("Demain "..contents.values[1].value)
TempoJ.updateText(contents.values[2].value)
TempoJ1.updateText(contents.values[1].value)
end
elseif (not response.ok) or (response.trigger ~= scriptName) then
domoticz.log('Last http response was not what expected. Trigger: '..response.trigger, domoticz.LOG_ERROR)
domoticz.log(response.data, domoticz.LOG_ERROR)
return
end
end
}
A améliorer avec un switch selector