Min Max sensor: how to show which sensor is reported?

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

What do you have so far? What sensor?

Prezzibenzina sensor, an italian website.

# 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?

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!

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?

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:

image

I want to know if it is possible to see which sensor has the lowest value.

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 %}

Status is error:

image

what does sensors, min, and selection look like in the template editor when you paste that code in it?

Always error:

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 }}

No results.

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 }}

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]

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 }}

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!

Yes, you’ll also need to change the name of the template sensor. probably lowest_petrol

1 Like

It worked, THANK YOU!

1 Like