Closed chemelli74 closed 7 months ago
Works on my side.
- type: custom:auto-entities
card:
type: entities
state_color: false
filter:
include:
- entity_id: '*testing_device_class_battery*'
domain: sensor
options:
type: custom:secondaryinfo-entity-row
secondary_info: xxxxx
card_mod:
style: |
:host {
{% if states(config.entity) | int(0) >= 67 -%}
--paper-item-icon-color: green;
{% elif states(config.entity) | int(0) >= 34 -%}
--paper-item-icon-color: yellow;
{% else -%}
--paper-item-icon-color: red;
{% endif %}
}
sort:
method: state
reverse: true
numeric: true
Note that sensor
entities of device_class: battery
since 2022.12 have their own colors for icons dependingly on a state.
It works when state_color: true
and has hard-coded levels (find yourself these changes in a code).
type: custom:secondaryinfo-entity-row secondary_info: xxxxx
The issue in only related to the parsing of "xxxxx" value ;-)
Sorry for the bed title, just updated.
Simone
Log report:
2022-12-11 22:39:55.126 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'config' is undefined when rendering '{{ config.entity[22:-14] }}'
The config.entity
is NOT related to auto-entities
.
What you used here was a card-mod feature and may be used inside card-mod templates only - unless this config
object is documented as available like it is for custom:template-entity-row
.
Godo point, thx.
So which is the correct object to use ? this.entity
doesn't work as well.
Simone
Try to achieve your result w/o using another plugins - only with secondaryinfo-entity-row.
So which is the correct object to use ?
this.entity
doesn't work as well.
Have not tried i by myself.
If this
variable does not work - then probably it happens due to "templates in the secondaryinfo-entity-card
are resolved AFTER resolving this
".
I think so because secondary_info: this.entity_id
is resolved into displaying the entity's id, but when placed inside a template ({..}, [[[..]]) - does not work.
For some cases a documented way may be used - i.e. [[ {entity}.state .... ]]
.
For some cases a documented way may be used - i.e.
[[ {entity}.state .... ]]
.
This works:
secondary_info: "[[ {entity}.entity_id ]]"
but the following not:
secondary_info: "[[ {entity}.entity_id[22:-14] ]]"
Any further idea ?
Simone
entity_id[22:-14]
If this is jinjia - then you are mixing it with non-jinjia templates
You have a suggested solution then ? Seems to me that non-jinjia is lacking the substring handling, and jinjia doesn't work with entity substitution.
Simone
Seems to me that non-jinjia is lacking the substring handling, and jinjia doesn't work with entity substitution.
The best way is using auto-entities
with a template
filter to define a STRING which then will be used as a secondary-info.
So you will use jinjia to make that "entity_id[22:-14]" operation.
Go to auto-entities community thread - you will find plenty of examples for that "template" filter.
Go to auto-entities community thread - you will find plenty of examples for that "template" filter.
I must be blind, will keep searching; but if you have a link it would be much appreciated.
Simone
Last test shows:
secondary_info: "[[ {entity} ]]"
-> OK
secondary_info: "{{ states('sensor.xiaomi_sensore_4_battery_level') }}"
-> OK
secondary_info: '{{ states({entity}) }}'
-> Nothing shown on UI, no error logged.
Simone
link it would be much appreciated.
https://community.home-assistant.io/t/auto-entities-automatically-fill-cards-with-entities/147801
secondary_info: '{{ states({entity}) }}'
Mix of 2 alternative styles will not work.
https://community.home-assistant.io/t/auto-entities-automatically-fill-cards-with-entities/147801
:-) I mean link to the comment with the example, not to the thread...
secondary_info: '{{ states({entity}) }}'
Mix of 2 alternative styles will not work.
So back to the main issue, there is no variable to replace the entity in jinjia style.
Simone
I mean link to the comment with the example, not to the thread...
Search thread for examples.
there is no variable to replace the entity in jinjia style.
Good point, suggest you to close this issue and create a new FR to add a variable which may be used in jinjia templates.
Btw, I strongly suggest not to use GitHub for questions. Use GitHub for bugs & FRs only. Ask questions in the HA Community (there is a dedicated thread for this card) - there you will get answers faster (not to mention a fact that posting there = sharing knowledge with other people).
Seems I cannot use the object
config.entity
from custom:auto-entities in custom:secondaryinfo-entity-row. While it works fine for ":host
"Any hint ?
The goal is to extract a part of the entity name and show it as secondary row (due to ESPhome not handling attributes...).
Simone