Pulling an attribute from a entity and display it?

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

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

I assume the attribute is misspelled. Compare it in Develepor Tools → States, as recommended by Wally.

No capital letters in “code”

wha’ts the attributes name in developer tools → states page?

Just what I was looking for! Thanks!

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

Custom button card doesn’t allow Jinja Templates. It uses JS. The code above that uses {% %} or {{ }} is jinja.

Ok, thx.
So what would it need to be then?

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)

With a little help of a friend… :wink:
Okay, two steps:

  1. 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.

  1. 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… :wink:

Hope I could help.

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} %`; ]]]

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.

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

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’)}}

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.)

Hi Thanks, It Mapped Correctly now using below code

{{ state_attr(‘sensor.weather_update’, ‘entries’)[0][‘summary’] }}

1 Like

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?