Hi!
I’m trying to scrape price by hour from my local electricity provider with their API, and by now, I have multiple sensors with the value with each hour, so it isn’t really useful for me right now.
What I’m trying, is to populate a template_sensor with the values from the JSON below, each value in his correspondent timestamp, provided by their API, but I can’t figure it right now.
{
"indicator" : {
"geos" : [
{
"geo_name" : "España",
"geo_id" : 3
}
],
"magnitud" : [
{
"id" : 23,
"name" : "Precio"
}
],
"short_name" : "2.0.DHA Coste de comcercialización",
"step_type" : "linear",
"id" : 1389,
"values_updated_at" : "2019-12-15T20:21:31.000+01:00",
"disaggregated" : false,
"values" : [
{
"geo_name" : "España",
"value" : 1.76,
"geo_id" : 3,
"tz_time" : "2019-12-15T23:00:00.000Z",
"datetime_utc" : "2019-12-15T23:00:00Z",
"datetime" : "2019-12-16T00:00:00.000+01:00"
},
{
"datetime_utc" : "2019-12-16T00:00:00Z",
"tz_time" : "2019-12-16T00:00:00.000Z",
"datetime" : "2019-12-16T01:00:00.000+01:00",
"geo_name" : "España",
"value" : 1.65,
"geo_id" : 3
},
{
"geo_id" : 3,
"value" : 1.61,
"geo_name" : "España",
"datetime" : "2019-12-16T02:00:00.000+01:00",
"datetime_utc" : "2019-12-16T01:00:00Z",
"tz_time" : "2019-12-16T01:00:00.000Z"
},
{
"datetime" : "2019-12-16T03:00:00.000+01:00",
"datetime_utc" : "2019-12-16T02:00:00Z",
"tz_time" : "2019-12-16T02:00:00.000Z",
"geo_id" : 3,
"geo_name" : "España",
"value" : 1.59
},
{
"datetime_utc" : "2019-12-16T03:00:00Z",
"tz_time" : "2019-12-16T03:00:00.000Z",
"datetime" : "2019-12-16T04:00:00.000+01:00",
"geo_name" : "España",
"value" : 1.59,
"geo_id" : 3
},
{
"datetime" : "2019-12-16T05:00:00.000+01:00",
"tz_time" : "2019-12-16T04:00:00.000Z",
"datetime_utc" : "2019-12-16T04:00:00Z",
"geo_id" : 3,
"value" : 1.62,
"geo_name" : "España"
},
{
"datetime_utc" : "2019-12-16T05:00:00Z",
"tz_time" : "2019-12-16T05:00:00.000Z",
"datetime" : "2019-12-16T06:00:00.000+01:00",
"geo_name" : "España",
"value" : 1.74,
"geo_id" : 3
},
{
"tz_time" : "2019-12-16T06:00:00.000Z",
"datetime_utc" : "2019-12-16T06:00:00Z",
"datetime" : "2019-12-16T07:00:00.000+01:00",
"value" : 1.81,
"geo_name" : "España",
"geo_id" : 3
},
{
"tz_time" : "2019-12-16T07:00:00.000Z",
"datetime_utc" : "2019-12-16T07:00:00Z",
"datetime" : "2019-12-16T08:00:00.000+01:00",
"geo_name" : "España",
"value" : 1.75,
"geo_id" : 3
},
{
"geo_name" : "España",
"value" : 1.78,
"geo_id" : 3,
"datetime_utc" : "2019-12-16T08:00:00Z",
"tz_time" : "2019-12-16T08:00:00.000Z",
"datetime" : "2019-12-16T09:00:00.000+01:00"
},
{
"geo_id" : 3,
"geo_name" : "España",
"value" : 1.74,
"datetime" : "2019-12-16T10:00:00.000+01:00",
"tz_time" : "2019-12-16T09:00:00.000Z",
"datetime_utc" : "2019-12-16T09:00:00Z"
},
{
"geo_name" : "España",
"value" : 1.71,
"geo_id" : 3,
"datetime_utc" : "2019-12-16T10:00:00Z",
"tz_time" : "2019-12-16T10:00:00.000Z",
"datetime" : "2019-12-16T11:00:00.000+01:00"
},
{
"datetime" : "2019-12-16T12:00:00.000+01:00",
"tz_time" : "2019-12-16T11:00:00.000Z",
"datetime_utc" : "2019-12-16T11:00:00Z",
"geo_id" : 3,
"value" : 1.85,
"geo_name" : "España"
},
{
"datetime" : "2019-12-16T13:00:00.000+01:00",
"datetime_utc" : "2019-12-16T12:00:00Z",
"tz_time" : "2019-12-16T12:00:00.000Z",
"geo_id" : 3,
"value" : 1.84,
"geo_name" : "España"
},
{
"tz_time" : "2019-12-16T13:00:00.000Z",
"datetime_utc" : "2019-12-16T13:00:00Z",
"datetime" : "2019-12-16T14:00:00.000+01:00",
"value" : 1.82,
"geo_name" : "España",
"geo_id" : 3
},
{
"datetime" : "2019-12-16T15:00:00.000+01:00",
"tz_time" : "2019-12-16T14:00:00.000Z",
"datetime_utc" : "2019-12-16T14:00:00Z",
"geo_id" : 3,
"geo_name" : "España",
"value" : 1.83
},
{
"geo_id" : 3,
"value" : 1.82,
"geo_name" : "España",
"datetime" : "2019-12-16T16:00:00.000+01:00",
"datetime_utc" : "2019-12-16T15:00:00Z",
"tz_time" : "2019-12-16T15:00:00.000Z"
},
{
"geo_id" : 3,
"geo_name" : "España",
"value" : 1.83,
"datetime" : "2019-12-16T17:00:00.000+01:00",
"tz_time" : "2019-12-16T16:00:00.000Z",
"datetime_utc" : "2019-12-16T16:00:00Z"
},
{
"value" : 1.86,
"geo_name" : "España",
"geo_id" : 3,
"tz_time" : "2019-12-16T17:00:00.000Z",
"datetime_utc" : "2019-12-16T17:00:00Z",
"datetime" : "2019-12-16T18:00:00.000+01:00"
},
{
"datetime_utc" : "2019-12-16T18:00:00Z",
"tz_time" : "2019-12-16T18:00:00.000Z",
"datetime" : "2019-12-16T19:00:00.000+01:00",
"value" : 1.91,
"geo_name" : "España",
"geo_id" : 3
},
{
"datetime" : "2019-12-16T20:00:00.000+01:00",
"datetime_utc" : "2019-12-16T19:00:00Z",
"tz_time" : "2019-12-16T19:00:00.000Z",
"geo_id" : 3,
"geo_name" : "España",
"value" : 1.89
},
{
"geo_id" : 3,
"value" : 1.82,
"geo_name" : "España",
"datetime" : "2019-12-16T21:00:00.000+01:00",
"datetime_utc" : "2019-12-16T20:00:00Z",
"tz_time" : "2019-12-16T20:00:00.000Z"
},
{
"datetime" : "2019-12-16T22:00:00.000+01:00",
"datetime_utc" : "2019-12-16T21:00:00Z",
"tz_time" : "2019-12-16T21:00:00.000Z",
"geo_id" : 3,
"geo_name" : "España",
"value" : 1.66
},
{
"datetime" : "2019-12-16T23:00:00.000+01:00",
"datetime_utc" : "2019-12-16T22:00:00Z",
"tz_time" : "2019-12-16T22:00:00.000Z",
"geo_id" : 3,
"geo_name" : "España",
"value" : 1.63
}
],
"composited" : false,
"tiempo" : [
{
"id" : 4,
"name" : "Hora"
}
],
"name" : "Desglose eficiencia 2 periodos (DHA) 2.0.DHA Coste de comercialización"
}
}
And my sensor is:
sensor:
- platform: rest
name: precioluz_ree
method: GET
resource_template: https://api.esios.ree.es/indicators/1389?start_date={{ now().strftime('%Y-%m-%d') }}T00:00:00&end_date={{ now().strftime('%Y-%m-%d') }}T23:50:00"
headers:
Accept: application/json; application/vnd.esios-api-v1+json
Content-Type: application/json
Host: api.esios.ree.es
Authorization: !secret token_ree
# Cookie:
value_template: '{{ value_json.indicator.values.value }}'
scan_interval: 300
Any help is welcomed!