Custom Templates

Today I try update HA Core to version 2023.4.6 with the same result.
Translations still not working :frowning:

I know, I’ll check it out soon :frowning:

Fixed!

1 Like

Piotr, unfortunately does not work:

Log:

2023-05-03 13:40:08.328 WARNING (MainThread) [custom_components.custom_templates] No translation found for key: fcomponent.sun.state._.below_horizon
2023-05-03 13:40:17.447 WARNING (MainThread) [custom_components.custom_templates] No translation found for key: fcomponent.sun.state._.below_horizon
2023-05-03 13:40:48.984 WARNING (MainThread) [custom_components.custom_templates] No translation found for key: fcomponent.sun.state._.below_horizon
2023-05-03 13:40:48.996 WARNING (MainThread) [custom_components.custom_templates] No translation found for key: fcomponent.sun.state._.below_horizon

configuration.yaml:

custom_templates:
  preload_translations:
    - en
    - ru

Seems to be the latest version, installed by HACS:

{
  "domain": "custom_templates",
  "name": "Custom Templates",
  "codeowners": ["@PiotrMachowski"],
  "documentation": "https://github.com/PiotrMachowski/Home-Assistant-custom-components-Custom-Templates",
  "iot_class": "calculated",
  "issue_tracker": "https://github.com/PiotrMachowski/Home-Assistant-custom-components-Custom-Templates/issues",
  "requirements": [],
  "version": "v1.2.0"
}

It works, but the translation key in HA has been changed. Use component.sun.entity_component._.state.above_horizon instead

1 Like

Thanks a lot, that was a reason:

Its works perfect! Thank you for release, Piotr!

I’ve been using this custom integration to display the friendly status of my entities in a template, for example, Leak detectors to show Wet or Dry as shown in the default Lovelace dashboards. This has been working well until the April update to HA.

An example:

{{ ct_state_translated('binary_sensor.hall_motion', 'en') }}

Used to say Clear or Detected but now shows Off or On, is there a way to return to the previous behaviour?

Yes, I have to include device_class in the translation key of a new translations as well to make it work.

I have fixed it in v1.2.1

Don’t quite understand how to use this… Can be this somehow used directly in lovelace or need to be used as template sensor?

You have to add this to the configuration.yaml (list of supported languages):

custom_templates:
  preload_translations:
    - en
    - nl
    - <any language you want>

Then you can use new functions wherever you use jinja templates.

I installed via HACS, did the first step regarding custom_templates…

Now I do not know how to let say fix the translation for “sensor.nvr_hikdevice_status”
image

So that it will be instead of Online translated to “Povezano” or whatever I would like.

So is possible to use own custom strings and how to achieve that?

This integration doesn’t change states/translations of existing entities. It just adds new functions to jinja templates. You can use these functions to create template sensors, in notifications, on dashboards (in markdown card) and in many different places.

Thank you…

Then this is now what I’m searching for… to much work for small needed results…

Hi, Piotr!
Currently it is possible to localize strings like these:

component.binary_sensor.entity_component.problem.state.on
component.sun.entity_component._.state.below_horizon

But what about values “unavailable” & “unknown”?
I found these resources:

state.default.unavailable
state.default.unknown

but seems that these strings cannot be localized:

Could you give me a hint how to localize these values?

They are not supported at this moment, I need to adjust the implementation to include them.

Thanks a lot for a reply.
Shall I register a FR on GitHub?

You can if you want to

Please consider this FR when you will be able: