Closed chemelli74 closed 4 months ago
The card shows a "raw" state, i.e. this is expected behaviour. Here is a way (check readme) to localize:
type: entities
entities:
- type: custom:template-entity-row
entity: person.ildar
state: >-
_(component.device_tracker.entity_component._.state.{{states(config.entity)}})
- type: custom:template-entity-row
entity: person.ildar
Thx for the clarification.
I would expect that the default behaviour is the same as built-in entities.
And eventually specify a "state: raw
" if a user want it.
Tested and seems it doesn't follow device_class: gas
Got it, thx a lot for your time !
personally I feel this should be reopened as a config like:
- type: custom:template-entity-row
entity: device_tracker.private_ble_device_marijn
secondary: >
Verbonden: {{states('sensor.private_ble_device_marijn_connection')}}
so, without a state template, should optimally really show the localized state, and not require a dedicated template to do so.
Agree with @chemelli74 on his thoughts that default should localize. if possible. that might constitute a FR, but given this is new functionality, Id hope this could be implemented.
also those template formats are really peculiar, and not core HA style.
_(state.binary_sensor.motion.off)
is very uncommon. if a state of a binary template would be involved and lokalisation must be done with an underscore, shouldnt it better be configured as {{_states('binary_sensor.motion_sensor')}}
.
that way it would still use the known jinja syntax, and only requirement would be the additional _
how could this be thought to be user friendly....
state: >-
_(component.device_tracker.entity_component._.state.{{states(config.entity)}})
compare with
- type: custom:button-card
entity: device_tracker.private_ble_device_marijn
show_state: true
which does just that, follow core HA style and shows the translated state
hopefully this PR will allow us to simply use state_translated('device_tracker.private_ble_device_marijn')}}
or state_translated('binary_sensor.motion')}}
soon!
hi @ildar170975, can you be so kind to tell me how to get the zone nome ?
Usual device_tracker
behaviour is:
Cannot achive the same with your suggestion.
@chemelli74 I do not understand(( Please elaborate.
When a device_tracker
entity enter a zone, the status of the tracker takes the name of the zone itself.
Instead when it's in a unknown zone is just "Away
" and when at home is "Home
".
Last two are localized, but the zone names not of course.
I cannot achive the result of getting the correct status with template-entity-row :-(
If I add the code for "state:" then I get Away and Home localized, but a bad status for all known zones.
If I don't add the code for "state:" then I get all known zones right, but "home
" and "not_home
" raw.
When a device_tracker entity enter a zone, the status of the tracker takes the name of the zone itself.
It takes a friendly_name
of the zone, "Home" (localized name of home
), "Away" (localized name of not_home
).
If I add the code for "state:" then I get Away and Home localized, but a bad status for all known zones.
When using t-e-r, you need to use those _(...)
functions only to get localized home
& not_home
.
I.e. use a template like
if home or not_home
use _(...)
else
use states(config.entity)
Just for future reference if others will find this issue, here the final working code:
state: |-
{%- if states(config.entity) not in ['home', 'not_home'] -%}
{{ states(config.entity) }}
{%- else -%}
_(component.device_tracker.entity_component._.state.{{states(config.entity)}})
{%- endif -%}
Thank you so much for your assistance and solution.
ive just installed todays dev, and this is now available:
type: entities
entities:
- type: custom:template-entity-row
name: Translated state
entity: person.marijn
state: |
{{state_translated(config.entity)}}
and working beautifully.
seems the latest PR on localization for template-entity-row this issue is discussing should again be reverted (taken out) because of core support for localization Hope @thomasloven will have a look
Unfortunately as soon as I add this card, entity status revert to default.
vs