diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index aa17b2a1fba..e389f95dae1 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -669,6 +669,8 @@ def forgiving_round(value, precision=0, method="common"): value = math.ceil(float(value) * multiplier) / multiplier elif method == "floor": value = math.floor(float(value) * multiplier) / multiplier + elif method == "half": + value = round(float(value) * 2) / 2 else: # if method is common or something else, use common rounding value = round(float(value), precision) diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index b69fdb17e35..f2066ce2c6f 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -227,6 +227,13 @@ def test_rounding_value(hass): == "12.8" ) + assert ( + template.Template( + '{{ states.sensor.temperature.state | round(1, "half") }}', hass + ).async_render() + == "13.0" + ) + def test_rounding_value_get_original_value_on_error(hass): """Test rounding value get original value on error."""