From 2b6869c188c323d15272ba65566a7981d29deff9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 3 Sep 2020 14:35:28 -0500 Subject: [PATCH] Add support for as_local as a global and a filter (#14387) --- source/_docs/configuration/templating.markdown | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/_docs/configuration/templating.markdown b/source/_docs/configuration/templating.markdown index 21cdc5c0b18..1f7a603eea8 100644 --- a/source/_docs/configuration/templating.markdown +++ b/source/_docs/configuration/templating.markdown @@ -108,7 +108,12 @@ Other state examples: {{ as_timestamp(states.binary_sensor.garage_door.last_changed) }} +{{ as_local(states.binary_sensor.garage_door.last_changed) }} + {{ as_timestamp(now()) - as_timestamp(states.binary_sensor.garage_door.last_changed) }} + +{{ as_local(states.sensor.time.last_changed) }} + ``` {% endraw %} @@ -174,6 +179,7 @@ The same thing can also be expressed as a filter: - `utcnow()` returns a datetime object of the current time in the UTC timezone. - For specific values: `utcnow().second`, `utcnow().minute`, `utcnow().hour`, `utcnow().day`, `utcnow().month`, `utcnow().year`, `utcnow().weekday()` and `utcnow().isoweekday()`. - `as_timestamp()` converts datetime object or string to UNIX timestamp. This function also be used as a filter. +- `as_local()` converts datetime object to local time. This function also be used as a filter. - `strptime(string, format)` parses a string based on a [format](https://docs.python.org/3.8/library/datetime.html#strftime-and-strptime-behavior) and returns a datetime object. - `relative_time` converts datetime object to its human-friendly "age" string. The age can be in second, minute, hour, day, month or year (but only the biggest unit is considered, e.g., if it's 2 days and 3 hours, "2 days" will be returned). Note that it only works for dates _in the past_. - Filter `timestamp_local` converts an UNIX timestamp to its string representation as date/time in your local timezone.