Skip to content

Commit ce53c0e

Browse files
Shoufabaff
authored andcommitted
Add more math functions to templates (home-assistant#5186)
Document usage of `sin`, `cos`, `tan`, and `sqrt`, and the `e`, `pi`, and `tau` constants.
1 parent 36a385b commit ce53c0e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

source/_docs/configuration/templating.markdown

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ Home Assistant adds extensions to allow templates to access all of the current s
8080
- `float` will format the output as float.
8181
- `strptime(string, format)` will parse a string to a datetime based on a [format][strp-format].
8282
- `log(value, base)` will take the logarithm of the input. When the base is omitted, it defaults to `e` - the natural logarithm. Can also be used as a filter.
83+
- `sin(value)` will return the sine of the input. Can be used as a filter.
84+
- `cos(value)` will return the cosine of the input. Can be used as a filter.
85+
- `tan(value)` will return the tangent of the input. Can be used as a filter.
86+
- `sqrt(value)` will return the square root of the input. Can be used as a filter.
87+
- `e` mathematical constant, approximately 2.71828.
88+
- `pi` mathematical constant, approximately 3.14159.
89+
- `tau` mathematical constant, approximately 6.28318.
8390
- Filter `round(x)` will convert the input to a number and round it to `x` decimals.
8491
- Filter `timestamp_local` will convert an UNIX timestamp to local time/data.
8592
- Filter `timestamp_utc` will convert an UNIX timestamp to UTC time/data.
@@ -274,6 +281,10 @@ The following overview contains a couple of options to get the needed values:
274281
{% raw %}{{ float(value_json) * (2**10) }}{% endraw %}
275282
{% raw %}{{ value_json | log }}{% endraw %}
276283
{% raw %}{{ log(1000, 10) }}{% endraw %}
284+
{% raw %}{{ sin(pi / 2) }}{% endraw %}
285+
{% raw %}{{ cos(tau) }}{% endraw %}
286+
{% raw %}{{ tan(pi) }}{% endraw %}
287+
{% raw %}{{ sqrt(e) }}{% endraw %}
277288
278289
# Timestamps
279290
{% raw %}{{ value_json.tst | timestamp_local }}{% endraw %}

0 commit comments

Comments
 (0)