Great work, loving it!
Just one little improvement for the address in the secondary information, you might want to use |title
instead of |capitalize
which (in my case) will render “innsbrucker bundesstraße” to “Innsbrucker Bundesstraße” instead of “Innsbrucker bundesstraße”
1 Like
Hy,
I’ve implemented an improved version of the lovelace card using auto-entities
type: custom:auto-entities
card:
type: entities
title: Bruck an der Mur
filter:
include:
- entity_id: "sensor.fuel_price_bruck_die_*"
options:
type: custom:template-entity-row
icon: mdi:gas-station-outline
state: >
{% set state=states(config.entity) %}
{% if state != 'unknown' %}
{% set state = state + " " + state_attr(config.entity, 'unit_of_measurement') %}
{% endif %}
{{state}}
name: "{{state_attr(config.entity, 'name')}}"
secondary: >-
{{state_attr(config.entity, 'location')['postalCode']}}
{{state_attr(config.entity, 'location')['city']}},
{{state_attr(config.entity, 'location')['address']|title}}
sort:
method: state
1 Like
Wow, thanks for sharing! That’s great!
But maybe edit your original post to include this solution.
Would have saved me some time to edit all the config and throw it away again!
Pretty sure others would appreciate to avoid to wast the time as well.
But really, that’s great.
Thanks again
I’m also using your solution now. Really great work that is much appreciated!
cboogie
(Christoph)
February 18, 2023, 2:04pm
26
pachi:
Hi,
you could also just filter the json data - no need for a script.
Here is my configuration for a sensor with specified id (value_template info came from @petro @Craig_McGowan in this thread):
- name: Diesel F.Leitner Leoben
unit_of_measurement: €
device_class: monetary
value_template: "{{(value_json | selectattr('id','eq',1469006) | list | first).prices[0].amount}}"
json_attributes_path: "$.[?(@.id== 1469006)].location"
json_attributes:
- latitude
- longitude
You would only need to adapt the id to in value_template and json_attributes_path to make it work for you. I extracted lat/long as attributes, so that ha shows the fuel stations on the map.
br
Hi @pachi ,
sorry for my late feedback, i must have overlooked your post.
Anyway, i implemented the filter and it works great, that’s what i was looking for!
Thanks for sharing and best regards,
Chris
2 Likes
Hi! I also tried this snippet but I always get the first entry.
Can someone support me in this regard? → to get data from a specific gas station…
Thx, Chris
cboogie
(Christoph)
February 21, 2023, 8:44am
28
Hi, what does your filter look like and what entries do you want to see?
Currently, I can only see the first entry (it’s a list of many gas stations but I only get the first entry).
To verify the data - i used in HASSIO developer mode to check the sensor status (I can see the value, the name of the gas station, etc.) and compared with Firefox (it automatically creates a readable JSON) - same entries. I checked SUP and DIE (HASSIO and Firefox) - it’s the same.
→ I want to get some values from a specific gas station as already mentioned - there’s an ID which I can use but - no change the get the values for one specific.
I also tried this one:
value_template: "{{(value_json | selectattr('id','eq',1469006) | list | first).prices[0].amount}}"
json_attributes_path: "$.[?(@.id== 1469006)].location"
But without any success.
home88
(juergen mannsberge)
August 30, 2023, 4:36pm
31
Hallo ich habe es versucht aber irgendwie bekomme ich es nicht zum laufen steht immer unknow
rest:
- resource: https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=47.405965&longitude=15.261849&fuelType=DIE&includeClosed=true
headers:
accept: application/json
scan_interval: 1800
sensor:
- name: fuel_price_bruck_die_1
device_class: monetary
value_template: "{{ value_json[0]['prices'][0]['amount'] }}"
unit_of_measurement: "EUR"
force_update: True
json_attributes_path: "$[0]"
json_attributes:
- name
- id
- location
- name: fuel_price_bruck_die_2
device_class: monetary
value_template: "{{ value_json[1]['prices'][0]['amount'] }}"
unit_of_measurement: "EUR"
force_update: True
json_attributes_path: "$[1]"
json_attributes:
- name
- id
- location
- name: fuel_price_bruck_die_3
device_class: monetary
value_template: "{{ value_json[2]['prices'][0]['amount'] }}"
unit_of_measurement: "EUR"
force_update: True
json_attributes_path: "$[2]"
json_attributes:
- name
- id
- location
- name: fuel_price_bruck_die_4
device_class: monetary
value_template: "{{ value_json[3]['prices'][0]['amount'] }}"
unit_of_measurement: "EUR"
force_update: True
json_attributes_path: "$[3]"
json_attributes:
- name
- id
- location
- name: fuel_price_bruck_die_5
device_class: monetary
value_template: "{{ value_json[4]['prices'][0]['amount'] }}"
unit_of_measurement: "EUR"
force_update: True
json_attributes_path: "$[4]"
json_attributes:
- name
- id
- location
wo habe ich denn hund drinnen?
Gramigumi
(Richi)
September 13, 2023, 10:37am
32
Hi, hast du es hinbekommen?
Hab das gleiche Problem und finde auch den Fehler nicht…oder funktioniert die API nicht mehr?
Bin eher Neuling auf dem ganzen Gebiet
Edit: habs nun hinbekommen indem ich bei mir die URL angepasst hab von der Vorgabe hier im Forum und nicht die generierte URL von der Swagger Ui genommen habe…nun läuft alles wie es soll!
Vielen Dank!
lg Richi
Hallo, kann mir vielleicht wer helfen diese Fehler weg zu bekommen.
Logger: homeassistant.helpers.template
Source: helpers/template.py:2209
First occurred: 11:42:25 (15 occurrences)
Last logged: 11:42:25
Template variable warning: 'None' has no attribute 'postalCode' when rendering '{{state_attr(config.entity, 'location')['postalCode'] }} {{state_attr(config.entity, 'location')['city'] }}, {{state_attr(config.entity, 'location')['address']|title}}'
Template variable warning: 'None' has no attribute 'city' when rendering '{{state_attr(config.entity, 'location')['postalCode'] }} {{state_attr(config.entity, 'location')['city'] }}, {{state_attr(config.entity, 'location')['address']|title}}'
Template variable warning: 'None' has no attribute 'address' when rendering '{{state_attr(config.entity, 'location')['postalCode'] }} {{state_attr(config.entity, 'location')['city'] }}, {{state_attr(config.entity, 'location')['address']|title}}'
Ich verwende folgenden Sensor Code:
- name: diesel_preise_tankstelle_5
device_class: monetary
value_template: "{{ value_json[4]['prices'][0]['amount'] | default(0) | float }}"
unit_of_measurement: "EUR"
force_update: True
json_attributes_path: "$[4]"
json_attributes:
- name
- id
- "location"
KirchiF
(Fabian Kirchweger)
February 4, 2024, 7:06pm
34
Does anyone have any advice for me on how I can have the name and price of the gas station sent to my cell phone? I’ve only gotten so far that I can have all the data sent to me from the sensor, but I just want the price and the name of the gas station, maybe the address, but nothing more
This is what it looks like at the moment:
<template TemplateState(<state sensor.fuel_price_bruck_die_1=1.599; name=freie Tankstelle, id=34019, location=address=Salzburgerstr. 35, postalCode=4713, city=Gallspach, latitude=, longitude=, unit_of_measurement=EUR, device_class=monetary, friendly_name=fuel_price_bruck_die_1 @ 2024-02-04T19:16:54.344159+01:00>)>