Add template as_timedelta (#22740)

This commit is contained in:
Kevin Stillhammer 2022-05-23 19:33:49 +02:00 committed by GitHub
parent 5646666ce6
commit 479413cc5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -424,6 +424,17 @@ For example, if you wanted to select a field from `trigger` in an automation bas
{% endraw %}
- `as_timedelta(string)` converts a string to a timedelta object. Expects data in the format `DD HH:MM:SS.uuuuuu`, `DD HH:MM:SS,uuuuuu`, or as specified by ISO 8601 (e.g. `P4DT1H15M20S` which is equivalent to `4 1:15:20`) or PostgreSQLs day-time interval format (e.g. `3 days 04:05:06`) This function can also be used as a filter.
{% raw %}
```yaml
# Renders to "00:10:00"
{{ as_timedelta("PT10M") }}
```
{% endraw %}
- Filter `timestamp_local(default)` converts a UNIX timestamp to the ISO format string representation as date/time in your local timezone. If that fails, returns the `default` value, or if omitted the unprocessed input value. If a custom string format is needed in the string, use `timestamp_custom` instead.
- Filter `timestamp_utc(default)` converts a UNIX timestamp to the ISO format string representation representation as date/time in UTC timezone. If that fails, returns the `default` value, or if omitted the unprocessed input value. If a custom string format is needed in the string, use `timestamp_custom` instead.
- Filter `timestamp_custom(format_string, local=True, default)` converts an UNIX timestamp to its string representation based on a custom format, the use of a local timezone is default. If that fails, returns the `default` value, or if omitted the unprocessed input value. Supports the standard [Python time formatting options](https://docs.python.org/3/library/time.html#time.strftime).