You may be interested to know that I have another solution that I feel works more efficiently. It pre-processes the contents of the URL using jq (a command-line JSON processor). It means that the sensor will receive only the data you want (for gasolinera1, gasolinera2, gasolinera3, etc) instead of containing all the data returned by the URL. However, for this to work, your Home Assistant must be running on Linux and contain the jq software (I am using Ubuntu and jq is already installed). If you are using hass.io then I donāt think jq is available.
OK, if youāre happy with the current solution then all is well.
Just to show you what I was experimenting with, the following jq query extracts three matching IDEESS items then formats them into a simple dictionary consisting of id and precio.
Hereās one more solution that stores much less data in the RESTful sensor. It also stores it in the sensorās state as opposed to an attribute.
- platform: rest
resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroMunicipioProducto/4354/4
name: gasolinera
value_template: >
{%- for y in value_json.ListaEESSPrecio | selectattr('IDEESS', 'in', '3089, 4520, 4337, 12878') | list -%}
{{y.IDEESS}}:{{(y.PrecioProducto).replace(',','.')}},
{%- endfor -%}
scan_interval: 86400
In the template, change '3089, 4520, 4337, 12878' to all the IDEESS values you need. The sensorās state value will look something like this (very compact and less than 255 characters):
4520:1.279,12878:1.209,3089:1.189,4337:1.259,
Each Template Sensor matches the desired IDEESS value and gets the associated precio (using the function regex_findall_index).