Hi,
I’m trying to create an automation that will send a push notification to my ios device if the diesel price dops below a price defined by a input slider.
Right now I have it working, but with everyhing “hard coded”. I’d like to use a for loop and only list the gas stations that are below the slider limit. I googled for the better part of the afternoon, found many examples but nothing worked out so far.
What I’d like to archive:
- loop through group.all_gas_stations
- if diesel price is below slider value, add the gas station name and the price to the push notification.
My attempt at this is (loop based) version is a mess, so I think it’s better to add the “static” version here:
automation:
alias: Diesel Price Monitor
trigger:
platform: state
entity_id: sensor.score_holtland_diesel, sensor.vela24_diesel, sensor.multi_emden_diesel, input_number.slider1
condition:
condition: or
conditions:
- condition: template
value_template: "{{ (states('sensor.score_holtland_diesel')|float) < (states('input_number.slider1')|float) }}"
- condition: template
value_template: "{{ (states('sensor.vela24_diesel')|float) < (states('input_number.slider1')|float) }}"
- condition: template
value_template: "{{ (states('sensor.multi_emden_diesel')|float) < (states('input_number.slider1')|float) }}"
action:
service: notify.ios_socrates_iphone
data_template:
message: |-
Current Prices: {{state_attr('sensor.score_holtland_diesel', 'friendly_name')}}: {{ states('sensor.score_holtland_diesel') }}
Current Prices: {{state_attr('sensor.vela24_diesel', 'friendly_name')}}: {{ states('sensor.vela24_diesel') }}
Current Prices: {{state_attr('sensor.multi_
Could someone point me at some comprehensive documentation or maybe show me how I can remove the hard coded entries in data_template and maybe even in condition?
I know it would be better to post the “not working” version, but since I currently (sadly) lack understanding of the template engine my “not working” version is really only try and error.
Entities (from the web frontend to show value and attributes)
group.all_gas_stations unknown
entity_id: sensor.score_holtland_diesel,sensor.vela24_diesel,sensor.multi_emden_diesel
friendly_name: All Gas Stations
view: true
order: 1
hidden: true
input_number.slider1 1.1
icon: mdi:currency-eur
friendly_name: Notification Price Diesel
step: 0.01
min: 1.1
initial: null
mode: slider
unit_of_measurement: €
max: 1.5
sensor.multi_emden_diesel 1.239
id: 839ec92a-1b5c-4989-82bc-5bebac644742
name: Multi Emden
friendly_name: Multi Emden Diesel
unit_of_measurement: €
icon: mdi:gas-station
sensor.score_holtland_diesel 1.279
id: 6151509b-91c5-43fe-ed78-a5196b38888c
name: Score Holtland
friendly_name: Score Holtland Diesel
unit_of_measurement: €
icon: mdi:gas-station
sensor.vela24_diesel 1.339
id: c0c4e510-c7b0-46b4-564b-808a6439cc0d
name: VELA24
friendly_name: VELA24 Diesel
unit_of_measurement: €
icon: mdi:gas-station
Thanks in advance!