From 479413cc5fbc2e901a96486026c6b0904b08ed3b Mon Sep 17 00:00:00 2001 From: Kevin Stillhammer Date: Mon, 23 May 2022 19:33:49 +0200 Subject: [PATCH] Add template as_timedelta (#22740) --- source/_docs/configuration/templating.markdown | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/_docs/configuration/templating.markdown b/source/_docs/configuration/templating.markdown index c8c15ef65b6..f599c633431 100644 --- a/source/_docs/configuration/templating.markdown +++ b/source/_docs/configuration/templating.markdown @@ -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 PostgreSQL’s 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).