From 245b047eb668e75672f33f1bee6b2b444ac0a227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Thu, 15 Sep 2022 15:02:14 +0200 Subject: [PATCH] Add documentation for version in templates (#24131) Co-authored-by: Franck Nijhof --- source/_docs/configuration/templating.markdown | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/source/_docs/configuration/templating.markdown b/source/_docs/configuration/templating.markdown index 77d92cf3504..1b0c5405cb9 100644 --- a/source/_docs/configuration/templating.markdown +++ b/source/_docs/configuration/templating.markdown @@ -548,6 +548,23 @@ Example using `is_defined` to parse a JSON payload: This will throw an error `UndefinedError: 'value_json' is undefined` if the JSON payload has no `val` attribute. +### Version + +- `version()` Returns a [AwesomeVersion object](https://github.com/ludeeus/awesomeversion) for the value given inside the brackets. + - This is also available as a filter (`| version`). + +Examples: + +{% raw %} + +- `{{ version("2099.9.9") > "2000.0.0" }}` Will return `True` +- `{{ version("2099.9.9") < "2099.10" }}` Will return `True` +- `{{ "2099.9.9" | version < "2099.10" }}` Will return `True` +- `{{ (version("2099.9.9") - "2100.9.10").major }}` Will return `True` +- `{{ (version("2099.9.9") - "2099.10.9").minor }}` Will return `True` +- `{{ (version("2099.9.9") - "2099.9.10").patch }}` Will return `True` + +{% endraw %} ### Distance @@ -556,6 +573,7 @@ Not supported in [limited templates](#limited-templates). - `distance()` will measure the distance in kilometers between home, entity, coordinates. - `closest()` will find the closest entity. + #### Distance examples If only one location is passed in, Home Assistant will measure the distance from home.