API ecowatt RTE

Posez ici vos questions d'utilisation, de configuration de DomoticZ, de bugs, de conseils sur le logiciel lui même dans son utilisation et son paramétrage.
Des forums spécifiques sont ouverts ci-dessous pour regrouper les différents sujets.
Martial
Messages : 201
Inscription : 03 mars 2017, 18:58

Re: API ecowatt RTE

Message par Martial »

Merci pour l'info @Neutrino, effectivement, si ce n'est que ça...
denis_brasseur
Messages : 898
Inscription : 24 déc. 2018, 17:05
Localisation : (26)

Re: API ecowatt RTE

Message par denis_brasseur »

Messages d'erreur chez moi en remplaçant v4 par v5.
Mon script s'exécute route les heures, et message d'erreur 1 appel sur 2.
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')
Pi3 + DD PiDrive - RFXtrx433 - AEON Labs ZW090
Neutrino
Messages : 2662
Inscription : 10 juil. 2015, 15:42
Localisation : Les Herbiers(85)

Re: API ecowatt RTE

Message par Neutrino »

Il faut aussi s'abonner à l'API v5 sur le site de rte-france.
Ma maison à plein d'IP ! :mrgreen:
SAV Bonjour. Vous avez vidé le cache ?
denis_brasseur
Messages : 898
Inscription : 24 déc. 2018, 17:05
Localisation : (26)

Re: API ecowatt RTE

Message par denis_brasseur »

Merci Neutrino, c'est mieux après abonnement !
Pi3 + DD PiDrive - RFXtrx433 - AEON Labs ZW090
Chrominator
Messages : 1042
Inscription : 19 déc. 2015, 07:29
Localisation : France

Re: API ecowatt RTE

Message par Chrominator »

Je passais voir s'il y avait du nouveau ; le script plante depuis longtemps,

Code : Tout sélectionner

ecowatt 1.0: HTTP/1.1 response: 401 ==>> Unauthorized
Je suis abonné à la V5, je ne parviens pas à comprendre ce qui ne va pas.

Code : 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')
Le script est assez fidèle à celui d'origine, je n'ai changé que les conditions d'exécution.

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
}
Un bon frein vaut mieux que deux sparadraps.

Ubuntu 24.04.3 LTS - Domoticz 2025.1 (build 16782)
Pentium G3220T 2.6GHz - 4Go DDR3
RFXtrx433 USB Ver Pro1/1043
Z-Stick GEN5 Version: 1.6-1136-g07ea22bb
Rtl433 RTL-SDR receiver
RFLink Gateway
Zigbee SLZB-06
Neutrino
Messages : 2662
Inscription : 10 juil. 2015, 15:42
Localisation : Les Herbiers(85)

Re: API ecowatt RTE

Message par Neutrino »

Recrée une clé API peut-être ?
Ma maison à plein d'IP ! :mrgreen:
SAV Bonjour. Vous avez vidé le cache ?
Chrominator
Messages : 1042
Inscription : 19 déc. 2015, 07:29
Localisation : France

Re: API ecowatt RTE

Message par Chrominator »

Merci d'avoir pris le temps de regarder.

En réalité c'est aléatoire, j'ai souvent ce message "HTTP/1.1 response: 401 ==>> Unauthorized", mais aussi quelques succès dans l'exécution de ce script.
D'une exécution toutes les 15 mn je suis passé à une fois par heure, mais ça ne change rien.
C'est peut-être côté serveur qu'il y a un souci du coup.
Un bon frein vaut mieux que deux sparadraps.

Ubuntu 24.04.3 LTS - Domoticz 2025.1 (build 16782)
Pentium G3220T 2.6GHz - 4Go DDR3
RFXtrx433 USB Ver Pro1/1043
Z-Stick GEN5 Version: 1.6-1136-g07ea22bb
Rtl433 RTL-SDR receiver
RFLink Gateway
Zigbee SLZB-06
Neutrino
Messages : 2662
Inscription : 10 juil. 2015, 15:42
Localisation : Les Herbiers(85)

Re: API ecowatt RTE

Message par Neutrino »

J'ai la même chose en faite. :mrgreen:
C'est le token qui semble expirer plus vite qu'avant.
J'ai modifié

Code : Tout sélectionner

maxMinutes = 30
au lieu de 110.
A voir.
Ma maison à plein d'IP ! :mrgreen:
SAV Bonjour. Vous avez vidé le cache ?
Chrominator
Messages : 1042
Inscription : 19 déc. 2015, 07:29
Localisation : France

Re: API ecowatt RTE

Message par Chrominator »

J'ai adapté aussi mon script, merci.
A suivre donc.
Un bon frein vaut mieux que deux sparadraps.

Ubuntu 24.04.3 LTS - Domoticz 2025.1 (build 16782)
Pentium G3220T 2.6GHz - 4Go DDR3
RFXtrx433 USB Ver Pro1/1043
Z-Stick GEN5 Version: 1.6-1136-g07ea22bb
Rtl433 RTL-SDR receiver
RFLink Gateway
Zigbee SLZB-06
Chrominator
Messages : 1042
Inscription : 19 déc. 2015, 07:29
Localisation : France

Re: API ecowatt RTE

Message par Chrominator »

Neutrino a écrit : 13 oct. 2025, 13:19 J'ai la même chose en faite. :mrgreen:
C'est le token qui semble expirer plus vite qu'avant.
J'ai modifié

Code : Tout sélectionner

maxMinutes = 30
au lieu de 110.
A voir.
J'ai l'impression que c'est une bonne pioche, je n'ai plus eu l'erreur depuis la modif du script.
Encore merci ! :)
Un bon frein vaut mieux que deux sparadraps.

Ubuntu 24.04.3 LTS - Domoticz 2025.1 (build 16782)
Pentium G3220T 2.6GHz - 4Go DDR3
RFXtrx433 USB Ver Pro1/1043
Z-Stick GEN5 Version: 1.6-1136-g07ea22bb
Rtl433 RTL-SDR receiver
RFLink Gateway
Zigbee SLZB-06
Répondre