Home-Assistant-custom-components-Custom-Templates
Home-Assistant-custom-components-Custom-Templates copied to clipboard
This integration adds possibility to use new functions in Home Assistant Jinja2 templating engine.
Custom Templates
[!CAUTION] This custom integration tampers with internal code of Home Assistant which might cause some unforeseen issues (especially after HA updates).
If you encounter any problems related to templating engine or translations try uninstalling this integration before raising an issue in Home Assistant repository.
This integration adds possibility to use new functions in Home Assistant Jinja2 templating engine:
ct_state_translated- returns translated state of an entityct_state_attr_translated- returns translated value of an attribute of an entityct_translated- returns translation for a given keyct_all_translations- returns all available translations (that can be used withct_translated)ct_eval- evaluates text as a templatect_is_available- checks if given entity is availablect_dict_merge- Merges two or more dictionaries together.
Usage
ct_state_translated
This function returns translated state of an entity. Second parameter (language) is optional - it defaults to the language configured in Home Assistant.
| Input | Output |
|---|---|
|
|
ct_state_attr_translated
This function returns translated value of an attribute of an entity. Third parameter (language) is optional - it defaults to the language configured in Home Assistant.
| Input | Output |
|---|---|
|
|
ct_translated
This function returns translation for a given key. You can use ct_all_translations to check available keys.
Second parameter (language) is optional - it defaults to the language configured in Home Assistant.
| Input | Output |
|---|---|
|
|
ct_all_translations
This function returns all available translations. Parameter (language) is optional - it defaults to the language configured in Home Assistant.
| Input | Output |
|---|---|
|
|
ct_eval
This function evaluates text as a template.
| Input | Output |
|---|---|
|
|
ct_is_available
This function checks if given entity has an available state.
By default, the following states are treated as not available: unknown, unavailable, <empty_text>, None.
It is possible to override this list by providing a second argument.
| Input | Output |
|---|---|
|
|
ct_dict_merge
This function will merge one or more dictionaries (mappings) together into a single dictionary. If any key is shared between two or more dictionaries, the value of the key will be the last value passed.
| Input | Output |
|---|---|
|
|
Configuration
To use this integration you have to add following config in configuration.yaml:
-
Without additional languages:
custom_templates: -
With additional languages:
custom_templates: preload_translations: - en - nl
A list of available language tags is available here, a list of descriptions of language tags is available here.
Section preload_translations should contain a list of languages you want to use with translations-related functions.
If it is not provided only a language provided in HA config will be loaded.
Installation
Since version v1.4.0 the minimal supported version of Home Assistant is 2024.5.0.
Using HACS (recommended)
This integration can be installed using HACS.
To do it search for Custom Templates in Integrations section.
Manual
Download custom_templates.zip and extract its contents to config/custom_components/custom_templates directory:
mkdir -p custom_components/custom_templates
cd custom_components/custom_templates
wget https://github.com/PiotrMachowski/Home-Assistant-custom-components-Custom-Templates/releases/latest/download/custom_templates.zip
unzip custom_templates.zip
rm custom_templates.zip
Finally, restart Home Assistant and configure the integration.
Support
If you want to support my work with a donation you can use one of the following platforms:
| Platform | Payment methods | Link | Comment |
|---|---|---|---|
| Ko-fi |
|
|
|
| buycoffee.to |
|
|
|
| PayPal |
|
|
|
| Revolut |
|
|
|

