Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for version in templates #24131

Merged
merged 4 commits into from
Sep 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions source/_docs/configuration/templating.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`
ludeeus marked this conversation as resolved.
Show resolved Hide resolved
- `{{ (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

Expand All @@ -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.
Expand Down