I’d like the following to return just “xx” if it’s xx.0 but leave xx.5 as xx.5. Possible?
The living room is currently {{ state_attr("climate.living_room","current_temperature")|round(1,"half") }} degrees
I’d like the following to return just “xx” if it’s xx.0 but leave xx.5 as xx.5. Possible?
The living room is currently {{ state_attr("climate.living_room","current_temperature")|round(1,"half") }} degrees
The living room is currently {{ state_attr("climate.living_room","current_temperature")|round(1)|replace('.0','' }} degrees
Thank for leading me in the right direction!
I had to add )
to make your suggestion work…
{{ state_attr("climate.living_room","current_temperature") | round(1,"half") | replace('.0','') }}
Can you explain what this does?
round(1,"half")
I’ve only ever seen round(n)
and can’t find any documentation on what you have done.
Also, apologies for the missing closing bracket.
round(1,"half")
rounds to the nearest .5
See https://www.home-assistant.io/docs/configuration/templating/#numeric-functions-and-filters
Filter round(x)
will convert the input to a number and round it to x
decimals. Round has four modes and the default mode (with no mode specified) will round-to-even.
round(x, "floor")
will always round down to x
decimalsround(x, "ceil")
will always round up to x
decimalsround(1, "half")
will always round to the nearest .5 value. x
should be 1 for this modeNo worries about the syntax! I figured it out…
Good Morning!
The living room is currently {{ state_attr("climate.living_room","current_temperature")|round(1,"half")|replace('.0','') }} degrees
and the heat is {% if is_state("climate.living_room", "off") %}turned off.
{% else %}set to {{ state_attr("climate.living_room","temperature")|round(1,"half")|replace('.0','') }} degrees.
{% endif %}The temperature outside feels like {{ states("sensor.norton_court_realfeel_temperature")|round }} degrees.
Thanks again!