nice and thanks for sharing!
First of all thanks for sharing this nice price tracking possibility.
Based on the initial sensor I wanted to also track the recent minimum price over the last 7 days, therefore I build the following:
This is my code:
sensors:
- platform: rest
name: Fuel
scan_interval: 600
resource: https://creativecommons.tankerkoenig.de/json/prices.php?apikey=<API>&ids=<ID>
value_template: '{ value_json.prices.[] }'
json_attributes:
- prices
- platform: template
sensors:
gasstation_1_diesel:
friendly_name: 'Behrenswerth (Diesel)'
unit_of_measurement: '€'
value_template: '{{ states.sensor.fuel.attributes["prices"]["<ID>"]["diesel"]}}'
- platform: statistics
entity_id: sensor.gasstation_1_diesel
name: gasstation_1_diesel
max_age:
days: 7
- platform: template
sensors:
gasstation_1_diesel_min:
friendly_name: 'Behrenswerth (Diesel) Min'
unit_of_measurement: '€'
value_template: '{{ states.sensor.gasstation_1_diesel_mean.attributes["min_value"] }}'
Next step would be to compare minimum price and current price, in order to trigger a notification while they are the same.
Maybe it’s not yet the most beautiful approach, but it works…
Did anybody tried to create a automation with the price as trigger and getting an notify?
I thought of sending a notification when I am near the cheapest gas station and my tank needs a refill. But as I have no way of determining the tank level I figured, I would only get spammed whenever I am near the station.
What are your thoughts?
The tanke level could be possible with the mercedes me component for example, but mine works not at the moment
I thought if price is lower than an adjustable level (may be with input_number:
)
I now created a tankerkönig component for Home-Assistant. You can find the component on GitHub https://github.com/panbachi/homeassistant-tankerkoenig
Wow, nice. Thank you
Is it possible to add a selection (like monitored conditions) for example that it only creates a sensor for diesel prices? Otherwise Home Assistant needs to keep 3 additional sensors up to date. Also i think the binary sensor should be optional.
Hi @phiwa,
This is the automation I use. It will compare the current price with recent (last days) minimum + 0.02:
- id: dieselnotification
alias: ALIASHERE
trigger:
- platform: template
value_template: '{% if states(''sensor.gasstation_1_diesel'' ) | float <= states(''sensor.gasstation_1_diesel_min'') | float + 0.02 %}true{% endif %}'
condition: []
action:
- data:
message: 'Diesel ist günstig: {{ states.sensor.gasstation_1_diesel.state }}
€/L'
service: notify.XXX
In order to compare the current price with a recent minimum I used the following sensors:
####################################################
#
# TANKERKÖNIG
#
####################################################
- platform: rest
name: Fuel
scan_interval: 600
resource: https://creativecommons.tankerkoenig.de/json/prices.php?apikey=YOURKEYHERE&ids=STATIONHERE
value_template: '{ value_json.prices.[] }'
json_attributes:
- prices
- platform: template
sensors:
gasstation_1_diesel:
friendly_name: 'FRIENDLYNAMEHERE'
unit_of_measurement: '€'
value_template: '{{ states.sensor.fuel.attributes["prices"]["STATIONHERE"]["diesel"]}}'
- platform: statistics
entity_id: sensor.gasstation_1_diesel
name: gasstation_1_diesel
max_age:
minutes: '10080'
sampling_size: 300
- platform: template
sensors:
gasstation_1_diesel_min:
friendly_name: 'YOURFRIENDLYNAMEHERE Min'
unit_of_measurement: '€'
value_template: '{{ states.sensor.gasstation_1_diesel_mean.attributes["min_value"] }}'
I hope it is of help.
Awesome. Thank you
The line 83 in custom_components/tankerkoenig.py must be changed to:
if('state' in tankerkoenig_config[CONF_MONITORED_CONDITIONS]):
And I’m getting the following error in the log:
ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: datetime.timedelta(0, 600) is not JSON serializable
After this error appears, the history and the logbook are not working anymore.
The ‘state’ typo is fixed. I can’t imagine where the recorder error comes from. Does anybody else here has this effect?
Hi,
thank you for your work and the nice component.
I have no binary_sensor for the state and no state history for the prices, but no error in the log so far.
I have used your instructions from https://www.panbachi.de/tankerkoenig-preise-in-homeassistant-darstellen-141/
to create a state card for selected gas prices.
My card is empty and did not show any gas station.
I have checked my config files with hass --script check_config and have detected no errors.
What’s wrong here? What can I do to locate the error? Any hints?
Thank you.
regards Tom
No problems here so far with this sensor.
How does your config in the sensors.yaml look like?
I have seen that now the component Tankerkönig is availabe.
Should I better use the component now?
Can I use these state cards with this component as well?
So I think I have to make less configuration changes to HA.
regards
Tom
Tankerkönig component? where?
Does anyone have a hint for me?
Didn’t get it working until now.