ha-nunjucks 1.7.5 → 1.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +270 -270
  2. package/dist/index.js +3 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  [![Github][github]][github]
9
9
 
10
- A wrapper for [nunjucks](https://www.npmjs.com/package/nunjucks) for use with Home Assistant frontend custom components to render [templates](https://www.home-assistant.io/docs/configuration/templating/) instanteneously at HTML render time. This repository offers a fast and easy way for developers to add templating support to Home Assistant custom cards.
10
+ A wrapper for [nunjucks](https://www.npmjs.com/package/nunjucks) for use with Home Assistant frontend custom components to render [templates](https://www.home-assistant.io/docs/templating/) instanteneously at HTML render time. This repository offers a fast and easy way for developers to add templating support to Home Assistant custom cards.
11
11
 
12
12
  ## What is nunjucks?
13
13
 
@@ -149,7 +149,7 @@ ha-nunjucks creates one global object on the browser window, which contains an n
149
149
 
150
150
  ## Available Extensions
151
151
 
152
- All of the [Home Assistant template extensions](https://www.home-assistant.io/docs/configuration/templating/#home-assistant-template-extensions) have been implemented into this package. If there are newer functions that you use that are not currently supported or behave unexpectedly, please make a feature request or try adding it to the project yourself and create a pull request. Do note that some template extensions behave differently from their Home Assistant backend jinja2 counterparts due to differences between Python and JavaScript and language feature constraints.
152
+ All of the [Home Assistant template functions](https://www.home-assistant.io/template-functions/) have been implemented into this package. If there are newer functions that you use that are not currently supported or behave unexpectedly, please make a feature request or try adding it to the project yourself and create a pull request. Do note that some template extensions behave differently from their Home Assistant backend jinja2 counterparts due to differences between Python and JavaScript and language feature constraints.
153
153
 
154
154
  Template extensions can be functions, tests, filters, and/or constants. Functions are called like a regular programming function, such as `states()` or `floors()`. Filters are added to the end of a string using a pipe character like `123.45 | int` or `"light.lounge" | state_attr("brightness")`. Tests are functions which return booleans and can be used in an if statement like `if "foo" is string_like`, not to be confused with functions that return booleans and can be used in if statements like `if is_state("light.lounge", "on")`. Contants are static values, and are just called as is like `{{ True }}` or `{{ pi }}`.
155
155
 
@@ -173,7 +173,7 @@ Because entity IDs contain periods in them, you cannot use dot notation when acc
173
173
 
174
174
  `{{ hass.states["light.sunroom_ceiling"].state }}`
175
175
 
176
- For convenience, the `hass.states` object is rebuilt as a separate object that can be accessed with dot notation. Because of JavaScript limitations not allowing for functions and object to share the same name, it has been named `_states`.
176
+ For convenience, the `hass.states` object is rebuilt as a separate object that can be accessed with dot notation. Because of JavaScript limitations not allowing for functions and object to share the same name, it has been named `_states`. Note that this object is only rebuilt as needed and can cause a performance hit. It is preferable to use `hass.states` or a template function instead.
177
177
 
178
178
  `{{ _states.light.sunroom_ceiling.state }}`
179
179
 
@@ -181,121 +181,121 @@ You do have to use bracket notation for arrays within state objects.
181
181
 
182
182
  `{{ _states.light.sunroom_ceiling.attributes.supported_color_modes[0] }}`
183
183
 
184
- ### [States](https://www.home-assistant.io/docs/configuration/templating/#states)
184
+ ### States
185
185
 
186
186
  Functions used to determine an entity's state or an attribute.
187
187
 
188
- | Name | Type | Arguments | Description |
189
- | ------------- | ---------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
190
- | states | function, filter | entity_id, rounded (default false), with_unit (default false) | Returns the state string of the given entity. Optionally round numerical states and append the unit of measurement. |
191
- | is_state | function | entity_id, value | Compares an entity's state with a specified state or list of states and returns `true` or `false`. |
192
- | state_attr | function, filter | entity_id, attribute | Returns the value of the attribute or `undefined` if it doesn't exist. |
193
- | is_state_attr | function | entity_id, attribute, value | Tests if the given entity attribute is the specified value. |
194
- | has_value | function, filter | entity_id | Tests if the given entity is not unknown or unavailable. |
188
+ | Name | Type | Arguments | Description |
189
+ | -------------------------------------------------------------------------------- | ---------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
190
+ | [states](https://www.home-assistant.io/template-functions/states/) | function, filter | entity_id, rounded (default false), with_unit (default false) | Returns the state string of the given entity. Optionally round numerical states and append the unit of measurement. |
191
+ | [is_state](https://www.home-assistant.io/template-functions/is_state/) | function | entity_id, value | Compares an entity's state with a specified state or list of states and returns `true` or `false`. |
192
+ | [state_attr](https://www.home-assistant.io/template-functions/state_attr/) | function, filter | entity_id, attribute | Returns the value of the attribute or `undefined` if it doesn't exist. |
193
+ | [is_state_attr](https://www.home-assistant.io/template-functions/is_state_attr/) | function | entity_id, attribute, value | Tests if the given entity attribute is the specified value. |
194
+ | [has_value](https://www.home-assistant.io/template-functions/has_value/) | function, filter | entity_id | Tests if the given entity is not unknown or unavailable. |
195
195
 
196
- ### [State Translated](https://www.home-assistant.io/docs/configuration/templating/#state-translated)
196
+ ### State Translated
197
197
 
198
- | Name | Type | Arguments | Description |
199
- | --------------------- | ---------------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
200
- | state_translated | function, filter | entity_id, state (optional) | Returns the formatted and translated state of an entity or provided state using a language that is currently configured in the general settings. |
201
- | attr_name_translated | function, filter | entity_id, attr_name | Returns the formatted and translated attribute name of an entity using a language that is currently configured in the general settings. |
202
- | attr_value_translated | function, filter | entity_id, attr_name, attr_value (optional) | Returns the formatted and translated attribute value of an entity or provided attribute value using a language that is currently configured in the general settings. |
203
- | number_translated | function, filter | value | Returns the formatted and translated input number using a language that is currently configured in the general settings. |
204
- | date_translated | function, filter | value | Returns the formatted and translated input date or datetime as a date using a language that is currently configured in the general settings. |
205
- | time_translated | function, filter | value | Returns the formatted and translated input time or datetime as a time using a language that is currently configured in the general settings. |
206
- | datetime_translated | function, filter | value | Returns the formatted and translated input datetime using a language that is currently configured in the general settings. |
198
+ | Name | Type | Arguments | Description |
199
+ | -------------------------------------------------------------------------------------- | ---------------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
200
+ | [state_translated](https://www.home-assistant.io/template-functions/state_translated/) | function, filter | entity_id, state (optional) | Returns the formatted and translated state of an entity or provided state using a language that is currently configured in the general settings. |
201
+ | attr_name_translated | function, filter | entity_id, attr_name | Returns the formatted and translated attribute name of an entity using a language that is currently configured in the general settings. |
202
+ | attr_value_translated | function, filter | entity_id, attr_name, attr_value (optional) | Returns the formatted and translated attribute value of an entity or provided attribute value using a language that is currently configured in the general settings. |
203
+ | number_translated | function, filter | value | Returns the formatted and translated input number using a language that is currently configured in the general settings. |
204
+ | date_translated | function, filter | value | Returns the formatted and translated input date or datetime as a date using a language that is currently configured in the general settings. |
205
+ | time_translated | function, filter | value | Returns the formatted and translated input time or datetime as a time using a language that is currently configured in the general settings. |
206
+ | datetime_translated | function, filter | value | Returns the formatted and translated input datetime using a language that is currently configured in the general settings. |
207
207
 
208
- ### [Groups](https://www.home-assistant.io/docs/configuration/templating/#working-with-groups)
208
+ ### Groups
209
209
 
210
- | Name | Type | Arguments | Description |
211
- | ------ | ---------------- | --------- | ------------------------------------------------------------------------------------------------- |
212
- | expand | function, filter | args | Retrieve state objects for provided entities and sort. Expands group entities into their members. |
210
+ | Name | Type | Arguments | Description |
211
+ | ------------------------------------------------------------------ | ---------------- | --------- | ------------------------------------------------------------------------------------------------- |
212
+ | [expand](https://www.home-assistant.io/template-functions/expand/) | function, filter | args | Retrieve state objects for provided entities and sort. Expands group entities into their members. |
213
213
 
214
- ### [Entities](https://www.home-assistant.io/docs/configuration/templating/#entities)
214
+ ### Entities
215
215
 
216
- | Name | Type | Arguments | Description |
217
- | ---------------- | -------- | --------- | ------------------------------------------ |
218
- | is_hidden_entity | function | entity_id | Returns whether an entity has been hidden. |
216
+ | Name | Type | Arguments | Description |
217
+ | -------------------------------------------------------------------------------------- | -------- | --------- | ------------------------------------------ |
218
+ | [is_hidden_entity](https://www.home-assistant.io/template-functions/is_hidden_entity/) | function | entity_id | Returns whether an entity has been hidden. |
219
219
 
220
- ### [Devices](https://www.home-assistant.io/docs/configuration/templating/#devices)
220
+ ### Devices
221
221
 
222
- | Name | Type | Arguments | Description |
223
- | --------------- | ---------------- | ------------------------------------------ | -------------------------------------------------------------------------------------------- |
224
- | device_entities | function, filter | device_id | Returns a list of entities that are associated with a given device ID. |
225
- | device_attr | function, filter | device_or_entity_id, attr_name | Returns the value of attr_name for the given device or entity ID. |
226
- | is_device_attr | function | device_or_entity_id, attr_name, attr_value | Returns whether the value of attr_name for the given device or entity ID matches attr_value. |
227
- | device_id | function, filter | entity_id | Returns the device ID for a given entity ID or device name. |
228
- | device_name | function, filter | device_or_entity_id | Returns the device name as defined by user or default for a give entity or device ID. |
222
+ | Name | Type | Arguments | Description |
223
+ | ------------------------------------------------------------------------------------ | ---------------- | ------------------------------------------ | -------------------------------------------------------------------------------------------- |
224
+ | [device_entities](https://www.home-assistant.io/template-functions/device_entities/) | function, filter | device_id | Returns a list of entities that are associated with a given device ID. |
225
+ | [device_attr](https://www.home-assistant.io/template-functions/device_attr/) | function, filter | device_or_entity_id, attr_name | Returns the value of attr_name for the given device or entity ID. |
226
+ | [is_device_attr](https://www.home-assistant.io/template-functions/is_device_attr/) | function | device_or_entity_id, attr_name, attr_value | Returns whether the value of attr_name for the given device or entity ID matches attr_value. |
227
+ | [device_id](https://www.home-assistant.io/template-functions/device_id/) | function, filter | entity_id | Returns the device ID for a given entity ID or device name. |
228
+ | [device_name](https://www.home-assistant.io/template-functions/device_name/) | function, filter | device_or_entity_id | Returns the device name as defined by user or default for a give entity or device ID. |
229
229
 
230
- ### [Config Entries](https://www.home-assistant.io/docs/configuration/templating/#config-entries)
230
+ ### Config Entries
231
231
 
232
232
  **NOTE**: Relies on async request on initial page load. May return nothing on first render.
233
233
 
234
- | Name | Type | Arguments | Description |
235
- | ----------------- | ---------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
236
- | config_entry_id | function, filter | entity_id | Returns the config entry ID for a given entity ID. |
237
- | config_entry_attr | function, filter | config_entry_id, attr | Returns the value of `attr` for the config entry of the given entity ID. The following attributes are allowed: `domain`, `title`, `state`, `source`, `disabled_by`. |
234
+ | Name | Type | Arguments | Description |
235
+ | ---------------------------------------------------------------------------------------- | ---------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
236
+ | [config_entry_id](https://www.home-assistant.io/template-functions/config_entry_id/) | function, filter | entity_id | Returns the config entry ID for a given entity ID. |
237
+ | [config_entry_attr](https://www.home-assistant.io/template-functions/config_entry_attr/) | function, filter | config_entry_id, attr | Returns the value of `attr` for the config entry of the given entity ID. The following attributes are allowed: `domain`, `title`, `state`, `source`, `disabled_by`. |
238
238
 
239
- ### [Floors](https://www.home-assistant.io/docs/configuration/templating/#floors)
239
+ ### Floors
240
240
 
241
- | Name | Type | Arguments | Description |
242
- | -------------- | ---------------- | ---------------- | ----------------------------------------------------------------------------------------------------------- |
243
- | floors | function | | Returns the full list of floor IDs that include an area. |
244
- | floor_id | function, filter | lookup_value | Returns the floor ID for a given floor name or alias, device ID, entity ID, area ID, or area name or alias. |
245
- | floor_name | function, filter | lookup_value | Returns the floor name for a given device ID, entity ID, area ID, area name, or floor ID. |
246
- | floor_areas | function, filter | floor_name_or_id | Returns the list of area IDs tied to a given floor ID or name. |
247
- | floor_entities | function, filter | floor_name_or_id | Returns the list of entity IDs tied to a given floor ID or name. |
241
+ | Name | Type | Arguments | Description |
242
+ | ---------------------------------------------------------------------------------- | ---------------- | ---------------- | ----------------------------------------------------------------------------------------------------------- |
243
+ | [floors](https://www.home-assistant.io/template-functions/floors/) | function | | Returns the full list of floor IDs that include an area. |
244
+ | [floor_id](https://www.home-assistant.io/template-functions/floor_id/) | function, filter | lookup_value | Returns the floor ID for a given floor name or alias, device ID, entity ID, area ID, or area name or alias. |
245
+ | [floor_name](https://www.home-assistant.io/template-functions/floor_name/) | function, filter | lookup_value | Returns the floor name for a given device ID, entity ID, area ID, area name, or floor ID. |
246
+ | [floor_areas](https://www.home-assistant.io/template-functions/floor_areas/) | function, filter | floor_name_or_id | Returns the list of area IDs tied to a given floor ID or name. |
247
+ | [floor_entities](https://www.home-assistant.io/template-functions/floor_entities/) | function, filter | floor_name_or_id | Returns the list of entity IDs tied to a given floor ID or name. |
248
248
 
249
- ### [Areas](https://www.home-assistant.io/docs/configuration/templating/#areas)
249
+ ### Areas
250
250
 
251
- | Name | Type | Arguments | Description |
252
- | ------------- | ---------------- | --------------- | ------------------------------------------------------------------- |
253
- | areas | function | | Returns the full list of area IDs. |
254
- | area_id | function, filter | lookup_value | Returns the area ID for a given device ID, entity ID, or area name. |
255
- | area_name | function, filter | lookup_value | Returns the area name for a given device ID, entity ID, or area ID. |
256
- | area_entities | function, filter | area_name_or_id | Returns the list of entity IDs tied to a given area ID or name. |
257
- | area_devices | function, filter | area_name_or_id | Returns the list of device IDs tied to a given area ID or name. |
251
+ | Name | Type | Arguments | Description |
252
+ | -------------------------------------------------------------------------------- | ---------------- | --------------- | ------------------------------------------------------------------- |
253
+ | [areas](https://www.home-assistant.io/template-functions/areas/) | function | | Returns the full list of area IDs. |
254
+ | [area_id](https://www.home-assistant.io/template-functions/area_id/) | function, filter | lookup_value | Returns the area ID for a given device ID, entity ID, or area name. |
255
+ | [area_name](https://www.home-assistant.io/template-functions/area_name/) | function, filter | lookup_value | Returns the area name for a given device ID, entity ID, or area ID. |
256
+ | [area_entities](https://www.home-assistant.io/template-functions/area_entities/) | function, filter | area_name_or_id | Returns the list of entity IDs tied to a given area ID or name. |
257
+ | [area_devices](https://www.home-assistant.io/template-functions/area_devices/) | function, filter | area_name_or_id | Returns the list of device IDs tied to a given area ID or name. |
258
258
 
259
- ### [Entities For An Integration](https://www.home-assistant.io/docs/configuration/templating/#entities-for-an-integration)
259
+ ### Entities For An Integration
260
260
 
261
261
  **NOTE**: Relies on async request on initial page load. May return nothing on first render.
262
262
 
263
- | Name | Type | Arguments | Description |
264
- | -------------------- | -------- | --------------------------------- | ---------------------------------------------------------------------------------------------- |
265
- | integration_entities | function | integration_or_config_entry_title | Returns a list of entities that are associated with a given integration or config entry title. |
263
+ | Name | Type | Arguments | Description |
264
+ | ---------------------------------------------------------------------------------------------- | -------- | --------------------------------- | ---------------------------------------------------------------------------------------------- |
265
+ | [integration_entities](https://www.home-assistant.io/template-functions/integration_entities/) | function | integration_or_config_entry_title | Returns a list of entities that are associated with a given integration or config entry title. |
266
266
 
267
- ### [Labels](https://www.home-assistant.io/docs/configuration/templating/#labels)
267
+ ### Labels
268
268
 
269
269
  **NOTE**: Relies on async request on initial page load. May return nothing on first render.
270
270
 
271
- | Name | Type | Arguments | Description |
272
- | ----------------- | ---------------- | ----------------------- | ------------------------------------------------------------------------------------------ |
273
- | labels | function, filter | lookup_value (optional) | Returns the full list of label IDs, or those for a given area ID, device ID, or entity ID. |
274
- | label_id | function, filter | lookup_value | Returns the label ID for a given label name. |
275
- | label_name | function, filter | lookup_value | Returns the label name for a given label ID. |
276
- | label_description | function, filter | lookup_value | Returns the label description for a given label ID. |
277
- | label_areas | function, filter | label_name_or_id | Returns the list of area IDs tied to a given label ID or name. |
278
- | label_devices | function, filter | label_name_or_id | Returns the list of device IDs tied to a given label ID or name. |
279
- | label_entities | function, filter | label_name_or_id | Returns the list of entity IDs tied to a given label ID or name. |
271
+ | Name | Type | Arguments | Description |
272
+ | ---------------------------------------------------------------------------------------- | ---------------- | ----------------------- | ------------------------------------------------------------------------------------------ |
273
+ | [labels](https://www.home-assistant.io/template-functions/labels/) | function, filter | lookup_value (optional) | Returns the full list of label IDs, or those for a given area ID, device ID, or entity ID. |
274
+ | [label_id](https://www.home-assistant.io/template-functions/label_id/) | function, filter | lookup_value | Returns the label ID for a given label name. |
275
+ | [label_name](https://www.home-assistant.io/template-functions/label_name/) | function, filter | lookup_value | Returns the label name for a given label ID. |
276
+ | [label_description](https://www.home-assistant.io/template-functions/label_description/) | function, filter | lookup_value | Returns the label description for a given label ID. |
277
+ | [label_areas](https://www.home-assistant.io/template-functions/label_areas/) | function, filter | label_name_or_id | Returns the list of area IDs tied to a given label ID or name. |
278
+ | [label_devices](https://www.home-assistant.io/template-functions/label_devices/) | function, filter | label_name_or_id | Returns the list of device IDs tied to a given label ID or name. |
279
+ | [label_entities](https://www.home-assistant.io/template-functions/label_entities/) | function, filter | label_name_or_id | Returns the list of entity IDs tied to a given label ID or name. |
280
280
 
281
- ### [Issues](https://www.home-assistant.io/docs/configuration/templating/#issues)
281
+ ### Issues
282
282
 
283
283
  **NOTE**: Relies on async request on initial page load. May return nothing on first render.
284
284
 
285
- | Name | Type | Arguments | Description |
286
- | ------ | -------- | ---------------- | -------------------------------------------------------------------------------------- |
287
- | issues | function | | Returns all open issues as a mapping of `domain,issue_id` strings to the issue object. |
288
- | issue | function | domain, issue_id | Returns an issue object. |
285
+ | Name | Type | Arguments | Description |
286
+ | ------------------------------------------------------------------ | -------- | ---------------- | -------------------------------------------------------------------------------------- |
287
+ | [issues](https://www.home-assistant.io/template-functions/issues/) | function | | Returns all open issues as a mapping of `domain,issue_id` strings to the issue object. |
288
+ | [issue](https://www.home-assistant.io/template-functions/issue/) | function | domain, issue_id | Returns an issue object. |
289
289
 
290
- ### [Immediate If](https://www.home-assistant.io/docs/configuration/templating/#immediate-if-iif)
290
+ ### Immediate If
291
291
 
292
292
  A shorthand for an if else statement.
293
293
 
294
- | Name | Type | Arguments | Description |
295
- | ---- | ---------------- | ---------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
296
- | iif | function, filter | condition, if_true (optional), if_false (optional), if_none (optional) | Immediate if. Returns the value of `if_true` if the condition is true, the value of `if_false` if it's false, and the value of `if_none` if it's `undefined`, `null`, or an empty string. All arguments except `condition` are optional. Cannot be used as a filter. |
294
+ | Name | Type | Arguments | Description |
295
+ | ------------------------------------------------------------ | ---------------- | ---------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
296
+ | [iif](https://www.home-assistant.io/template-functions/iif/) | function, filter | condition, if_true (optional), if_false (optional), if_none (optional) | Immediate if. Returns the value of `if_true` if the condition is true, the value of `if_false` if it's false, and the value of `if_none` if it's `undefined`, `null`, or an empty string. All arguments except `condition` are optional. Cannot be used as a filter. |
297
297
 
298
- ### [Time](https://www.home-assistant.io/docs/configuration/templating/#time)
298
+ ### Time
299
299
 
300
300
  **NOTE**:
301
301
 
@@ -303,22 +303,22 @@ A shorthand for an if else statement.
303
303
  - JS Date is not as good at handling timezones as Python datetime. Be careful about timezone differences! You can try to account for this using the `utc` flags and/or by including a timezone offset in a datetime string to parse using `as_datetime` or `strptime`.
304
304
  - Including time extensions in your templates does not cause them to refresh more regularly by themselves, although they will still update whenever the `hass` object does. If you are a developer, you have to implement this behavior yourself in your custom cards.
305
305
 
306
- | Name | Type | Arguments | Description |
307
- | ---------------- | ---------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
308
- | now | function | | Returns a datetime object that represents the current time in your time zone. |
309
- | utcnow | function | | Returns a datetime object of the current time in the UTC timezone. |
310
- | today_at | function, filter | value | Converts a string containing a military time format to a datetime object with today’s date in your time zone. Defaults to midnight (00:00). |
311
- | as_datetime | function, filter | value, fallback (optional), utc (default true) | Converts a string containing a timestamp, or valid UNIX timestamp, to a datetime object. If that fails, it returns the fallback value or, if omitted, raises an error. When the input is already a datetime object it will be returned as is. in case the input is a datetime.date object, midnight will be added as time. |
312
- | as_timestamp | function, filter | value, fallback (optional) | Converts a datetime object or string to UNIX timestamp. If that fails, returns the fallback value, or if omitted raises an error. |
313
- | as_local | function, filter | value | Converts a datetime object to local time. |
314
- | strptime | function | value, format, fallback (optional), utc (default false) | Parses a string based on a [format](https://d3js.org/d3-time-format#locale_format) and returns a datetime object. If that fails, it returns the default value or, if omitted, raises an error. |
315
- | relative_time | function, filter | value | Returns a human readable string indicating the differenceb between now and an input past datetime object. Only uses the largest unit (years, months, days, hours, minutes, seconds) rounded. |
316
- | time_since | function, filter | value, precision (default 1) | Returns a human readable string indicating the difference between now and an input past datetime object. `precision` indicates how many units (years, months, days, hours, minutes, seconds) to use, with the last unit being rounded and 0 being the same as 6. If the input datetime is in the future it returns the input. If the input datetime is not a datetime object it returns nothing. |
317
- | time_until | function, filter | value, precision (default 1) | Returns a human readable string indicating the difference between now and an input future datetime object. `precision` indicates how many units (years, months, days, hours, minutes, seconds) to use, with the last unit being rounded and 0 being the same as 6. If the input datetime is in the past it returns the input. If the input datetime is not a datetime object it returns nothing. |
318
- | as_timedelta | function, filter | value | 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`). |
319
- | timestamp_local | filter | value, fallback (optional) | Converts a UNIX timestamp to the ISO format string representation as date/time in your local timezone. If that fails, returns the `fallback` value, or if omitted raises an error. |
320
- | timestamp_utc | filter | value, fallback (optional) | Converts a UNIX timestamp to the ISO format string representation as date/time in UTC timezone. If that fails, returns the `fallback` value, or if omitted raises an error. |
321
- | timestamp_custom | filter | value, format, local (default true), fallback (optional) | Converts a UNIX timestamp to its string representation based on a custom format. Uses the local timezone by default. If that fails, returns the `fallback` value, or if omitted raises an error. |
306
+ | Name | Type | Arguments | Description |
307
+ | -------------------------------------------------------------------------------------- | ---------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
308
+ | [now](https://www.home-assistant.io/template-functions/now/) | function | | Returns a datetime object that represents the current time in your time zone. |
309
+ | [utcnow](https://www.home-assistant.io/template-functions/utcnow/) | function | | Returns a datetime object of the current time in the UTC timezone. |
310
+ | [today_at](https://www.home-assistant.io/template-functions/today_at/) | function, filter | value | Converts a string containing a military time format to a datetime object with today’s date in your time zone. Defaults to midnight (00:00). |
311
+ | [as_datetime](https://www.home-assistant.io/template-functions/as_datetime/) | function, filter | value, fallback (optional), utc (default true) | Converts a string containing a timestamp, or valid UNIX timestamp, to a datetime object. If that fails, it returns the fallback value or, if omitted, raises an error. When the input is already a datetime object it will be returned as is. in case the input is a datetime.date object, midnight will be added as time. |
312
+ | [as_timestamp](https://www.home-assistant.io/template-functions/as_timestamp/) | function, filter | value, fallback (optional) | Converts a datetime object or string to UNIX timestamp. If that fails, returns the fallback value, or if omitted raises an error. |
313
+ | [as_local](https://www.home-assistant.io/template-functions/as_local/) | function, filter | value | Converts a datetime object to local time. |
314
+ | [strptime](https://www.home-assistant.io/template-functions/strptime/) | function | value, format, fallback (optional), utc (default false) | Parses a string based on a [format](https://d3js.org/d3-time-format#locale_format) and returns a datetime object. If that fails, it returns the default value or, if omitted, raises an error. |
315
+ | [relative_time](https://www.home-assistant.io/template-functions/relative_time/) | function, filter | value | Returns a human readable string indicating the differenceb between now and an input past datetime object. Only uses the largest unit (years, months, days, hours, minutes, seconds) rounded. |
316
+ | [time_since](https://www.home-assistant.io/template-functions/time_since/) | function, filter | value, precision (default 1) | Returns a human readable string indicating the difference between now and an input past datetime object. `precision` indicates how many units (years, months, days, hours, minutes, seconds) to use, with the last unit being rounded and 0 being the same as 6. If the input datetime is in the future it returns the input. If the input datetime is not a datetime object it returns nothing. |
317
+ | [time_until](https://www.home-assistant.io/template-functions/time_until/) | function, filter | value, precision (default 1) | Returns a human readable string indicating the difference between now and an input future datetime object. `precision` indicates how many units (years, months, days, hours, minutes, seconds) to use, with the last unit being rounded and 0 being the same as 6. If the input datetime is in the past it returns the input. If the input datetime is not a datetime object it returns nothing. |
318
+ | [as_timedelta](https://www.home-assistant.io/template-functions/as_timedelta/) | function, filter | value | 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`). |
319
+ | [timestamp_local](https://www.home-assistant.io/template-functions/timestamp_local/) | filter | value, fallback (optional) | Converts a UNIX timestamp to the ISO format string representation as date/time in your local timezone. If that fails, returns the `fallback` value, or if omitted raises an error. |
320
+ | [timestamp_utc](https://www.home-assistant.io/template-functions/timestamp_utc/) | filter | value, fallback (optional) | Converts a UNIX timestamp to the ISO format string representation as date/time in UTC timezone. If that fails, returns the `fallback` value, or if omitted raises an error. |
321
+ | [timestamp_custom](https://www.home-assistant.io/template-functions/timestamp_custom/) | filter | value, format, local (default true), fallback (optional) | Converts a UNIX timestamp to its string representation based on a custom format. Uses the local timezone by default. If that fails, returns the `fallback` value, or if omitted raises an error. |
322
322
 
323
323
  In addition to these functions, you have access to [a datetime library](https://github.com/Nerwyn/ts-py-datetime) which emulates the Python datetime module in TypeScript. You can instantiate `date`, `time`, `datetime`, and `timedelta` objects using the `dt` object. You can then access it's class methods using these objects. To use the static method and constants of these classes, you can reference them directly without prefixing them with `dt`. See the README in the datetime repository linked above for more information on how to use it.
324
324
 
@@ -334,201 +334,201 @@ In addition to these functions, you have access to [a datetime library](https://
334
334
  | time | class | | The time class, which has static methods which can be called upon. |
335
335
  | timedelta | class | | The timedelta class, which has static methods which can be called upon. |
336
336
 
337
- ### [To/From JSON](https://www.home-assistant.io/docs/configuration/templating/#tofrom-json)
338
-
339
- | Name | Type | Arguments | Description |
340
- | --------- | ------ | ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
341
- | to_json | filter | obj, ensure_ascii, pretty_print, sort_keys | Turn an object into a JSON string. `ensure_ascii` converts unicode characters into escape sequences. `pretty_print` formats the output with new lines and an indent of two spaces. `sort_keys` sorts the keys of the JSON object. |
342
- | from_json | filter | value | Parse a string as JSON. |
343
-
344
- ### [Is Defined](https://www.home-assistant.io/docs/configuration/templating/#is-defined)
345
-
346
- | Name | Type | Arguments | Description |
347
- | ---------- | ------ | --------- | -------------------------------------------------------------- |
348
- | is_defined | filter | value | Returns the value if it is defined, otherwise throws an error. |
349
-
350
- ### [Version](https://www.home-assistant.io/docs/configuration/templating/#version)
351
-
352
- | Name | Type | Arguments | Description |
353
- | ------- | ---------------- | --------- | --------------------------------- |
354
- | version | function, filter | version | Returns a SemanticVersion object. |
355
-
356
- ### [Distance](https://www.home-assistant.io/docs/configuration/templating/#distance)
357
-
358
- | Name | Type | Arguments | Description |
359
- | -------- | ---------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
360
- | distance | function | args | Measures the distance between home, an entity, or coordinates. The unit of measurement (kilometers or miles) depends on the system’s configuration settings. |
361
- | closest | function, filter | args | Finds the closest entity to home, or the first entity or coordinate if multiple provided. Arguments can be entity IDs, domains, entity state objects, coordinate pairs, or arrays. |
362
-
363
- ### [Contains](https://www.home-assistant.io/docs/configuration/templating/#contains)
364
-
365
- | Name | Type | Arguments | Description |
366
- | -------- | ------------ | ----------- | ----------------------------------- |
367
- | contains | filter, test | list, value | Returns if an element is in a list. |
368
-
369
- ### [Numeric](https://www.home-assistant.io/docs/configuration/templating/#numeric-functions-and-filters)
370
-
371
- | Name | Type | Arguments | Description |
372
- | ---------------- | ---------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
373
- | float | function, filter | value, fallback (optional) | Converts a value to a float. If that fails, it returns the fallback value or, if omitted, raises an error. |
374
- | is_number | function, filter | value | Returns true if a value can be parsed as a number. |
375
- | int | function, filter | value, fallback (optional) | Converts a value to an integer. If that fails, it returns the fallback value or, if omitted, raises an error. |
376
- | bool | function, filter | value, fallback (optional ) | Converts a value to a boolean based on the human readable truthiness of it, case insensitive. Non-zero integers, `true`, `yes`, `on`, `enable`, and `1` return true. 0, `false`, `no`, `off`, `disable` and `0` return false. If the value's human readable truthiness cannot be determined, returns the fallback value or, if omitted, raises an error. |
377
- | log | function, filter | value, base (default e), fallback (optional) | Returns the logarithm of a value, defaulting to the natural logarithm if no base is provided. If that fails, it returns the fallback value or, if omitted, raises an error. |
378
- | sin | function, filter | value, fallback (optional) | Returns the sine of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
379
- | cos | function, filter | value, fallback (optional) | Returns the cosine of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
380
- | tan | function, filter | value, fallback (optional) | Returns the tangent of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
381
- | asin | function, filter | value, fallback (optional) | Returns the arcus sine of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
382
- | acos | function, filter | value, fallback (optional) | Returns the arcus cosine of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
383
- | atan | function, filter | value, fallback (optional) | Returns the arcus tangent of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
384
- | atan2 | function, filter | y, x, fallback (optional) | Returns the four quadrant arcus tangent of y / x. If that fails, it returns the fallback value or, if omitted, raises an error. |
385
- | sqrt | function, filter | value, fallback (optional) | Returns the square root of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
386
- | max | function, filter | args | Returns the largest argument provided, flattening any arrays. |
387
- | min | function, filter | args | Returns the smallest argument provided, flattening any arrays. |
388
- | average | function, filter | values, fallback (optional) | Returns the average of an array, flattening any subarrays. If a non-numeric value is detected or the array is empty, it returns the fallback value or, if omitted, raises an error. |
389
- | median | function, filter | values, fallback (optional) | Returns the median of an array, flattening any subarrays. If a non-numeric value is detected or the array is empty, it returns the fallback value or, if omitted, raises an error. |
390
- | statistical_mode | function, filter | values, fallback (optional) | Returns the mode of an array, flattening any subarrays. If a non-numeric value is detected or the array is empty, it returns the fallback value or, if omitted, raises an error. |
391
- | clamp | function, filter | value, min, max | Limits a value to be between min and max, clamping at the edges. If an input is not a number an error is raised. |
392
- | mod | function, filter | n, m | Performs the mathematical modulo operation on two numbers. Raises an error if the second number is 0. |
393
- | wrap | function, filter | value, min, max | Limits a value to be between min and max, wrapping at the edges. If an input is not a number an error is raised. |
394
- | remap | function, filter | value, in_min, in_max, out_min, out_max, steps (default 0), edges (default none) | Remaps a value from the input range to the output range. If the value or range inputs are not a number an error is raised. You can optionally set the `steps` parameter to a positive integer to quantize the output to a number of descrete steps. You can optionally set the `edges` parameter to control how out-of-bounds inputs values are handled. `edges='clamp'` will clamp the output to the min/max output range. `edges='wrap'` will wrap the input value around the input range before remapping. `edges='mirror'` will bounce the input value back and forth within the input range before remapping. |
395
- | e | constant | | Mathematical constant Euler's number. |
396
- | pi | constant | | Mathematical constant pi. |
397
- | tau | constant | | Mathematical constant tau. |
398
- | inf | constant | | Mathematical conceptual value infinity. |
399
- | round | filter | value, precision, method, fallback (optional) | Converts the input to a number and rounds it to `precision` decimals. It has four modes - `even`, `floor`, `ceil`, and `half`. If the input value is not a number, it returns the fallback value, or, if omitted, raises an error. |
400
- | bitwise_and | filter | value_one, value_two | Performs a bitwise and(&) operation with two values. |
401
- | bitwise_or | filter | value_one, value_two | Performs a bitwise or(\|) operation with two values. |
402
- | bitwise_xor | filter | value_one, value_two | Performs a bitwise xor(^) operation with two values. |
403
- | bitwise_not | filter | value | Performs a bitwise not(~) operation with one value. |
404
- | ord | filter | value | Returns an integer representing a character's (string of length one) Unicode code point. |
405
- | multiply | filter | value, arg | Converts the input to a number and multiplies it by the argument. |
406
- | add | filter | value, arg | Converts the input to a number and adds it to the argument. |
407
-
408
- ### [Complex Type Checking](https://www.home-assistant.io/docs/configuration/templating/#complex-type-checking)
409
-
410
- | Name | Type | Arguments | Description |
411
- | ----------- | ---- | --------- | -------------------------------------------------- |
412
- | list | test | value | Tests if a value is a list/array. |
413
- | set | test | value | Tests if a value is a set. |
414
- | datetime | test | value | Tests if a value is a datetime. |
415
- | string_like | test | value | Tests if a value is a string, bytes, or bytearray. |
416
-
417
- ### [Type Conversions](https://www.home-assistant.io/docs/configuration/templating/#type-conversions)
418
-
419
- | Name | Type | Arguments | Description |
420
- | ---- | ---------------- | --------- | ------------------------------------------------------ |
421
- | set | function | args | Convert a list/array to a set. Removes duplicates. |
422
- | list | function | args | Convert a set to an array. Does not remove duplicates. |
423
- | str | function, filter | value | Return the string representation of the input. |
424
-
425
- ### [Iterating Multiple Objects](https://www.home-assistant.io/docs/configuration/templating/#iterating-multiple-objects)
426
-
427
- | Name | Type | Arguments | Description |
428
- | ---- | -------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------- |
429
- | zip | function | args | Use to iterate over multiple collections in one operation. If given one array will perform the opposite action and unzip the list. |
430
-
431
- ### [Function and Filters to Process Raw Data](https://www.home-assistant.io/docs/configuration/templating/#functions-and-filters-to-process-raw-data)
432
-
433
- | Name | Type | Arguments | Description |
434
- | ------ | ---------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
435
- | pack | function, filter | data, format_string | Convert a native type to a bytes type object. |
436
- | unpack | function, filter | data, format_string, offset (default 0) | Convert a byte types object into a native object. The `offset` parameter defines the offset position in bytes from the start of the input bytes based buffer. |
437
-
438
- ### [String filters](https://www.home-assistant.io/docs/configuration/templating/#string-filters)
439
-
440
- | Name | Type | Arguments | Description |
441
- | ------------- | ------ | ----------------------------- | -------------------------------------------------------------------------------------------------------- |
442
- | urlencode | filter | value | Convert an object to a percent-encoded ASCII text string. |
443
- | slugify | filter | value, separator (default \_) | Convert a given string into a "slug". |
444
- | ordinal | filter | value | Convert an integer into a number defining a position in a series (e.g. `1st`, `2nd`, `3rd`, `4th`, etc). |
445
- | from_hex | filter | value | Decodes a hex string to raw bytes. |
446
- | base64_encode | filter | value | Encodes a string or bytes to a base 64 string. |
447
- | base64_decode | filter | value | Decodes a base 64 string to a UTF-8 string. |
448
-
449
- ### [Hashing](https://www.home-assistant.io/docs/configuration/templating/#hashing)
450
-
451
- | Name | Type | Arguments | Description |
452
- | ------ | ---------------- | --------- | ------------------------- |
453
- | md5 | function, filter | value | Hash value to md5 hex. |
454
- | sha1 | function, filter | value | Hash value to sha1 hex. |
455
- | sha256 | function, filter | value | Hash value to sha256 hex. |
456
- | sha512 | function, filter | value | Hash value to sha512 hex. |
457
-
458
- ### [Regular Expressions](https://www.home-assistant.io/docs/configuration/templating/#regular-expressions)
337
+ ### To/From JSON
338
+
339
+ | Name | Type | Arguments | Description |
340
+ | ------------------------------------------------------------------------ | ------ | ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
341
+ | [to_json](https://www.home-assistant.io/template-functions/to_json/) | filter | obj, ensure_ascii, pretty_print, sort_keys | Turn an object into a JSON string. `ensure_ascii` converts unicode characters into escape sequences. `pretty_print` formats the output with new lines and an indent of two spaces. `sort_keys` sorts the keys of the JSON object. |
342
+ | [from_json](https://www.home-assistant.io/template-functions/from_json/) | filter | value | Parse a string as JSON. |
343
+
344
+ ### Is Defined
345
+
346
+ | Name | Type | Arguments | Description |
347
+ | -------------------------------------------------------------------------- | ------ | --------- | -------------------------------------------------------------- |
348
+ | [is_defined](https://www.home-assistant.io/template-functions/is_defined/) | filter | value | Returns the value if it is defined, otherwise throws an error. |
349
+
350
+ ### Version
351
+
352
+ | Name | Type | Arguments | Description |
353
+ | -------------------------------------------------------------------- | ---------------- | --------- | --------------------------------- |
354
+ | [version](https://www.home-assistant.io/template-functions/version/) | function, filter | version | Returns a SemanticVersion object. |
355
+
356
+ ### Distance
357
+
358
+ | Name | Type | Arguments | Description |
359
+ | ---------------------------------------------------------------------- | ---------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
360
+ | [distance](https://www.home-assistant.io/template-functions/distance/) | function | args | Measures the distance between home, an entity, or coordinates. The unit of measurement (kilometers or miles) depends on the system’s configuration settings. |
361
+ | [closest](https://www.home-assistant.io/template-functions/closest/) | function, filter | args | Finds the closest entity to home, or the first entity or coordinate if multiple provided. Arguments can be entity IDs, domains, entity state objects, coordinate pairs, or arrays. |
362
+
363
+ ### Contains
364
+
365
+ | Name | Type | Arguments | Description |
366
+ | ---------------------------------------------------------------------- | ------------ | ----------- | ----------------------------------- |
367
+ | [contains](https://www.home-assistant.io/template-functions/contains/) | filter, test | list, value | Returns if an element is in a list. |
368
+
369
+ ### Numeric
370
+
371
+ | Name | Type | Arguments | Description |
372
+ | -------------------------------------------------------------------------------------- | ---------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
373
+ | [float](https://www.home-assistant.io/template-functions/float/) | function, filter | value, fallback (optional) | Converts a value to a float. If that fails, it returns the fallback value or, if omitted, raises an error. |
374
+ | [is_number](https://www.home-assistant.io/template-functions/is_number/) | function, filter | value | Returns true if a value can be parsed as a number. |
375
+ | [int](https://www.home-assistant.io/template-functions/int/) | function, filter | value, fallback (optional) | Converts a value to an integer. If that fails, it returns the fallback value or, if omitted, raises an error. |
376
+ | [bool](https://www.home-assistant.io/template-functions/bool/) | function, filter | value, fallback (optional ) | Converts a value to a boolean based on the human readable truthiness of it, case insensitive. Non-zero integers, `true`, `yes`, `on`, `enable`, and `1` return true. 0, `false`, `no`, `off`, `disable` and `0` return false. If the value's human readable truthiness cannot be determined, returns the fallback value or, if omitted, raises an error. |
377
+ | [log](https://www.home-assistant.io/template-functions/log/) | function, filter | value, base (default e), fallback (optional) | Returns the logarithm of a value, defaulting to the natural logarithm if no base is provided. If that fails, it returns the fallback value or, if omitted, raises an error. |
378
+ | [sin](https://www.home-assistant.io/template-functions/sin/) | function, filter | value, fallback (optional) | Returns the sine of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
379
+ | [cos](https://www.home-assistant.io/template-functions/cos/) | function, filter | value, fallback (optional) | Returns the cosine of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
380
+ | [tan](https://www.home-assistant.io/template-functions/tan/) | function, filter | value, fallback (optional) | Returns the tangent of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
381
+ | [asin](https://www.home-assistant.io/template-functions/asin/) | function, filter | value, fallback (optional) | Returns the arcus sine of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
382
+ | [acos](https://www.home-assistant.io/template-functions/acos/) | function, filter | value, fallback (optional) | Returns the arcus cosine of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
383
+ | [atan](https://www.home-assistant.io/template-functions/atan/) | function, filter | value, fallback (optional) | Returns the arcus tangent of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
384
+ | [atan2](https://www.home-assistant.io/template-functions/atan2/) | function, filter | y, x, fallback (optional) | Returns the four quadrant arcus tangent of y / x. If that fails, it returns the fallback value or, if omitted, raises an error. |
385
+ | [sqrt](https://www.home-assistant.io/template-functions/sqrt/) | function, filter | value, fallback (optional) | Returns the square root of a value. If that fails, it returns the fallback value or, if omitted, raises an error. |
386
+ | [max](https://www.home-assistant.io/template-functions/max/) | function, filter | args | Returns the largest argument provided, flattening any arrays. |
387
+ | [min](https://www.home-assistant.io/template-functions/min/) | function, filter | args | Returns the smallest argument provided, flattening any arrays. |
388
+ | [average](https://www.home-assistant.io/template-functions/average/) | function, filter | values, fallback (optional) | Returns the average of an array, flattening any subarrays. If a non-numeric value is detected or the array is empty, it returns the fallback value or, if omitted, raises an error. |
389
+ | [median](https://www.home-assistant.io/template-functions/median/) | function, filter | values, fallback (optional) | Returns the median of an array, flattening any subarrays. If a non-numeric value is detected or the array is empty, it returns the fallback value or, if omitted, raises an error. |
390
+ | [statistical_mode](https://www.home-assistant.io/template-functions/statistical_mode/) | function, filter | values, fallback (optional) | Returns the mode of an array, flattening any subarrays. If a non-numeric value is detected or the array is empty, it returns the fallback value or, if omitted, raises an error. |
391
+ | [clamp](https://www.home-assistant.io/template-functions/clamp/) | function, filter | value, min, max | Limits a value to be between min and max, clamping at the edges. If an input is not a number an error is raised. |
392
+ | mod | function, filter | n, m | Performs the mathematical modulo operation on two numbers. Raises an error if the second number is 0. |
393
+ | [wrap](https://www.home-assistant.io/template-functions/wrap/) | function, filter | value, min, max | Limits a value to be between min and max, wrapping at the edges. If an input is not a number an error is raised. |
394
+ | [remap](https://www.home-assistant.io/template-functions/remap/) | function, filter | value, in_min, in_max, out_min, out_max, steps (default 0), edges (default none) | Remaps a value from the input range to the output range. If the value or range inputs are not a number an error is raised. You can optionally set the `steps` parameter to a positive integer to quantize the output to a number of descrete steps. You can optionally set the `edges` parameter to control how out-of-bounds inputs values are handled. `edges='clamp'` will clamp the output to the min/max output range. `edges='wrap'` will wrap the input value around the input range before remapping. `edges='mirror'` will bounce the input value back and forth within the input range before remapping. |
395
+ | [e](https://www.home-assistant.io/template-functions/e/) | constant | | Mathematical constant Euler's number. |
396
+ | [pi](https://www.home-assistant.io/template-functions/pi/) | constant | | Mathematical constant pi. |
397
+ | [tau](https://www.home-assistant.io/template-functions/tau/) | constant | | Mathematical constant tau. |
398
+ | inf | constant | | Mathematical conceptual value infinity. |
399
+ | [round](https://www.home-assistant.io/template-functions/round/) | filter | value, precision, method, fallback (optional) | Converts the input to a number and rounds it to `precision` decimals. It has four modes - `even`, `floor`, `ceil`, and `half`. If the input value is not a number, it returns the fallback value, or, if omitted, raises an error. |
400
+ | [bitwise_and](https://www.home-assistant.io/template-functions/bitwise_and/) | filter | value_one, value_two | Performs a bitwise and(&) operation with two values. |
401
+ | [bitwise_or](https://www.home-assistant.io/template-functions/bitwise_or/) | filter | value_one, value_two | Performs a bitwise or(\|) operation with two values. |
402
+ | [bitwise_xor](https://www.home-assistant.io/template-functions/bitwise_xor/) | filter | value_one, value_two | Performs a bitwise xor(^) operation with two values. |
403
+ | bitwise_not | filter | value | Performs a bitwise not(~) operation with one value. |
404
+ | [ord](https://www.home-assistant.io/template-functions/ord/) | filter | value | Returns an integer representing a character's (string of length one) Unicode code point. |
405
+ | [multiply](https://www.home-assistant.io/template-functions/multiply/) | filter | value, arg | Converts the input to a number and multiplies it by the argument. |
406
+ | [add](https://www.home-assistant.io/template-functions/add/) | filter | value, arg | Converts the input to a number and adds it to the argument. |
407
+
408
+ ### Complex Type Checking
409
+
410
+ | Name | Type | Arguments | Description |
411
+ | ------------------------------------------------------------ | ---- | --------- | -------------------------------------------------- |
412
+ | list | test | value | Tests if a value is a list/array. |
413
+ | [set](https://www.home-assistant.io/template-functions/set/) | test | value | Tests if a value is a set. |
414
+ | datetime | test | value | Tests if a value is a datetime. |
415
+ | string_like | test | value | Tests if a value is a string, bytes, or bytearray. |
416
+
417
+ ### Type Conversions
418
+
419
+ | Name | Type | Arguments | Description |
420
+ | --------------------------------------------------------------- | ---------------- | --------- | ------------------------------------------------------ |
421
+ | [set](https://www.home-assistant.io/template-functions/set/) | function | args | Convert a list/array to a set. Removes duplicates. |
422
+ | [list](https://www.home-assistant.io/template-functions/list/) | function | args | Convert a set to an array. Does not remove duplicates. |
423
+ | [str](https://www.home-assistant.io/template-functions/string/) | function, filter | value | Return the string representation of the input. |
424
+
425
+ ### Iterating Multiple Objects
426
+
427
+ | Name | Type | Arguments | Description |
428
+ | ------------------------------------------------------------ | -------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------- |
429
+ | [zip](https://www.home-assistant.io/template-functions/zip/) | function | args | Use to iterate over multiple collections in one operation. If given one array will perform the opposite action and unzip the list. |
430
+
431
+ ### Function and Filters to Process Raw Data
432
+
433
+ | Name | Type | Arguments | Description |
434
+ | ------------------------------------------------------------------ | ---------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
435
+ | [pack](https://www.home-assistant.io/template-functions/pack/) | function, filter | data, format_string | Convert a native type to a bytes type object. |
436
+ | [unpack](https://www.home-assistant.io/template-functions/unpack/) | function, filter | data, format_string, offset (default 0) | Convert a byte types object into a native object. The `offset` parameter defines the offset position in bytes from the start of the input bytes based buffer. |
437
+
438
+ ### String filters
439
+
440
+ | Name | Type | Arguments | Description |
441
+ | -------------------------------------------------------------------------------- | ------ | ----------------------------- | -------------------------------------------------------------------------------------------------------- |
442
+ | [urlencode](https://www.home-assistant.io/template-functions/urlencode/) | filter | value | Convert an object to a percent-encoded ASCII text string. |
443
+ | [slugify](https://www.home-assistant.io/template-functions/slugify/) | filter | value, separator (default \_) | Convert a given string into a "slug". |
444
+ | [ordinal](https://www.home-assistant.io/template-functions/ordinal/) | filter | value | Convert an integer into a number defining a position in a series (e.g. `1st`, `2nd`, `3rd`, `4th`, etc). |
445
+ | [from_hex](https://www.home-assistant.io/template-functions/from_hex/) | filter | value | Decodes a hex string to raw bytes. |
446
+ | [base64_encode](https://www.home-assistant.io/template-functions/base64_encode/) | filter | value | Encodes a string or bytes to a base 64 string. |
447
+ | [base64_decode](https://www.home-assistant.io/template-functions/base64_decode/) | filter | value | Decodes a base 64 string to a UTF-8 string. |
448
+
449
+ ### Hashing
450
+
451
+ | Name | Type | Arguments | Description |
452
+ | ------------------------------------------------------------------ | ---------------- | --------- | ------------------------- |
453
+ | [md5](https://www.home-assistant.io/template-functions/md5/) | function, filter | value | Hash value to md5 hex. |
454
+ | [sha1](https://www.home-assistant.io/template-functions/sha1/) | function, filter | value | Hash value to sha1 hex. |
455
+ | [sha256](https://www.home-assistant.io/template-functions/sha256/) | function, filter | value | Hash value to sha256 hex. |
456
+ | [sha512](https://www.home-assistant.io/template-functions/sha512/) | function, filter | value | Hash value to sha512 hex. |
457
+
458
+ ### Regular Expressions
459
459
 
460
460
  **NOTE**: The format of regular expressions in nunjucks is different than jinja2. You may want to read the [Nunjucks](https://mozilla.github.io/nunjucks/templating.html#regular-expressions) and [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions) documentation.
461
461
 
462
- | Name | Type | Arguments | Description |
463
- | ------------------- | ------ | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
464
- | match | test | value, find | Matches the find string at the beginning of the value string using regex. |
465
- | search | test | value, find | Matches the find string anywhere in the value string using regex. |
466
- | test | test | value, find | Matches the find regular expression in the value string using regex. Regular expressions should be preceded by r, like `r/foobar/g`. |
467
- | regex_replace | filter | value, find (default ''), replace (default '') | Replaces the find expression with the replace expression string using RegEx. |
468
- | regex_findall | filter | value, find (default '') | Finds all RegEx matches of the find expression in value and returns an array of matches. |
469
- | regex_findall_index | filter | value, find (default ''), index (default 0) | Performs a RegEx find all but returns the match at a provided index. |
462
+ | Name | Type | Arguments | Description |
463
+ | -------------------------------------------------------------------------------------------- | ------ | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
464
+ | [match](https://www.home-assistant.io/template-functions/match/) | test | value, find | Matches the find string at the beginning of the value string using regex. |
465
+ | [search](https://www.home-assistant.io/template-functions/search/) | test | value, find | Matches the find string anywhere in the value string using regex. |
466
+ | test | test | value, find | Matches the find regular expression in the value string using regex. Regular expressions should be preceded by r, like `r/foobar/g`. |
467
+ | [regex_replace](https://www.home-assistant.io/template-functions/regex_replace/) | filter | value, find (default ''), replace (default '') | Replaces the find expression with the replace expression string using RegEx. |
468
+ | [regex_findall](https://www.home-assistant.io/template-functions/regex_findall/) | filter | value, find (default '') | Finds all RegEx matches of the find expression in value and returns an array of matches. |
469
+ | [regex_findall_index](https://www.home-assistant.io/template-functions/regex_findall_index/) | filter | value, find (default ''), index (default 0) | Performs a RegEx find all but returns the match at a provided index. |
470
470
 
471
- ### [Shuffling](https://www.home-assistant.io/docs/configuration/templating/#shuffling)
471
+ ### Shuffling
472
472
 
473
- | Name | Type | Arguments | Description |
474
- | ------- | ---------------- | ----------------------- | -------------------------------------------------------------- |
475
- | shuffle | function, filter | values, seed (optional) | Shuffle an array, either using a random seed or providing one. |
473
+ | Name | Type | Arguments | Description |
474
+ | -------------------------------------------------------------------- | ---------------- | ----------------------- | -------------------------------------------------------------- |
475
+ | [shuffle](https://www.home-assistant.io/template-functions/shuffle/) | function, filter | values, seed (optional) | Shuffle an array, either using a random seed or providing one. |
476
476
 
477
- ### [Flatten a List of Lists](https://www.home-assistant.io/docs/configuration/templating/#flatten-a-list-of-lists)
477
+ ### Flatten a List of Lists
478
478
 
479
- | Name | Type | Arguments | Description |
480
- | ------- | ---------------- | ------------------------- | ---------------------------------------------------------------------------------------------------- |
481
- | flatten | function, filter | values, levels (optional) | Flatten a list of lists. The depth of the flattening can be controlled using the `levels` parameter. |
479
+ | Name | Type | Arguments | Description |
480
+ | -------------------------------------------------------------------- | ---------------- | ------------------------- | ---------------------------------------------------------------------------------------------------- |
481
+ | [flatten](https://www.home-assistant.io/template-functions/flatten/) | function, filter | values, levels (optional) | Flatten a list of lists. The depth of the flattening can be controlled using the `levels` parameter. |
482
482
 
483
- ### [Find Common Elements Between Lists](https://www.home-assistant.io/docs/configuration/templating/#find-common-elements-between-lists)
483
+ ### Find Common Elements Between Lists
484
484
 
485
- | Name | Type | Arguments | Description |
486
- | --------- | ---------------- | ------------ | ----------------------------------------- |
487
- | intersect | function, filter | list1, list2 | Finds comment elements between two lists. |
485
+ | Name | Type | Arguments | Description |
486
+ | ------------------------------------------------------------------------ | ---------------- | ------------ | ----------------------------------------- |
487
+ | [intersect](https://www.home-assistant.io/template-functions/intersect/) | function, filter | list1, list2 | Finds comment elements between two lists. |
488
488
 
489
- ### [Find Elements In First List Not In Second List](https://www.home-assistant.io/docs/configuration/templating/#find-elements-in-first-list-not-in-second-list)
489
+ ### Find Elements In First List Not In Second List
490
490
 
491
- | Name | Type | Arguments | Description |
492
- | ---------- | ---------------- | ------------ | ---------------------------------------------------------------------- |
493
- | difference | function, filter | list1, list2 | Finds elements that are in the first list but not in the secondc list. |
491
+ | Name | Type | Arguments | Description |
492
+ | -------------------------------------------------------------------------- | ---------------- | ------------ | ---------------------------------------------------------------------- |
493
+ | [difference](https://www.home-assistant.io/template-functions/difference/) | function, filter | list1, list2 | Finds elements that are in the first list but not in the secondc list. |
494
494
 
495
- ### [Find Elements That Are In Either List But Not In Both](https://www.home-assistant.io/docs/configuration/templating/#find-elements-that-are-in-either-list-but-not-in-both)
495
+ ### Find Elements That Are In Either List But Not In Both
496
496
 
497
- | Name | Type | Arguments | Description |
498
- | -------------------- | ---------------- | ------------ | --------------------------------------------------------------------- |
499
- | symmetric_difference | function, filter | list1, list2 | Finds elements that are in either of the input lists but not in both. |
497
+ | Name | Type | Arguments | Description |
498
+ | ---------------------------------------------------------------------------------------------- | ---------------- | ------------ | --------------------------------------------------------------------- |
499
+ | [symmetric_difference](https://www.home-assistant.io/template-functions/symmetric_difference/) | function, filter | list1, list2 | Finds elements that are in either of the input lists but not in both. |
500
500
 
501
- ### [Combine All Unique Elements From Two Lists](https://www.home-assistant.io/docs/configuration/templating/#combine-all-unique-elements-from-two-lists)
501
+ ### Combine All Unique Elements From Two Lists
502
502
 
503
- | Name | Type | Arguments | Description |
504
- | ----- | ---------------- | ------------ | ------------------------------------------- |
505
- | union | function, filter | list1, list2 | Combine all unique elements from two lists. |
503
+ | Name | Type | Arguments | Description |
504
+ | ---------------------------------------------------------------- | ---------------- | ------------ | ------------------------------------------- |
505
+ | [union](https://www.home-assistant.io/template-functions/union/) | function, filter | list1, list2 | Combine all unique elements from two lists. |
506
506
 
507
- ### [Combining Dictionaries](https://www.home-assistant.io/docs/configuration/templating/#combining-dictionaries)
507
+ ### Combining Dictionaries
508
508
 
509
- | Name | Type | Arguments | Description |
510
- | ------- | ---------------- | --------- | ---------------------------- |
511
- | combine | function, filter | ...dicts | Merge multiple dictionaries. |
509
+ | Name | Type | Arguments | Description |
510
+ | -------------------------------------------------------------------- | ---------------- | --------- | ---------------------------- |
511
+ | [combine](https://www.home-assistant.io/template-functions/combine/) | function, filter | ...dicts | Merge multiple dictionaries. |
512
512
 
513
- ### [Working With Macros](https://www.home-assistant.io/docs/configuration/templating/#working-with-macros)
513
+ ### Working With Macros
514
514
 
515
- | Name | Type | Arguments | Description |
516
- | ----------- | ------------ | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
517
- | map | filter | arr, function, ...args | Call a function on every item in an array and return the resulting array. |
518
- | apply | filter, test | value, function, ...args | Apply a function to a value. Useful for calling other functions within other filters |
519
- | as_function | filter | macro | Convert a macro to a function to preserve underlying datatypes. The macro's first argument must be the callable parameter returns, which is silently called within the macro using `{%- set _ = returns(return_value) -%}`. |
515
+ | Name | Type | Arguments | Description |
516
+ | ---------------------------------------------------------------------------- | ------------ | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
517
+ | [map](https://www.home-assistant.io/template-functions/map/) | filter | arr, function, ...args | Call a function on every item in an array and return the resulting array. |
518
+ | [apply](https://www.home-assistant.io/template-functions/apply/) | filter, test | value, function, ...args | Apply a function to a value. Useful for calling other functions within other filters |
519
+ | [as_function](https://www.home-assistant.io/template-functions/as_function/) | filter | macro | Convert a macro to a function to preserve underlying datatypes. The macro's first argument must be the callable parameter returns, which is silently called within the macro using `{%- set _ = returns(return_value) -%}`. |
520
520
 
521
- ### [Merge Action Responses](https://www.home-assistant.io/docs/configuration/templating/#merge-action-responses)
521
+ ### Merge Action Responses
522
522
 
523
- | Name | Type | Arguments | Description |
524
- | -------------- | -------- | --------- | ------------------------------------------- |
525
- | merge_response | function | value | Merge several responses into a single array |
523
+ | Name | Type | Arguments | Description |
524
+ | ---------------------------------------------------------------------------------- | -------- | --------- | ------------------------------------------- |
525
+ | [merge_response](https://www.home-assistant.io/template-functions/merge_response/) | function | value | Merge several responses into a single array |
526
526
 
527
- ### [Determining Types](https://www.home-assistant.io/docs/configuration/templating/#determining-types)
527
+ ### Determining Types
528
528
 
529
- | Name | Type | Arguments | Description |
530
- | ------ | ---------------- | --------- | --------------------------------------------- |
531
- | typeof | function, filter | value | Returns the closest Python type of the input. |
529
+ | Name | Type | Arguments | Description |
530
+ | ------------------------------------------------------------------ | ---------------- | --------- | --------------------------------------------- |
531
+ | [typeof](https://www.home-assistant.io/template-functions/typeof/) | function, filter | value | Returns the closest Python type of the input. |
532
532
 
533
533
  ### Miscellaneous
534
534
 
package/dist/index.js CHANGED
@@ -66,8 +66,6 @@ if (version(packageInfo.version).compare(window.haNunjucks.version || '0.0.0') >
66
66
  }, window.haNunjucks[registry].updateEvent);
67
67
  }
68
68
  subscribeConfigEntries(ha.hass);
69
- // States object
70
- buildStatesObject();
71
69
  // Number and datetime translators
72
70
  window.haNunjucks.numberFormat = getNumberFormatter(ha.hass);
73
71
  window.haNunjucks.dateFormat = new Intl.DateTimeFormat(ha.hass.language, {
@@ -98,7 +96,9 @@ export function renderTemplate(hass, str, context, validate = true) {
98
96
  return str;
99
97
  }
100
98
  window.haNunjucks.hass = hass;
101
- buildStatesObject();
99
+ if (str.includes('_states')) {
100
+ buildStatesObject();
101
+ }
102
102
  str = window.haNunjucks.env
103
103
  .renderString(structuredClone(str), {
104
104
  hass,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ha-nunjucks",
3
- "version": "1.7.5",
3
+ "version": "1.7.6",
4
4
  "description": "Wrapper for nunjucks for use with Home Assistant frontend custom components to render templates",
5
5
  "main": "./dist/index.js",
6
6
  "files": [