Jokerigno
(Jokerigno)
January 22, 2019, 9:38am
1
Hi all,
I’m using a min_max sensor to monitor gasoline cost using a new sensor available in 0.85. It works but I’m wondering if there’s a way to show which gas pump has the lowest value reported by the min max sensor.
Can someone please help me?
Thank you in advance
hometoast
(Hometoast)
January 22, 2019, 1:04pm
2
What do you have so far? What sensor?
Jokerigno
(Jokerigno)
January 22, 2019, 1:05pm
3
Prezzibenzina sensor, an italian website.
hometoast
(Hometoast)
January 22, 2019, 1:08pm
4
# Example configuration.yaml entry
sensor:
- platform: prezzibenzina
station: STATION_ID
It appears that the sensor configuration requires a specific station to query. Are you querying more than one station and want to pick which one is the lowest?
Jokerigno
(Jokerigno)
January 22, 2019, 1:11pm
5
Yes.
I’ve specified different stations andh then merged it in one min_max sensor. So now I can see the lowest gasoline price in my home town. But I want to see also which gasoline station has it!
petro
(Petro)
January 22, 2019, 4:53pm
6
can you provide a screenshot of the sensor made from prezzibenzina in the states window? Also, can you provide all the entity_id’s and template sensor you made?
Jokerigno
(Jokerigno)
January 28, 2019, 4:10pm
7
sorry for the delay.
here’s the sensor code:
platform: min_max
type: min
entity_ids:
sensor.carrefour_torino_benzina_self_service
sensor.q8easy_grugliasco_c_o_cc_le_gru_benzina_self_service
sensor.rifornimento_pinerolo_benzina_self_service
and it looks like this:
I want to know if it is possible to see which sensor has the lowest value.
petro
(Petro)
January 28, 2019, 5:25pm
8
sensor:
- platform: template
sensors:
petrol:
friendly_name: Lowest Petrol
value_template: >
{% set sensors = [ 'sensor.carrefour_torino_benzina_self_service', 'sensor.q8easy_grugliasco_c_o_cc_le_gru_benzina_self_service', 'sensor.rifornimento_pinerolo_benzina_self_service' ] %}
{% set min = states('sensor.min') %}
{% set selection = states.sensor | selectattr('entity_id', 'in', sensors) | selectattr('state', 'eq', min) | map(attribute='name') | list %}
{% if selection | length > 0 %}
{{ selection[0] }}
{% else %}
Error
{% endif %}
petro
(Petro)
January 29, 2019, 12:02am
10
what does sensors, min, and selection look like in the template editor when you paste that code in it?
petro
(Petro)
January 29, 2019, 12:27pm
12
yes, but in order to debug it, i need to know more information. Put the following into the template editor
{{ sensors }}
{{ min }}
{{ selection }}
{{ sensors | map(attribute='state') | list }}
petro
(Petro)
January 29, 2019, 1:23pm
14
You gotta put the other template in too!
{% set sensors = [ 'sensor.carrefour_torino_benzina_self_service', 'sensor.q8easy_grugliasco_c_o_cc_le_gru_benzina_self_service', 'sensor.rifornimento_pinerolo_benzina_self_service' ] %}
{% set min = states('sensor.min') %}
{% set selection = states.sensor | selectattr('entity_id', 'in', sensors) | selectattr('state', 'eq', min) | map(attribute='name') | list %}
{% if selection | length > 0 %}
{{ selection[0] }}
{% else %}
Error
{% endif %}
{{ sensors }}
{{ min }}
{{ selection }}
{{ sensors | map(attribute='state') | list }}
Jokerigno
(Jokerigno)
January 29, 2019, 1:30pm
15
OPS!
Error
[‘sensor.carrefour_torino_benzina_self_service’, ‘sensor.q8easy_grugliasco_c_o_cc_le_gru_benzina_self_service’, ‘sensor.rifornimento_pinerolo_benzina_self_service’]
unknown
[]
[Undefined, Undefined, Undefined]
petro
(Petro)
January 29, 2019, 1:34pm
16
Ok, first problem, the name for the min sensor is wrong. Only you know that, so what is it? Second error was a typo on my part.
put this into the editor
{% set sensors = [ 'sensor.carrefour_torino_benzina_self_service', 'sensor.q8easy_grugliasco_c_o_cc_le_gru_benzina_self_service', 'sensor.rifornimento_pinerolo_benzina_self_service' ] %}
{% set min = states('sensor.min') %}
{% set selection = states.sensor | selectattr('entity_id', 'in', sensors) | selectattr('state', 'eq', min) | map(attribute='name') | list %}
{% if selection | length > 0 %}
{{ selection[0] }}
{% else %}
Error
{% endif %}
{{ sensors }}
{{ min }}
{{ selection }}
{{ states.sensor | selectattr('entity_id', 'in', sensors) | map(attribute='state') | list }}
Jokerigno
(Jokerigno)
January 29, 2019, 4:26pm
17
the min sensor name is petrol. So I have to change {% set min = states(‘sensor.min’) %} to {% set min = states(‘sensor.petrol’) %} right?
Sorry but I’m a noob on templating!
petro
(Petro)
January 29, 2019, 5:19pm
18
Yes, you’ll also need to change the name of the template sensor. probably lowest_petrol
1 Like