Help with Petrol REST sensor

Ciao,
I’m trying to create a REST sensor to get petrol price from a specific petrol station. The CURL request is as follows:

curl --request GET "https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvincia/28" | jq -r '.ListaEESSPrecio[] | select(.IDEESS=="4654") | ."Precio Gasolina 95 E5"'

I’ve tried the following config without success:

  - platform: rest
    resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvincia/28
    name: gasolinera
    method: GET
    scan_interval: 86400
    json_attributes_path: "$.ListaEESSPrecio"
    value_template: >
      {% set items = value_json | selectattr('IDEESS','eq','4654') | list | first %}
      {{ items['Precio Gasolina 95 E5'] }}

Can anyone guess what I’m doing wrong?
Thanks!!

Can you please format your post correctly.

1 Like

Done, sorry!

1 Like

json_attributes_path has no influence on value_template.

You need something like:

  - platform: rest
    resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvincia/28
    name: gasolinera
    method: GET
    scan_interval: 86400
    value_template: >
      {% set items = value_json['ListaEESSPrecio'] | selectattr('IDEESS','eq','4654') | list | first %}
      {{ items['Precio Gasolina 95 E5'] }}

EDIT: you can “simplify” with

value_template: "value_json['ListaEESSPrecio'] | selectattr('IDEESS','eq','4654') | map(attribute='Precio Gasolina 95 E5') | list | first"
2 Likes

That was the issue. Thanks man!!