Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secondary info template #124

Open
hiagocosta opened this issue Mar 4, 2024 · 22 comments
Open

secondary info template #124

hiagocosta opened this issue Mar 4, 2024 · 22 comments

Comments

@hiagocosta
Copy link

hi,
i'm trying to implement the templantes on a row for my Fire Tablet, that will inform it's currently situation, if is charging or not,
but I think that my logics is good enough...

I miss a bit

image

@hiagocosta
Copy link
Author

this is the full coding of this card:

image

@ildar170975
Copy link

  1. In future: post a real formatted code, not it's image.
  2. There is no secondary_info option, it is secondary.

@hiagocosta
Copy link
Author

hiagocosta commented Mar 6, 2024

sorry,
this is de the code of the card at all, still not picking the template

type: entities
entities:
  - entity: sensor.ble_battery_sensor_sala
    name: Termômetro Sala
  - entity: sensor.ble_battery_sensor_escritorio
    name: Termômetro Escritório
  - entity: sensor.ble_battery_sensor_quarto
    name: Termômetro Quarto
  - entity: sensor.ble_battery_sensor_externo
    name: Termômetro Externo
  - entity: sensor.ble_battery_sensor_banheiro
    name: Termômetro Banheiro
  - entity: sensor.ble_battery_sensor_cozinha
    name: Termômetro Cozinha
  - type: custom:template-entity-row
    entity: sensor.fire_tablet_battery
    secondary: >-
      {{% if is_state('binary_sensor.fire_tablet_plugged_in' , 'on') %}}
      Carregando {{% endif %}}
  - entity: sensor.mi_9_battery_level
    name: Xiaomi Mi9
    secondary_info: last-changed
  - entity: sensor.watch_6_battery_level
    name: Galaxy Watch 6
    secondary_info: last-updated
title: Nível de Bateria
theme: Mushroom Shadow
state_color: true

@ildar170975
Copy link

ildar170975 commented Mar 6, 2024

Because templates are wrong.

{{% ... %}}

must be

{% ... %}

@hiagocosta
Copy link
Author

now it works, thansk for help!!
by the way, this is shows as integer, how can I add in percentage?

image

@Misiu
Copy link

Misiu commented Mar 11, 2024

@hiagocosta I think it is the same bug as described here: #62

Use state template, something like this:

state:  '{{ state("sensor.fire_tablet_battery") }} %'

@ildar170975
Copy link

I think it is the same bug as described here

That issue #62 is not a bug - OP created it because he expected smth which is not supported. And did not close the issue after receiving explanations.
Also, that issue #62 is not related to the current issue - here it is about wrong use of jinja.
I wonder why both issues are still open.

@Misiu
Copy link

Misiu commented Mar 11, 2024

@ildar170975 I was only replying about the last question of OP because I had a similar issue with missing units:

image

type: entities
entities:
  - entity: sensor.x_cloud_days_until_expiration
  - entity: sensor.x_cloud_days_until_expiration
    type: custom:template-entity-row

the default row shows the unit when the [template-entity-row](custom:template-entity-row) is missing it.
I suggested using a template for the state as I'm doing: https://community.home-assistant.io/t/auto-entities-customize-displayed-name-and-use-attribute-as-secondary-info/700415/1

@ildar170975
Copy link

about the last question of OP because I had a similar issue with missing units

I see, thanks for clarifications.
UoM is not showing as it is not a part of a state. It has to be added manually in a template.

@Misiu
Copy link

Misiu commented Mar 11, 2024

UoM is not showing as it is not a part of a state. It has to be added manually in a template.

Exactly 👍

@Mariusthvdb
Copy link

Mariusthvdb commented Mar 11, 2024

for UOM, you can use:

            {{states[config.entity].state_with_unit}}

or

{{ states(config.entity, with_unit=True) }}

@hiagocosta if all of the above answers your config trouble, please close, so Thomas needs to check only valid/open issues? thx!

@ganjakyp-hub
Copy link

Are there any plans to implement last-changed information?

@ildar170975
Copy link

@ganjakyp-hub
Have you read what was written above? There is nothing to implement.

@ganjakyp-hub
Copy link

Maybe I didn’t understand something, but I tried different methods and they don’t work:

  • entity: binary_sensor.192_168_10_165
    secondary_info: last-changed
  • type: custom:template-entity-row
    entity: binary_sensor.192_168_10_165
    secondary_info: last-changed
  • type: custom:template-entity-row
    entity: binary_sensor.192_168_10_165
    secondary: last-changed
  • type: custom:template-entity-row
    entity: binary_sensor.192_168_10_165
    secondary: "{{ relative_time(states[config.entity].last_changed) }} назад"

