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?