Hi, I am playing with a json who has info about gas stations prices in my city, without knowing nothing about rest sensor, I’ve managed to get that info this way:
rest:
- resource: https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroMunicipioProducto/1220/1
scan_interval: 86400
sensor:
- name: Gasolinera 1 nombre
value_template: "{{ value_json['ListaEESSPrecio'][0]['Rótulo'] }}"
- name: Gasolinera 1 precio
value_template: "{{ value_json['ListaEESSPrecio'][0]['PrecioProducto'] }}"
unit_of_measurement: "€"
- name: Gasolinera 1 dirección
value_template: "{{ value_json['ListaEESSPrecio'][0]['Dirección'] }}"
# - name: Gasolinera 2 nombre
# value_template: "{{ value_json['ListaEESSPrecio'][1]['Rótulo'] }}"
# - name: Gasolinera 2 precio
# value_template: "{{ value_json['ListaEESSPrecio'][1]['PrecioProducto'] }}"
# unit_of_measurement: "€"
# - name: Gasolinera 2 dirección
# value_template: "{{ value_json['ListaEESSPrecio'][1]['Dirección'] }}"
# - name: Gasolinera 3 nombre
# value_template: "{{ value_json['ListaEESSPrecio'][2]['Rótulo'] }}"
# - name: Gasolinera 3 precio
# value_template: "{{ value_json['ListaEESSPrecio'][2]['PrecioProducto'] }}"
# unit_of_measurement: "€"
# - name: Gasolinera 3 dirección
# value_template: "{{ value_json['ListaEESSPrecio'][2]['Dirección'] }}"
This return the json data:
{
"Fecha": "22/03/2022 12:10:11",
"ListaEESSPrecio": [
{
"C.P.": "09003",
"Dirección": "CL GENERAL SANZ PASTOR, S.N.",
"Horario": "L-V: 08:00-16:00",
"Latitud": "42,344667",
"Localidad": "BURGOS",
"Longitud (WGS84)": "-3,698667",
"Margen": "D",
"Municipio": "Burgos",
"PrecioProducto": "1,789",
"Provincia": "BURGOS",
"Remisión": "OM",
"Rótulo": "REPSOL",
"Tipo Venta": "P",
"IDEESS": "5989",
"IDMunicipio": "1220",
"IDProvincia": "09",
"IDCCAA": "08"
},
{
"C.P.": "09001",
"Dirección": "LOPEZ BRAVO, 93",
"Horario": "L-V: 06:30-22:00; S: 08:00-14:30",
"Latitud": "42,362528",
"Localidad": "BURGOS",
"Longitud (WGS84)": "-3,762083",
"Margen": "D",
"Municipio": "Burgos",
"PrecioProducto": "1,798",
"Provincia": "BURGOS",
"Remisión": "dm",
"Rótulo": "VILLALÓN",
"Tipo Venta": "P",
"IDEESS": "9803",
"IDMunicipio": "1220",
"IDProvincia": "09",
"IDCCAA": "08"
},
{
"C.P.": "09001",
"Dirección": "CALLE CONDADO DE TREVIÑO, 30",
"Horario": "L-D: 06:00-00:00",
"Latitud": "42,370528",
"Localidad": "BURGOS",
"Longitud (WGS84)": "-3,718528",
"Margen": "I",
"Municipio": "Burgos",
"PrecioProducto": "1,792",
"Provincia": "BURGOS",
"Remisión": "dm",
"Rótulo": "VILLALONQUEJAR",
"Tipo Venta": "P",
"IDEESS": "11878",
"IDMunicipio": "1220",
"IDProvincia": "09",
"IDCCAA": "08"
}]
}
And so more results.
Then in a lovelace card I show the info like this:
title: Gasolineras
type: entities
entities:
- entity: sensor.gasolinera_1_precio
name: Gasolinera 1
type: custom:secondaryinfo-entity-row
secondary_info: '[[ sensor.gasolinera_1_nombre ]] - [[ sensor.gasolinera_1_direccion ]]'
- entity: sensor.gasolinera_2_precio
name: Gasolinera 2
type: custom:secondaryinfo-entity-row
secondary_info: '[[ sensor.gasolinera_2_nombre ]] - [[ sensor.gasolinera_2_direccion ]]'
- entity: sensor.gasolinera_3_precio
name: Gasolinera 3
type: custom:secondaryinfo-entity-row
secondary_info: '[[ sensor.gasolinera_3_nombre ]] - [[ sensor.gasolinera_3_direccion ]]'
But this gives me the first 3 results of course. My questions is, is it possible to order all the results for example by the field “Precio” (Price) and then in the card show the lower 3 gas stations of all of the results?
Thank you as always!