[SOLVED!] How would I round a sensor state attribute value?

I am using this as a notification:

The overnight low will be {% set forecast = state_attr('weather.ecobee', 'forecast') %}{{ forecast[1]['templow'] }}°C.

It outputs “The overnight low will be 18.6°C.”

Which is good, it works. I’d like to round it to say 19°C instead. It’s at-a-glance info for me, and also I don’t like the implied precision in a forecast when the actual overnight low could easily vary by a few degrees.

I have tried to round this in several places, and apparently I don’t understand how it works. Could someone help me understand how to round a sensor state attribute? Here are the things I tried:

{% set forecast = (state_attr('weather.ecobee', 'forecast') | float) | round(1) %}{{ forecast[1]['templow'] }}
{% set forecast = state_attr('weather.ecobee', 'forecast') %}{{ (forecast[1]['templow']) | float) | round(1) }}
{% (set forecast = state_attr('weather.ecobee', 'forecast') %}{{ forecast[1]['templow']) | float) | round (1) }}

Yes, I’m just trying stuff to see if any of it works. I obviously don’t know where to put the float and round. Can anyone steer me in the right direction?

Isn’t it always the case, you post a question, and just laying it out helps you figure it out yourself.

The overnight low is {% set forecast = state_attr('weather.devondale_2', 'forecast') %}{{ (forecast[1]['templow']) | float | round(0) }}°C.

It works!

Good and … a bit shorter works too :slight_smile:

The overnight low is {{ state_attr('weather.devondale_2', 'forecast')[1]['templow'] | float | round(0) }}°C
1 Like