mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-10 02:46:53 +00:00
Add more math functions to templates (#5186)
Document usage of `sin`, `cos`, `tan`, and `sqrt`, and the `e`, `pi`, and `tau` constants.
This commit is contained in:
parent
36a385b5b7
commit
ce53c0e9f0
@ -80,6 +80,13 @@ Home Assistant adds extensions to allow templates to access all of the current s
|
||||
- `float` will format the output as float.
|
||||
- `strptime(string, format)` will parse a string to a datetime based on a [format][strp-format].
|
||||
- `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.
|
||||
- `sin(value)` will return the sine of the input. Can be used as a filter.
|
||||
- `cos(value)` will return the cosine of the input. Can be used as a filter.
|
||||
- `tan(value)` will return the tangent of the input. Can be used as a filter.
|
||||
- `sqrt(value)` will return the square root of the input. Can be used as a filter.
|
||||
- `e` mathematical constant, approximately 2.71828.
|
||||
- `pi` mathematical constant, approximately 3.14159.
|
||||
- `tau` mathematical constant, approximately 6.28318.
|
||||
- Filter `round(x)` will convert the input to a number and round it to `x` decimals.
|
||||
- Filter `timestamp_local` will convert an UNIX timestamp to local time/data.
|
||||
- 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:
|
||||
{% raw %}{{ float(value_json) * (2**10) }}{% endraw %}
|
||||
{% raw %}{{ value_json | log }}{% endraw %}
|
||||
{% raw %}{{ log(1000, 10) }}{% endraw %}
|
||||
{% raw %}{{ sin(pi / 2) }}{% endraw %}
|
||||
{% raw %}{{ cos(tau) }}{% endraw %}
|
||||
{% raw %}{{ tan(pi) }}{% endraw %}
|
||||
{% raw %}{{ sqrt(e) }}{% endraw %}
|
||||
|
||||
# Timestamps
|
||||
{% raw %}{{ value_json.tst | timestamp_local }}{% endraw %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user