How to get multiple sensors for 1 rest call with Petrol REST?

Hello!

I’m stying to get multiple sensors from 1 rest call from Petrol API. Any idea how to do it? My sensors.yaml file… Only can see the last sensor…

- platform: rest
  resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvincia/07
  scan_interval: 1800
# CARRETERA MA-15 KM. 36,6
  name: "GAS95 - Sant Joan REPSOL"
  value_template: >-
    {% set station = value_json['ListaEESSPrecio'] | selectattr('IDEESS', 'match', '2723') | first %}
    {{ station['Precio Gasolina 95 E5'] | replace(",",".") }}
  unit_of_measurement: "€/L"
# CARRETERA C-715 KM. 42,5
  name: "GAS95 - Vilafranca CEPSA"
  value_template: >-
    {% set station = value_json['ListaEESSPrecio'] | selectattr('IDEESS', 'match', '2599') | first %}
    {{ station['Precio Gasolina 95 E5'] | replace(",",".") }}
  unit_of_measurement: "€/L"

Did you look at restful ?
RESTful - Home Assistant (home-assistant.io)

Yes, I have tried it in configuration.yaml and it works, the problem comes when I try to transfer the configuration of the multiple sensors from a REST query to the file sensors.yaml
I don’t know how to define multiple sensors with a single REST query in sensors.yaml config file
Thanks for your reply anyway.

Not sure if you read this but these are two different things…
restful integration and restful sensor look the same but have their particular things
RESTful Sensor - Home Assistant (home-assistant.io)
In the first few lines you can read when to go for restful int.

versus

RESTful - Home Assistant (home-assistant.io)

2 Likes
rest:
  - resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvincia/07
    scan_interval: 1800
    sensor:
      # CARRETERA MA-15 KM. 36,6
      - name: "GAS95 - Sant Joan REPSOL"
        value_template: >
          {% set station = value_json['ListaEESSPrecio'] | selectattr('IDEESS', 'match', '2723') | first %}
          {{ station['Precio Gasolina 95 E5'] | replace(",",".") }}
        unit_of_measurement: "€/L"

      # CARRETERA C-715 KM. 42,5
      - name: "GAS95 - Vilafranca CEPSA"
        value_template: >
          {% set station = value_json['ListaEESSPrecio'] | selectattr('IDEESS', 'match', '2599') | first %}
          {{ station['Precio Gasolina 95 E5'] | replace(",",".") }}
        unit_of_measurement: "€/L"
1 Like

I have managed to get different gas station sensors to appear by configuring a REST integration with a single query in the configuration.yaml file. But I can’t get that configuration into the sensors.yaml file. Can this configuration be transferred to the sensors.yaml file?

Thank you tom_I! This configuration works perfect in configuration.yaml! But can I move this configuration to sensors.yaml file or it’s imposible?

It’s a separate integration and it stays in a separate location. You can include it the same way as sensors.yaml, but with a different file name… e.g.

rest: !include rest.yaml

then in rest.yaml

  - resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroProvincia/07
    scan_interval: 1800
    sensor:
      # CARRETERA MA-15 KM. 36,6
      - name: "GAS95 - Sant Joan REPSOL"
        value_template: >
          {% set station = value_json['ListaEESSPrecio'] | selectattr('IDEESS', 'match', '2723') | first %}
          {{ station['Precio Gasolina 95 E5'] | replace(",",".") }}
        unit_of_measurement: "€/L"

      # CARRETERA C-715 KM. 42,5
      - name: "GAS95 - Vilafranca CEPSA"
        value_template: >
          {% set station = value_json['ListaEESSPrecio'] | selectattr('IDEESS', 'match', '2599') | first %}
          {{ station['Precio Gasolina 95 E5'] | replace(",",".") }}
        unit_of_measurement: "€/L"

It may seem silly. But it’s what I was looking for. I sin as a rookie. I try to keep a bit of organization in the configuration.yaml.
Thank you Petro and the everyone.

image

hy, do you have any idea how can I use multiple files? For example: rest1.yaml, rest2.yaml etc.
How can I merge this and include inside the configuration.yaml?

Thank you!