Re: API ecowatt RTE
Publié : 26 mai 2024, 20:04
Merci pour l'info @Neutrino, effectivement, si ce n'est que ça...
Reprenez le contrôle de votre domotique
https://easydomoticz.com/forum/
2024-05-27 03:49:02.192 Error: Error opening url: https://digital.iservices.rte-france.co ... v5/signals
2024-05-27 05:49:01.158 Error: Error opening url: https://digital.iservices.rte-france.co ... v5/signals
2024-05-27 05:49:01.303 Error: dzVents: Error: (3.1.8) ecowatt 1.0: HTTP/1.1 response: 403 ==>> Forbidden
2024-05-27 05:49:01.306 Error: dzVents: Error: (3.1.8) ecowatt 1.0: An error occurred when calling event handler monecowatt
2024-05-27 05:49:01.306 Error: dzVents: Error: (3.1.8) ecowatt 1.0: /home/pi/domoticz/scripts/dzVents/scripts/monecowatt.lua:81: attempt to index a nil value (field 'json')
Code : Tout sélectionner
ecowatt 1.0: HTTP/1.1 response: 401 ==>> UnauthorizedCode : Tout sélectionner
2025-10-04 07:45:00.207 dzVents: ecowatt 1.0: ------ Start external script: ecowatt.lua:, trigger: "every 15 minutes"
2025-10-04 07:45:00.208 dzVents: Debug: ecowatt 1.0: access_token age: 5399
2025-10-04 07:45:00.208 dzVents: Debug: ecowatt 1.0: access_token : >>>>>>>>>>>>>>TOKEN<<<<<<<<<<<<<<
2025-10-04 07:45:00.208 dzVents: Debug: ecowatt 1.0: Requesting data from RTE
2025-10-04 07:45:00.208 dzVents: Debug: ecowatt 1.0: OpenURL: url = https://digital.iservices.rte-france.com/open_api/ecowatt/v5/signals
2025-10-04 07:45:00.208 dzVents: Debug: ecowatt 1.0: OpenURL: method = GET
2025-10-04 07:45:00.208 dzVents: Debug: ecowatt 1.0: OpenURL: post data = nil
2025-10-04 07:45:00.208 dzVents: Debug: ecowatt 1.0: OpenURL: headers = !#Authorization: Bearer >>>>>>>>>>>>>>TOKEN<<<<<<<<<<<<<<!#Content-Type: application/soap+xml;charset=UTF-8
2025-10-04 07:45:00.208 dzVents: Debug: ecowatt 1.0: OpenURL: callback = ecowatt
2025-10-04 07:45:00.209 dzVents: ecowatt 1.0: ------ Finished ecowatt.lua
Code : Tout sélectionner
2025-10-04 07:45:01.600 dzVents: ecowatt 1.0: ------ Start external script: ecowatt.lua: HTTPResponse: "ecowatt"
2025-10-04 07:45:01.600 Error: dzVents: ecowatt 1.0: HTTP/1.1 response: 401 ==>> Unauthorized
2025-10-04 07:45:01.600 dzVents: Debug: ecowatt 1.0:
2025-10-04 07:45:01.600 Error: dzVents: ecowatt 1.0: An error occurred when calling event handler ecowatt
2025-10-04 07:45:01.600 Error: dzVents: ecowatt 1.0: /home/pi/domoticz/scripts/dzVents/scripts/ecowatt.lua:84: attempt to index a nil value (field 'json')
Code : Tout sélectionner
local scriptName = 'ecowatt'
local scriptVersion = '1.0'
--[[
- Créez un compte sur le site de RTE (https://data.rte-france.com/web/guest)
- Allez sur l'API Ecowatt (https://data.rte-france.com/catalog/-/api/consumption/Ecowatt/v4.0)
- 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 AlertEcoWatt = "EcoWatt" -- Alert device J
local AlertEcoWatt2 = nil -- Alert device J+1
local cleAPI = "je_cache_ma_clé_bien_sur=="
return {
active = function(domoticz)
return domoticz.variables('Internet_available').value == 'True'
end,
logging = {
level = domoticz.LOG_DEBUG, -- Uncomment to override the dzVents global logging setting
marker = scriptName..' '..scriptVersion
},
on = {
--timer = {'at *:49'},
timer = {'every 15 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 url = "https://digital.iservices.rte-france.com/open_api/ecowatt/v5/signals"
domoticz.log('Requesting data from RTE', domoticz.LOG_DEBUG)
domoticz.openURL({
url = url,
method = 'GET',
headers = { ['Content-Type'] = 'application/soap+xml;charset=UTF-8',
['Authorization'] = 'Bearer '..domoticz.data.access_token.get(1).data},
callback = scriptName,
})
end
end
if not item.isHTTPResponse then 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.signals
domoticz.log("jour : "..contents[1].jour )
domoticz.log("dvalue : "..contents[1].dvalue.." message : "..contents[1].message)
if contents[1].dvalue == 1 then
domoticz.devices(AlertEcoWatt).updateAlertSensor(domoticz.ALERTLEVEL_GREEN, contents[1].message)
elseif contents[1].dvalue == 2 then
domoticz.devices(AlertEcoWatt).updateAlertSensor(domoticz.ALERTLEVEL_ORANGE, contents[1].message)
elseif contents[1].dvalue == 3 then
domoticz.devices(AlertEcoWatt).updateAlertSensor(domoticz.ALERTLEVEL_RED, contents[1].message)
else
domoticz.devices(AlertEcoWatt).updateAlertSensor(domoticz.ALERTLEVEL_GREY, contents[1].message)
end
if AlertEcoWatt2 then
domoticz.log("jour2 : "..contents[2].jour )
domoticz.log("dvalue : "..contents[2].dvalue.." message : "..contents[2].message)
if contents[2].dvalue == 1 then
domoticz.devices(AlertEcoWatt2).updateAlertSensor(domoticz.ALERTLEVEL_GREEN, contents[2].message)
elseif contents[2].dvalue == 2 then
domoticz.devices(AlertEcoWatt2).updateAlertSensor(domoticz.ALERTLEVEL_ORANGE, contents[2].message)
elseif contents[2].dvalue == 3 then
domoticz.devices(AlertEcoWatt2).updateAlertSensor(domoticz.ALERTLEVEL_RED, contents[2].message)
else
domoticz.devices(AlertEcoWatt2).updateAlertSensor(domoticz.ALERTLEVEL_GREY, contents[2].message)
end
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
}
Code : Tout sélectionner
maxMinutes = 30J'ai l'impression que c'est une bonne pioche, je n'ai plus eu l'erreur depuis la modif du script.Neutrino a écrit : 13 oct. 2025, 13:19 J'ai la même chose en faite.![]()
C'est le token qui semble expirer plus vite qu'avant.
J'ai modifiéau lieu de 110.Code : Tout sélectionner
maxMinutes = 30
A voir.