diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index ea338e22b84..83c347c7cb2 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -1457,6 +1457,9 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment): self.globals["timedelta"] = timedelta self.globals["strptime"] = strptime self.globals["urlencode"] = urlencode + self.globals["max"] = max + self.globals["min"] = min + if hass is None: return diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index 06b313218ca..0e8b2f76843 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -567,11 +567,15 @@ def test_from_json(hass): def test_min(hass): """Test the min filter.""" assert template.Template("{{ [1, 2, 3] | min }}", hass).async_render() == 1 + assert template.Template("{{ min([1, 2, 3]) }}", hass).async_render() == 1 + assert template.Template("{{ min(1, 2, 3) }}", hass).async_render() == 1 def test_max(hass): """Test the max filter.""" assert template.Template("{{ [1, 2, 3] | max }}", hass).async_render() == 3 + assert template.Template("{{ max([1, 2, 3]) }}", hass).async_render() == 3 + assert template.Template("{{ max(1, 2, 3) }}", hass).async_render() == 3 def test_ord(hass):