Hello
Due to the recent change in the electricity tariff in Spain, I have returned to this script to modify it.
Now the indicator is 1001 for the PVPC T 2.0TD.
I have removed the part that calculates the time as it is unnecessary.
I have simplified the url by removing the time range as it is not required.
The question is that now when making the records appear things that I do not understand.
1. The response_body log now contains two strings, the first one is cut into dat and the bottom one starts with etime and ends with three dots, with no more data.
2. In the data log, I do not see any data, such as the long name, the short one. It is also cut in field 23, showing other ...
Doing a test with https://reqbin.com/curl, it works perfectly, returning a JSON with all the records from 00 to 23, of the present day. Of all the Spanish territory.
The code is
The script is:
Any ideas?
Greetings
Due to the recent change in the electricity tariff in Spain, I have returned to this script to modify it.
Now the indicator is 1001 for the PVPC T 2.0TD.
I have removed the part that calculates the time as it is unnecessary.
I have simplified the url by removing the time range as it is not required.
The question is that now when making the records appear things that I do not understand.
1. The response_body log now contains two strings, the first one is cut into dat and the bottom one starts with etime and ends with three dots, with no more data.
Code:
table:
[1]
* string: {"indicator":{"name":"Término de facturación de energía activa del PVPC 2.0TD","short_name":"PVPC T. 2.0TD","id":1001,"composited":false,"step_type":"linear","disaggregated":true,"magnitud":[{"name":"Precio","id":23}],"tiempo":[{"name":"Hora","id":4}],"geos":[{"geo_id":8741,"geo_name":"Península"},{"geo_id":8742,"geo_name":"Canarias"},{"geo_id":8743,"geo_name":"Baleares"},{"geo_id":8744,"geo_name":"Ceuta"},{"geo_id":8745,"geo_name":"Melilla"}],"values_updated_at":"2021-06-15T20:16:44.000+02:00","values":[{"value":125.65,"datetime":"2021-06-16T00:00:00.000+02:00","datetime_utc":"2021-06-15T22:00:00Z","tz_time":"2021-06-15T22:00:00.000Z","geo_id":8741,"geo_name":"Península"},{"value":125.65,"datetime":"2021-06-16T00:00:00.000+02:00","datetime_utc":"2021-06-15T22:00:00Z","tz_time":"2021-06-15T22:00:00.000Z","geo_id":8742,"geo_name":"Canarias"},{"value":125.65,"datetime":"2021-06-16T00:00:00.000+02:00","datetime_utc":"2021-06-15T22:00:00Z","tz_time":"2021-06-15T22:00:00.000Z","geo_id":8743,"geo_name":"Baleares"},{"value":125.65,"datetime":"2021-06-16T00:00:00.000+02:00","datetime_utc":"2021-06-15T22:00:00Z","tz_time":"2021-06-15T22:00:00.000Z","geo_id":8744,"geo_name":"Ceuta"},{"value":125.65,"datetime":"2021-06-16T00:00:00.000+02:00","datetime_utc":"2021-06-15T22:00:00Z","tz_time":"2021-06-15T22:00:00.000Z","geo_id":8745,"geo_name":"Melilla"},{"value":123.54,"datetime":"2021-06-16T01:00:00.000+02:00","datetime_utc":"2021-06-15T23:00:00Z","tz_time":"2021-06-15T23:00:00.000Z","geo_id":8741,"geo_name":"Península"},{"value":123.54,"datetime":"2021-06-16T01:00:00.000+02:00","datetime_utc":"2021-06-15T23:00:00Z","tz_time":"2021-06-15T23:00:00.000Z","geo_id":8742,"geo_name":"Canarias"},{"value":123.54,"datetime":"2021-06-16T01:00:00.000+02:00","datetime_utc":"2021-06-15T23:00:00Z","tz_time":"2021-06-15T23:00:00.000Z","geo_id":8743,"geo_name":"Baleares"},{"value":123.54,"datetime":"2021-06-16T01:00:00.000+02:00","datetime_utc":"2021-06-15T23:00:00Z","tz_time":"2021-06-15T23:00:00.000Z","geo_id":8744,"geo_name":"Ceuta"},{"value":123.54,"datetime":"2021-06-16T01:00:00.000+02:00","datetime_utc":"2021-06-15T23:00:00Z","tz_time":"2021-06-15T23:00:00.000Z","geo_id":8745,"geo_name":"Melilla"},{"value":122.17,"datetime":"2021-06-16T02:00:00.000+02:00","datetime_utc":"2021-06-16T00:00:00Z","tz_time":"2021-06-16T00:00:00.000Z","geo_id":8741,"geo_name":"Península"},{"value":122.17,"datetime":"2021-06-16T02:00:00.000+02:00","datetime_utc":"2021-06-16T00:00:00Z","tz_time":"2021-06-16T00:00:00.000Z","geo_id":8742,"geo_name":"Canarias"},{"value":122.17,"datetime":"2021-06-16T02:00:00.000+02:00","datetime_utc":"2021-06-16T00:00:00Z","tz_time":"2021-06-16T00:00:00.000Z","geo_id":8743,"geo_name":"Baleares"},{"value":122.17,"datetime":"2021-06-16T02:00:00.000+02:00","datetime_utc":"2021-06-16T00:00:00Z","tz_time":"2021-06-16T00:00:00.000Z","geo_id":8744,"geo_name":"Ceuta"},{"value":122.17,"datetime":"2021-06-16T02:00:00.000+02:00","datetime_utc":"2021-06-16T00:00:00Z","tz_time":"2021-06-16T00:00:00.000Z","geo_id":8745,"geo_name":"Melilla"},{"value":122.53,"datetime":"2021-06-16T03:00:00.000+02:00","datetime_utc":"2021-06-16T01:00:00Z","tz_time":"2021-06-16T01:00:00.000Z","geo_id":8741,"geo_name":"Península"},{"value":122.53,"datetime":"2021-06-16T03:00:00.000+02:00","datetime_utc":"2021-06-16T01:00:00Z","tz_time":"2021-06-16T01:00:00.000Z","geo_id":8742,"geo_name":"Canarias"},{"value":122.53,"datetime":"2021-06-16T03:00:00.000+02:00","datetime_utc":"2021-06-16T01:00:00Z","tz_time":"2021-06-16T01:00:00.000Z","geo_id":8743,"geo_name":"Baleares"},{"value":122.53,"datetime":"2021-06-16T03:00:00.000+02:00","datetime_utc":"2021-06-16T01:00:00Z","tz_time":"2021-06-16T01:00:00.000Z","geo_id":8744,"geo_name":"Ceuta"},{"value":122.53,"datetime":"2021-06-16T03:00:00.000+02:00","datetime_utc":"2021-06-16T01:00:00Z","tz_time":"2021-06-16T01:00:00.000Z","geo_id":8745,"geo_name":"Melilla"},{"value":122.7,"datetime":"2021-06-16T04:00:00.000+02:00","datetime_utc":"2021-06-16T02:00:00Z","tz_time":"2021-06-16T02:00:00.000Z","geo_id":8741,"geo_name":"Península"},{"value":122.7,"datetime":"2021-06-16T04:00:00.000+02:00","datetime_utc":"2021-06-16T02:00:00Z","tz_time":"2021-06-16T02:00:00.000Z","geo_id":8742,"geo_name":"Canarias"},{"value":122.7,"datetime":"2021-06-16T04:00:00.000+02:00","datetime_utc":"2021-06-16T02:00:00Z","tz_time":"2021-06-16T02:00:00.000Z","geo_id":8743,"geo_name":"Baleares"},{"value":122.7,"datetime":"2021-06-16T04:00:00.000+02:00","datetime_utc":"2021-06-16T02:00:00Z","tz_time":"2021-06-16T02:00:00.000Z","geo_id":8744,"geo_name":"Ceuta"},{"value":122.7,"datetime":"2021-06-16T04:00:00.000+02:00","datetime_utc":"2021-06-16T02:00:00Z","tz_time":"2021-06-16T02:00:00.000Z","geo_id":8745,"geo_name":"Melilla"},{"value":121.72,"datetime":"2021-06-16T05:00:00.000+02:00","datetime_utc":"2021-06-16T03:00:00Z","tz_time":"2021-06-16T03:00:00.000Z","geo_id":8741,"geo_name":"Península"},{"value":121.72,"datetime":"2021-06-16T05:00:00.000+02:00","datetime_utc":"2021-06-16T03:00:00Z","tz_time":"2021-06-16T03:00:00.000Z","geo_id":8742,"geo_name":"Canarias"},{"value":121.72,"datetime":"2021-06-16T05:00:00.000+02:00","datetime_utc":"2021-06-16T03:00:00Z","tz_time":"2021-06-16T03:00:00.000Z","geo_id":8743,"geo_name":"Baleares"},{"value":121.72,"datetime":"2021-06-16T05:00:00.000+02:00","datetime_utc":"2021-06-16T03:00:00Z","tz_time":"2021-06-16T03:00:00.000Z","geo_id":8744,"geo_name":"Ceuta"},{"value":121.72,"datetime":"2021-06-16T05:00:00.000+02:00","datetime_utc":"2021-06-16T03:00:00Z","tz_time":"2021-06-16T03:00:00.000Z","geo_id":8745,"geo_name":"Melilla"},{"value":122.72,"datetime":"2021-06-16T06:00:00.000+02:00","datetime_utc":"2021-06-16T04:00:00Z","tz_time":"2021-06-16T04:00:00.000Z","geo_id":8741,"geo_name":"Península"},{"value":122.72,"datetime":"2021-06-16T06:00:00.000+02:00","datetime_utc":"2021-06-16T04:00:00Z","tz_time":"2021-06-16T04:00:00.000Z","geo_id":8742,"geo_name":"Canarias"},{"value":122.72,"datetime":"2021-06-16T06:00:00.000+02:00","datetime_utc":"2021-06-16T04:00:00Z","tz_time":"2021-06-16T04:00:00.000Z","geo_id":8743,"geo_name":"Baleares"},{"value":122.72,"datetime":"2021-06-16T06:00:00.000+02:00","datetime_utc":"2021-06-16T04:00:00Z","tz_time":"2021-06-16T04:00:00.000Z","geo_id":8744,"geo_name":"Ceuta"},{"value":122.72,"datetime":"2021-06-16T06:00:00.000+02:00","datetime_utc":"2021-06-16T04:00:00Z","tz_time":"2021-06-16T04:00:00.000Z","geo_id":8745,"geo_name":"Melilla"},{"value":125.12,"datetime":"2021-06-16T07:00:00.000+02:00","datetime_utc":"2021-06-16T05:00:00Z","tz_time":"2021-06-16T05:00:00.000Z","geo_id":8741,"geo_name":"Península"},{"value":125.12,"datetime":"2021-06-16T07:00:00.000+02:00","datetime_utc":"2021-06-16T05:00:00Z","tz_time":"2021-06-16T05:00:00.000Z","geo_id":8742,"geo_name":"Canarias"},{"value":125.12,"datetime":"2021-06-16T07:00:00.000+02:00","datetime_utc":"2021-06-16T05:00:00Z","tz_time":"2021-06-16T05:00:00.000Z","geo_id":8743,"geo_name":"Baleares"},{"value":125.12,"datetime":"2021-06-16T07:00:00.000+02:00","datetime_utc":"2021-06-16T05:00:00Z","tz_time":"2021-06-16T05:00:00.000Z","geo_id":8744,"geo_name":"Ceuta"},{"value":125.12,"datetime":"2021-06-16T07:00:00.000+02:00","datetime_utc":"2021-06-16T05:00:00Z","tz_time":"2021-06-16T05:00:00.000Z","geo_id":8745,"geo_name":"Melilla"},{"value":161.78,"datetime":"2021-06-16T08:00:00.000+02:00","datetime_utc":"2021-06-16T06:00:00Z","tz_time":"2021-06-16T06:00:00.000Z","geo_id":8741,"geo_name":"Península"},{"value":161.78,"datetime":"2021-06-16T08:00:00.000+02:00","datetime_utc":"2021-06-16T06:00:00Z","tz_time":"2021-06-16T06:00:00.000Z","geo_id":8742,"geo_name":"Canarias"},{"value":161.78,"datetime":"2021-06-16T08:00:00.000+02:00","datetime_utc":"2021-06-16T06:00:00Z","tz_time":"2021-06-16T06:00:00.000Z","geo_id":8743,"geo_name":"Baleares"},{"value":161.78,"dat
[2]
* string: etime":"2021-06-16T08:00:00.000+02:00","datetime_utc":"2021-06-16T06:00:00Z","tz_time":"2021-06-16T06:00:00.000Z","geo_id":8744,"geo_name":"Ceuta"},{"value":161.78,"datetime":"2021-06-16T08:00:00.000+02:00","datetime_utc":"2021-06-16T06:00:00Z","tz_time":"2021-06-16T06:00:00.000Z...
2. In the data log, I do not see any data, such as the long name, the short one. It is also cut in field 23, showing other ...
Code:
PVPC 16.06.2021 18:34:59
* table:
["indicator"]
* table:
["composited"]
* bool: false
["magnitud"]
* table:
[1]
* table:
["name"]
* string: Precio
["id"]
* number: 23
["id"]
* number: 1001
["tiempo"]
* table:
[1]
* table:
["name"]
* string: Hora
["id"]
* number: 4
["step_type"]
* string: linear
["short_name"]
* string: PVPC T. 2.0TD
["values"]
* table:
[1]
* table:
["datetime_utc"]
* string: 2021-06-15T22:00:00Z
["geo_id"]
* number: 8741
["value"]
* number: 125.65
["tz_time"]
* string: 2021-06-15T22:00:00.000Z
["geo_name"]
* string: Península
["datetime"]
* string: 2021-06-16T00:00:00.000+02:00
[2]
* table:
["datetime_utc"]
* string: 2021-06-15T22:00:00Z
["geo_id"]
* number: 8742
["value"]
* number: 125.65
["tz_time"]
* string: 2021-06-15T22:00:00.000Z
["geo_name"]
* string: Canarias
["datetime"]
* string: 2021-06-16T00:00:00.000+02:00
[3]
* table:
["datetime_utc"]
* string: 2021-06-15T22:00:00Z
["geo_id"]
* number: 8743
["value"]
* number: 125.65
["tz_time"]
* string: 2021-06-15T22:00:00.000Z
["geo_name"]
* string: Baleares
["datetime"]
* string: 2021-06-16T00:00:00.000+02:00
[4]
* table:
["datetime_utc"]
* string: 2021-06-15T22:00:00Z
["geo_id"]
* number: 8744
["value"]
* number: 125.65
["tz_time"]
* string: 2021-06-15T22:00:00.000Z
["geo_name"]
* string: Ceuta
["datetime"]
* string: 2021-06-16T00:00:00.000+02:00
[5]
* table:
["datetime_utc"]
* string: 2021-06-15T22:00:00Z
["geo_id"]
* number: 8745
["value"]
* number: 125.65
["tz_time"]
* string: 2021-06-15T22:00:00.000Z
["geo_name"]
* string: Melilla
["datetime"]
* string: 2021-06-16T00:00:00.000+02:00
[6]
* table:
["datetime_utc"]
* string: 2021-06-15T23:00:00Z
["geo_id"]
* number: 8741
["value"]
* number: 123.54
["tz_time"]
* string: 2021-06-15T23:00:00.000Z
["geo_name"]
* string: Península
["datetime"]
* string: 2021-06-16T01:00:00.000+02:00
[7]
* table:
["datetime_utc"]
* string: 2021-06-15T23:00:00Z
["geo_id"]
* number: 8742
["value"]
* number: 123.54
["tz_time"]
* string: 2021-06-15T23:00:00.000Z
["geo_name"]
* string: Canarias
["datetime"]
* string: 2021-06-16T01:00:00.000+02:00
[8]
* table:
["datetime_utc"]
* string: 2021-06-15T23:00:00Z
["geo_id"]
* number: 8743
["value"]
* number: 123.54
["tz_time"]
* string: 2021-06-15T23:00:00.000Z
["geo_name"]
* string: Baleares
["datetime"]
* string: 2021-06-16T01:00:00.000+02:00
[9]
* table:
["datetime_utc"]
* string: 2021-06-15T23:00:00Z
["geo_id"]
* number: 8744
["value"]
* number: 123.54
["tz_time"]
* string: 2021-06-15T23:00:00.000Z
["geo_name"]
* string: Ceuta
["datetime"]
* string: 2021-06-16T01:00:00.000+02:00
[10]
* table:
["datetime_utc"]
* string: 2021-06-15T23:00:00Z
["geo_id"]
* number: 8745
["value"]
* number: 123.54
["tz_time"]
* string: 2021-06-15T23:00:00.000Z
["geo_name"]
* string: Melilla
["datetime"]
* string: 2021-06-16T01:00:00.000+02:00
[11]
* table:
["datetime_utc"]
* string: 2021-06-16T00:00:00Z
["geo_id"]
* number: 8741
["value"]
* number: 122.17
["tz_time"]
* string: 2021-06-16T00:00:00.000Z
["geo_name"]
* string: Península
["datetime"]
* string: 2021-06-16T02:00:00.000+02:00
[12]
* table:
["datetime_utc"]
* string: 2021-06-16T00:00:00Z
["geo_id"]
* number: 8742
["value"]
* number: 122.17
["tz_time"]
* string: 2021-06-16T00:00:00.000Z
["geo_name"]
* string: Canarias
["datetime"]
* string: 2021-06-16T02:00:00.000+02:00
[13]
* table:
["datetime_utc"]
* string: 2021-06-16T00:00:00Z
["geo_id"]
* number: 8743
["value"]
* number: 122.17
["tz_time"]
* string: 2021-06-16T00:00:00.000Z
["geo_name"]
* string: Baleares
["datetime"]
* string: 2021-06-16T02:00:00.000+02:00
[14]
* table:
["datetime_utc"]
* string: 2021-06-16T00:00:00Z
["geo_id"]
* number: 8744
["value"]
* number: 122.17
["tz_time"]
* string: 2021-06-16T00:00:00.000Z
["geo_name"]
* string: Ceuta
["datetime"]
* string: 2021-06-16T02:00:00.000+02:00
[15]
* table:
["datetime_utc"]
* string: 2021-06-16T00:00:00Z
["geo_id"]
* number: 8745
["value"]
* number: 122.17
["tz_time"]
* string: 2021-06-16T00:00:00.000Z
["geo_name"]
* string: Melilla
["datetime"]
* string: 2021-06-16T02:00:00.000+02:00
[16]
* table:
["datetime_utc"]
* string: 2021-06-16T01:00:00Z
["geo_id"]
* number: 8741
["value"]
* number: 122.53
["tz_time"]
* string: 2021-06-16T01:00:00.000Z
["geo_name"]
* string: Península
["datetime"]
* string: 2021-06-16T03:00:00.000+02:00
[17]
* table:
["datetime_utc"]
* string: 2021-06-16T01:00:00Z
["geo_id"]
* number: 8742
["value"]
* number: 122.53
["tz_time"]
* string: 2021-06-16T01:00:00.000Z
["geo_name"]
* string: Canarias
["datetime"]
* string: 2021-06-16T03:00:00.000+02:00
[18]
* table:
["datetime_utc"]
* string: 2021-06-16T01:00:00Z
["geo_id"]
* number: 8743
["value"]
* number: 122.53
["tz_time"]
* string: 2021-06-16T01:00:00.000Z
["geo_name"]
* string: Baleares
["datetime"]
* string: 2021-06-16T03:00:00.000+02:00
[19]
* table:
["datetime_utc"]
* string: 2021-06-16T01:00:00Z
["geo_id"]
* number: 8744
["value"]
* number: 122.53
["tz_time"]
* string: 2021-06-16T01:00:00.000Z
["geo_name"]
* string: Ceuta
["datetime"]
* string: 2021-06-16T03:00:00.000+02:00
[20]
* table:
["datetime_utc"]
* string: 2021-06-16T01:00:00Z
["geo_id"]
* number: 8745
["value"]
* number: 122.53
["tz_time"]
* string: 2021-06-16T01:00:00.000Z
["geo_name"]
* string: Melilla
["datetime"]
* string: 2021-06-16T03:00:00.000+02:00
[21]
* table:
["datetime_utc"]
* string: 2021-06-16T02:00:00Z
["geo_id"]
* number: 8741
["value"]
* number: 122.7
["tz_time"]
* string: 2021-06-16T02:00:00.000Z
["geo_name"]
* string: Península
["datetime"]
* string: 2021-06-16T04:00:00.000+02:00
[22]
* table:
["datetime_utc"]
* string: 2021-06-16T02:00:00Z
["geo_id"]
* number: 8742
["value"]
* number: 122.7
["tz_time"]
* string: 2021-06-16T02:00:00.000Z
["geo_name"]
* string: Canarias
["datetime"]
* string: 2021-06-16T04:00:00.000+02:00
[23]
* table:
["datetime_utc"]
* string: 2021-06-16T02:00:00Z
...
Doing a test with https://reqbin.com/curl, it works perfectly, returning a JSON with all the records from 00 to 23, of the present day. Of all the Spanish territory.
The code is
Code:
curl "https://api.esios.ree.es/indicators/1001" -X GET \
-H "Accept: application/json; application/vnd.esios-api-v1+json" \
-H "Content-Type: application/json" \
-H "Host: api.esios.ree.es" \
-H "Authorization: Token token=\"Token de ESIOS\"" \
-H "Cookie: "\
Code:
-- Incluir las librerías necesarias
https = require('ssl.https')
json = require('json')
ltn12 = require('ltn12')
payload = ''
token ='Token de ESIOS'
Token=('Token token=\34'..token..'\34')
-- Url donde está el PVPC con su correspondiente indicador 1001 PVPC T 2.0TD
url = 'https://api.esios.ree.es/indicators/1001'
-- Petición
response_body = {}
body, code, hdrs, stat = https.request ({
url = url;
method = 'GET';
headers = {
['Accept'] = 'application/json; application/vnd.esios-api-v1+json';
['Content-Type'] = 'application/json';
['Host'] = 'api.esios.ree.es';
['Authorization'] = Token;
['Cookie'] = '';
};
source = ltn12.source.string(payload);
sink = ltn12.sink.table(response_body);
})
log(response_body)
-- Comprobación que la recepción en correcta
if type(response_body) ~= 'table' then -- Si el contenido de la variable es distinto a una tabla entonces
alert('Fallo al cargar la información')
elseif code == 200 then -- Si la llamada devuelve el codigo 200, todo OK
log(code .. ' Datos obtenidos con éxito')
elseif code == 401 then -- Si la llamada devuelve el codigo de error 401 o 404
alert(code .. ' Fallo con la llave de la API') -- Mensajes de error
elseif code == 404 then
alert(code .. ' Fallo datos no encontrados')
return
end
-- Tratamiento de los datos recibidos uniéndolos en una sola cadena y decodificando el Json
response = table.concat(response_body)
data = require('json').decode(response)
log(data)
--Utilizamos los datos de la PVCP obtenidos, se divide entre 1000 para obtener kWh--
--Hora 00
grp.write('32/2/21', data.indicator.values[ 1 ].value/1000)
--Hora 01
grp.write('32/2/22', data.indicator.values[ 2 ].value/1000)
Any ideas?
Greetings