youask
(Mattias Nilsson)
March 15, 2022, 7:12pm
1
Im trying to pull a attribute from a entity
but it wont show
tried this code
type: entities
entities:
entity: sensor.fordpass_elveh
secondary_info: last-changed
type: divider
type: attribute
entity: sensor.fordpass_elveh
attribute: ElVehDTE
name: laddning %
type: divider
entity: sensor.fordpass_odometer
entity: lock.fordpass_doorlock
type: divider
title: Ford Mach-E
1 Like
WallyR
(Wally)
March 15, 2022, 7:20pm
3
Use the developer tools to find the entity and see the extra data attributes.
Then use a markdown card to make your own view, like below:
type: markdown
content: >-
Temperature: {{ state_attr('climate.bedroomthermometer','current_temperature') }} C
Replace the climate.bedroomthermometer with the entity id and current_temperature with the name of the extra data attribute you want to retrieve.
6 Likes
pedolsky
(Pedolsky)
March 15, 2022, 7:36pm
4
I assume the attribute is misspelled. Compare it in Develepor Tools â States, as recommended by Wally.
No capital letters in âcodeâ
petro
(Petro)
March 16, 2022, 11:50am
6
whaâts the attributes name in developer tools â states page?
Justbob
(Bob)
December 25, 2022, 5:43pm
7
Just what I was looking for! Thanks!
Rico81
(Enrico)
January 29, 2023, 3:25pm
8
Hey guys Iâm trying something similar but despite all your help above I canât get it working.
Iâm trying to display the battery level of my vacuum robot.
So I tried to edit the ânameâ line to do so.
But it doesnât work.
With Wallys code I can display it in a markdown card but as soon as I try to add this to the code below it fails.
So can anyone help me pls?
The entity is âvacuum.saugefuchsâ and the respective atribute is âbattery_levelâ.
type: custom:button-card
entity: vacuum.saugefuchs
show_entity_picture: true
state:
- value: docked
color: grey
icon: mdi:vacuum
- value: cleaning
color: green
icon: mdi:vacuum
- value: returning
color: yellow
icon: mdi:vacuum
name: null
tap_action:
action: navigate
navigation_path: ecovacs
show_state: false
show_label: false
show_name: true
size: 30%
view_layout:
grid-area: Sf
Cheers
Ernico
petro
(Petro)
January 29, 2023, 3:31pm
9
Custom button card doesnât allow Jinja Templates. It uses JS. The code above that uses {% %} or {{ }} is jinja.
Rico81
(Enrico)
January 29, 2023, 3:43pm
10
Ok, thx.
So what would it need to be then?
Viking
April 23, 2023, 12:43pm
11
Iâm trying to do the same. Did you ever manage to find a solution?
(The issue is; How to display an attribute a an entity name)
Rico81
(Enrico)
April 23, 2023, 3:46pm
12
With a little help of a friendâŚ
Okay, two steps:
Create a sensor:
- platform: template
sensors:
saugefuchs_battery:
value_template: >
{{ state_attr("vacuum.saugefuchs", "battery_level" ) }}
friendly_name: 'Saugefuchs Akku'
unit_of_measurement: "%"
So âvacuum.saugefuchsâ is the entity that contains the attribute âbattery_levelâ, which I want to attach to the name. So the code above creates a sensor which gives me the battery level of my vacuum cleaner.
Add the following code to your card code:
name: |
[[[
return `Saugefuchs ${states['sensor.saugefuchs_battery'].state} %`;
]]]
The text just before the dollar sign is the text which will be shown. So in my case "Saugefuchs ". Notice the space after the word, otherwise the battery level would be showninonewordwithoutanyspaceâŚ
Hope I could help.
Viking
April 24, 2023, 10:44am
13
Sorry, but that didnât work out for me:
name: |
[[[
return `Sted ${states['sensor.min_diesel_price'].state} %`;
]]]
It just returned:
[[[ return 'Sted ${states[âsensor.min_diesel_priceâ].state} %`; ]]]
petro
(Petro)
April 24, 2023, 10:51am
14
He failed to mention that this code will only work on custom button card.
Just make a template sensor that pulls the attribute and use that entity in the frontend wherever you want like any normal entity.
Viking
April 24, 2023, 2:38pm
15
Well, Iâm not using a button card at all (Do I have to?)
Iâm using the plane old entity card and custom:template-entity-row
mhackdo18
(Mhackdo18)
July 16, 2023, 12:16pm
16
I have feed Parser I want to get the value of attribute inside the at attribute and display below code i am using and gives me None None
Weather Updates {{ state_attr(âsensor.weather_updateâ, âpublishedâ) }}
{{ state_attr(âsensor.weather_updateâ, âsummaryâ)}}
WallyR
(Wally)
July 16, 2023, 7:28pm
17
What does the output in the developer tools â states say for those sensors?
Try with:
<s> {{ state_attr('sensor.weather_update','entries') | selectattr('published') | list }}</s>
well didnât work so well in my attempt as i had several âlistsâ in my sensor , but you have to address the âlistâ in your case âentriesâ > âpublishedâ
Maybe like this:
"{{ state_attr('sensor.weather_update','entries').0 }}"
or .1
(lists entries always starts with â0â for the first item/entry, then â1â, â2â etc.)
mhackdo18
(Mhackdo18)
July 17, 2023, 5:08am
19
Hi Thanks, It Mapped Correctly now using below code
{{ state_attr(âsensor.weather_updateâ, âentriesâ)[0][âsummaryâ] }}
1 Like
Haze
March 3, 2024, 4:52am
20
I have a custom button card, and wanting to do the same, but for some reason, it is not showing up on the frontend.
I have this code in the Developer, and it works, returns Increasing
{{state_attr('sensor.allergy_index_forecasted_average', 'trend')}}
This is for a Allergen sensor, using the IQVIA integration.
I did this template also:
{% if (state_attr('sensor.allergy_index_forecasted_average', 'trend') == 'Increasing') %}
{% set symbol = 'â ' %}
{% else %}
{% set symbol = 'â ' %}
{% endif %}
{{symbol}}
and it returns the up arrow.
Now I am trying to put into the frontend button template, to get the label to return the arrow up or down symbol, but it is not working:
weather_allergy:
name: Allergy
label: |
[[[
if (state_attr('sensor.allergy_index_forecasted_average', 'trend') == 'Increasing') {
return 'â '
} else {
return 'â '
}
]]]
What I am doing wrong?