Retrieve values from a list with attributes and own attribute

Hi,
i’m learning but now it’s time to ash Help :slight_smile:

Briefly:
I have a template sesor :slight_smile:
a list where are stored 10 values ( data retrived every 10min)
hourly_pressure:

  • pressure: “1045.4”
    time: “2025-09-25T21:30:00.493249+02:00”
  • pressure: “1045.3”
    time: “2025-09-25T21:20:00.493682+02:00”
  • pressure: “1045.3”
    time: “2025-09-25T21:10:00.493549+02:00”

I need from this list 2 series:
serie1: index 0 -1-2 (basically tha last 3 based on time )
serie2: 9-8-7 ( the first 3 time based on this list)
Scope: average for each serie and after that math compare ( is great is low ,)

By the way, i’m able to retrieve 1 single value:

{{state_attr(‘sensor.atmopressure’,‘hourly_pressure’)[2] .pressure }}
I get the right value for presuure on index 3

I tried several options without any chance to retrieve multi values.
Dont “kill me”

Thanks to all for Suuport,

Series 1

{{ (state_attr('sensor.atmopressure','hourly_pressure')
| sort(attribute='time', reverse=true))[:3] | map(attribute='pressure') | list }}

… or if you just want the average:

{{ (state_attr('sensor.atmopressure','hourly_pressure')
| sort(attribute='time', reverse=true))[:3] | map(attribute='pressure') 
| map('float', 0) | average }}

Series 2 is the same, just remove the reverse=true from the sort.


If you are trying to determine whether pressure is rising or falling over time, there are bult-in integrations/methods to do that:

Copy-paste the following into the Template Editor and experiment with it.

{% set x = state_attr('sensor.atmopressure', 'hourly_pressure')
  | map(attribute='pressure')
  | map('float', 0) | list -%}

First three values (index 0 to 2).
{{ x[:3] }}

Average of first three values.
{% set y = x[:3] | average -%}
y is {{ y }}

Last three values (index 7 to 9).
{{ x[-3:] }}

Average of last three values.
{% set z = x[-3:] | average -%}
z is {{ z }}

Variable y is {{ 'same as' if y == z else 'greater than' if y > z else 'less than' }} variable z.

If you want pressure values based on oldest/newest times then you’ll need to sort them by time (see Didgeridrew’s example).

2 Likes

wooowww
First of all thks both of you Didgeridrew’s and Taras

I’ll read and experiment your suggestions