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 available
This function returns translated state of an entity.
Input | Output |
---|---|
|
|
This function returns translated value of an attribute of an entity.
Input | Output |
---|---|
|
|
This function returns translation for a given key. You can use ct_all_translations
to check available keys.
Input | Output |
---|---|
Translated en: {{ ct_translated("component.sun.entity_component._.state.below_horizon", "en") }}
Translated en: {{ "component.sun.entity_component._.state.below_horizon" | ct_translated("en") }}
Translated nl: {{ ct_translated("component.sun.entity_component._.state.below_horizon", "nl") }}
Translated nl: {{ "component.sun.entity_component._.state.below_horizon" | ct_translated("nl") }} |
|
This function returns all available translations.
Input | Output |
---|---|
|
{
"component.sun.entity_component._.state.above_horizon": "Above horizon",
"component.sun.entity_component._.state.below_horizon": "Below horizon"
} |
This function evaluates text as a template.
Input | Output |
---|---|
{% set template_text = "{{ states('sun.sun') }}" %}
{{ ct_eval(template_text) }}
{{ template_text | ct_eval }} |
|
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 |
---|---|
{{ states('sensor.invalid') }}
{{ ct_is_available('sensor.invalid') }}
{{ ct_is_available('sensor.invalid', ['', 'unknown']) }} |
|
To use this integration you have to add following config in configuration.yaml
:
custom_templates:
preload_translations:
- en
- nl
A list of available language tags is available here, a list of desriptions of language tags is available here.
Section preload_translations
should contain a list of languages you want to use with translations-related functions.
Since version v1.3.0 the minimal supported version of Home Assistant is 2024.2.0.
Using HACS (recommended)
This integration can be installed using HACS.
To do it search for Custom Templates
in Integrations section.
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.
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 |
|
|