Hi all,
I’m quite new to Home-Assistant and the last two days I’m trying to figure out how to extract some data from a nested JSON file which somehow is not working for me.
The given answers helped me already a lot to get an idea how it could be done, but I think I still miss something as I can’t make it run.
The data of the JSON file is data about petrol stations and fuel prices. I would like to extract the following info:
- Name (of the petrol station)
- Label (diesel/gasoline)
- Price (amount)
This would be the formatted JSON output:
[
{
"id": 1354695,
"name": "avanti - Rum Dörfer Straße 26b",
"location": {
"address": "Doerfer Strasse 26b",
"postalCode": "6064",
"city": "Rum",
"latitude": 47.2873,
"longitude": 11.46305
},
"contact": {
"telephone": "800202055",
"fax": "800",
"website": "www.omv.com"
},
"openingHours": [
{
"day": "MO",
"label": "Montag",
"order": 1,
"from": "07:00",
"to": "20:00"
},
{
"day": "DI",
"label": "Dienstag",
"order": 2,
"from": "07:00",
"to": "20:00"
},
{
"day": "MI",
"label": "Mittwoch",
"order": 3,
"from": "07:00",
"to": "20:00"
},
{
"day": "DO",
"label": "Donnerstag",
"order": 4,
"from": "07:00",
"to": "20:00"
},
{
"day": "FR",
"label": "Freitag",
"order": 5,
"from": "07:00",
"to": "20:00"
},
{
"day": "SA",
"label": "Samstag",
"order": 6,
"from": "07:00",
"to": "20:00"
},
{
"day": "SO",
"label": "Sonntag",
"order": 7,
"from": "07:00",
"to": "20:00"
},
{
"day": "FE",
"label": "Feiertag",
"order": 8,
"from": "07:00",
"to": "20:00"
}
],
"offerInformation": {
"service": false,
"selfService": true,
"unattended": true
},
"paymentMethods": {
"cash": false,
"debitCard": true,
"creditCard": true,
"others": "OMV STATIONSKARTE, DKV, MASTERCARD, MAESTRO, ROUTEX, DINERS, VISA"
},
"paymentArrangements": {
"cooperative": false,
"clubCard": false
},
"position": 1,
"open": true,
"distance": 3.3402903474358094,
"prices": [
{
"fuelType": "DIE",
"amount": 1.113,
"label": "Diesel"
}
]
},
{
"id": 665616,
"name": "avanti - Rum Siemensstraße 1",
"location": {
"address": "Siemensstrasse 1",
"postalCode": "6063",
"city": "Rum",
"latitude": 47.27753,
"longitude": 11.45756
},
"contact": {
"telephone": "800202055",
"fax": "800",
"website": "www.omv.com"
},
"openingHours": [
{
"day": "MO",
"label": "Montag",
"order": 1,
"from": "00:00",
"to": "24:00"
},
{
"day": "DI",
"label": "Dienstag",
"order": 2,
"from": "00:00",
"to": "24:00"
},
{
"day": "MI",
"label": "Mittwoch",
"order": 3,
"from": "00:00",
"to": "24:00"
},
{
"day": "DO",
"label": "Donnerstag",
"order": 4,
"from": "00:00",
"to": "24:00"
},
{
"day": "FR",
"label": "Freitag",
"order": 5,
"from": "00:00",
"to": "24:00"
},
{
"day": "SA",
"label": "Samstag",
"order": 6,
"from": "00:00",
"to": "24:00"
},
{
"day": "SO",
"label": "Sonntag",
"order": 7,
"from": "00:00",
"to": "24:00"
},
{
"day": "FE",
"label": "Feiertag",
"order": 8,
"from": "00:00",
"to": "24:00"
}
],
"offerInformation": {
"service": false,
"selfService": true,
"unattended": true
},
"paymentMethods": {
"cash": false,
"debitCard": true,
"creditCard": true,
"others": "OMV STATIONSKARTE, DKV, MASTERCARD, MAESTRO, ROUTEX, DINERS, VISA"
},
"paymentArrangements": {
"cooperative": false,
"clubCard": false
},
"position": 2,
"open": true,
"distance": 3.7335185653760985,
"prices": [
{
"fuelType": "DIE",
"amount": 1.113,
"label": "Diesel"
}
]
},
{
"id": 36007,
"name": "Disk",
"location": {
"address": "Innsbrucker Straße 28",
"postalCode": "6060",
"city": "Hall",
"latitude": 47.2783007,
"longitude": 11.4950006
},
"contact": {
"telephone": "43522357242"
},
"openingHours": [
{
"day": "MO",
"label": "Montag",
"order": 1,
"from": "06:00",
"to": "20:00"
},
{
"day": "DI",
"label": "Dienstag",
"order": 2,
"from": "06:00",
"to": "20:00"
},
{
"day": "MI",
"label": "Mittwoch",
"order": 3,
"from": "06:00",
"to": "20:00"
},
{
"day": "DO",
"label": "Donnerstag",
"order": 4,
"from": "06:00",
"to": "20:00"
},
{
"day": "FR",
"label": "Freitag",
"order": 5,
"from": "06:00",
"to": "20:00"
},
{
"day": "SA",
"label": "Samstag",
"order": 6,
"from": "06:00",
"to": "20:00"
},
{
"day": "SO",
"label": "Sonntag",
"order": 7,
"from": "08:00",
"to": "20:00"
},
{
"day": "FE",
"label": "Feiertag",
"order": 8,
"from": "08:00",
"to": "20:00"
}
],
"offerInformation": {
"service": false,
"selfService": true,
"unattended": false
},
"paymentMethods": {
"cash": true,
"debitCard": true,
"creditCard": true,
"others": "MOL Card, DKV, UTA"
},
"paymentArrangements": {
"cooperative": false,
"clubCard": false
},
"position": 3,
"open": true,
"distance": 0.9625345521235231,
"prices": [
{
"fuelType": "DIE",
"amount": 1.119,
"label": "Diesel"
}
]
}
]
To extract the data of my interest would be:
Name of the petrol station:
value_template: '{{ value_jason.[0].name }}'
Label:
value_template: '{{ value_jason.[0].prices[0].label}}'
Price:
value_template: '{{ value_jason.[0].prices[0].amount}}'
In my configuration.yaml I added the following:
sensor:
- platform: rest
resource: https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=47.281929&longitude=11.506570&fuelType=DIE&includeClosed=false
scan_interval: 15
name: Name
value_template: '{{ value_jason.[0].name }}'
If I restart HomeAssistant, nothing shows up in the “Developer-Tools”.
Would be highly appreciated if someone could point me in the direction what I’m missing or miss-configured.
Thank you all in advance!