Get every nth element from weather service response

Hi,
I am trying to get the temperature from the output of weather.get_forecast every third element.
Temperature is not changing so much, so I would like to safe some space on my display :wink:

I tried to use looping using a variable, according to this post: Counting simple variable in jinja (loop), but I donā€™t get the counter implemented in the .attribute.forecast[ ] the way it works correctly.

At the moment I am using this template to display the temperature of the next three hours

 {% for state in states.sensor.weather_forecast_hourly.attributes.forecast[1:4] -%}
        {{ as_timestamp(state.datetime)| timestamp_custom("%H") }}h;{{ state.temperature| round(0) }}Ā°#
        {%- endfor %}

Great idea ā€¦ I constructed this to show every 2nd oneā€¦possibly some of the guruā€™s have another idea :slight_smile:

 {% for s in range(0,states.sensor.weather_forecast_hourly.attributes.forecast|length) -%}
 {% if s  | int % 2 == 0 %}
{{ states.sensor.weather_forecast_hourly.attributes.forecast[s].temperature }}
{% endif %}        
{%- endfor %}
1 Like

It is working, thank you!

i changed the line states.sensor.weather_forecast_hourly.attributes.forecast|lengthā€™ to an integer to limit the number output values and added some more attributes to the output.

I really enjoy this community - 1h and some smart person has a solution and nobody tells you ā€œweather is stupidā€ or ā€œyou donā€™t need temperature, you need insert something totally differentā€