image

@Mariusthvdb
Copy link

Mariusthvdb commented Apr 10, 2024

secondary: last-changed

does not work in a template-entity-row config, as that is an option for regular entities rows/cards.

in the template-entity-row, secondary: simply indicates the position in the row where your template will show its result.

as it accepts any template, it's up to you what you want to show there.
The template can use config.entity, if you use that in the main config. However, you can have it show anything you like, as long as the template you are using produces a result

cut it short:

all options in template-entity-row require (well, accept) a template. ofc you can set an icon directly.... or a name.

@ganjakyp-hub
Copy link

ganjakyp-hub commented Apr 10, 2024

It seems I solved the issue using a third party component https://github.com/TheFes/relative-time-plus

secondary: >-
{% from 'relative_time_plus.jinja' import relative_time_plus %}
{{ relative_time_plus(states[config.entity].last_changed, 1, language='ru') }} назад


Unfortunately this component incorrectly inflects words in Russian :(
Is it possible to add a regular secondary_info?

@Mariusthvdb
Copy link

Mariusthvdb commented Apr 10, 2024

that relative-time-plus only formats, and has nothing to do with the options for template-entity-row itself.
As I said above, you can use any template you want, to reach the result you need.

if it results in Russian, maybe your system language is in Russian? that is not incorrect, that is as expected then. You can probably set a language flag in that template, but then you need to check with that component.
Again, not to do with template-entity-row

btw, maybe you are aware, but you can do this in a filter template:

      - type: custom:auto-entities
        card:
          type: entities
          state_color: true
        filter:
          template: >
            [{% for entity_id in label_entities('speler_tracker')  %}
               {{ {'entity': entity_id,
                   'secondary_info': 'last-changed'} }},
            {% endfor %}]

or

        filter:
          template: >
            [{% for s in label_entities('speler_tracker')  %}
               {{ {'entity': s,
                   'secondary_info': 'last-changed'} }},
            {% endfor %}]

for that matter (just to illustrate the variable entity_id in the first template is a mere string of choice.)

@ganjakyp-hub
Copy link

That is, it is impossible to add support for regular secondary_info?

@ganjakyp-hub
Copy link

that relative-time-plus only formats, and has nothing to do with the options for template-entity-row itself. As I said above, you can use any template you want, to reach the result you need.

if it results in Russian, maybe your system language is in Russian? that is not incorrect, that is as expected then. You can probably set a language flag in that template, but then you need to check with that component. Again, not to do with template-entity-row

btw, maybe you are aware, but you can do this in a filter template:

      - type: custom:auto-entities
        card:
          type: entities
          state_color: true
        filter:
          template: >
            [{% for entity_id in label_entities('speler_tracker')  %}
               {{ {'entity': entity_id,
                   'secondary_info': 'last-changed'} }},
            {% endfor %}]

or

        filter:
          template: >
            [{% for s in label_entities('speler_tracker')  %}
               {{ {'entity': s,
                   'secondary_info': 'last-changed'} }},
            {% endfor %}]

for that matter (just to illustrate the variable entity_id in the first template is a mere string of choice.)

It doesn't work, something wrong?

  type: custom:template-entity-row
  entity: binary_sensor.192_168_10_210
  icon: mdi:television-classic
  name: TCL
  state: >-
    {% if is_state('binary_sensor.192_168_10_210', 'on')%}  {% else %}  {%
    endif %}    
  filter:
    template: >
      [{% for s in label_entities('binary_sensor.192_168_10_210')  %}
         {{ {'entity': s, 'secondary_info': 'last-changed'} }},
      {% endfor %}]

@Mariusthvdb
Copy link

Mariusthvdb commented Apr 30, 2024

It doesn't work, something wrong?

well, almost everything is wrong there yes...

your state template is not correct, missing the 'else' value

secondly, your are using a auto-entities filter template inside the template-entity-row config.....

besides, you are using this

label_entities('binary_sensor.192_168_10_210')

which seems incorrect. do you have binary_sensor.192_168_10_210 set as a label??

let me suggest you hop over to the Community where we can help you out with all of this.
This repo place is for 'issues' really, as in bugs, or feature request.

not for config assistance

@hiagocosta please close as there is no more issue?

@ganjakyp-hub
Copy link

Maybe it's possible to add this as a feature request?

@Mariusthvdb
Copy link

add what?

its not really clear what you want, and besides that, before making a FR, please try and figure out your errors, because you clearly are mixing various things up.

as said, this is not the place for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants