Nested Attributes in Card Title

I have the “Low battery level detection & notification for all battery sensors” Blueprint by Sbyx, and I added a Dashboard card with the title

{{ state_attr(‘sensor.battery’, ‘min_entity_id’) }}

which returns just the name of the device that has the lowest battery level. e.g. “sensor.temperature_outside_battery”. However, I want that card Title to also list that device’s ‘battery_level’. I tried this non-working solution

{{ state_attr(‘sensor.battery’, ‘min_entity_id’) }} is at {{ state_attr('{{ state_attr(‘sensor.battery’, ‘min_entity_id’) }}, ‘battery_level’) }}%

I have run out of ideas, and am unsure if this is even possible. If not, is there some other way to get this information onto the Dashboard? If the answer is making a template, would you kindly post the actual code, as I am an eager newbie to coding. Thank you.

1 Like

Welcome to the forums!

Post the attributes of your sensor (Developer Tools —> States).

All my devices have “battery_level” which is the state attribute I want to show for the sensor with the lowest battery level found with

{{ state_attr(‘sensor.battery’, ‘min_entity_id’) }}

I apologize if I am not clearly stating my needs due to terminology, and I greatly appreciate any assistance.

You are trying to display attributes of sensor.battery . Does this sensor provide the attributes you want to display?
You refer to a blueprint that sends a notification. How is this related to your sensor sensor.battery ?

@pedolsky yes. The Blueprint is called in my Title using

{{ state_attr(‘sensor.battery’, ‘min_entity_id’) }}

and it returns the name of the device with the lowest battery level. What I am hoping is for a way that I can insert that result (lets call that code string “X”) into

{{ state_attr(X, ‘battery_level’) }}

I can’t follow. The blueprint is an automation and everything it does is to send a notification with a list of sensors that are below the given threshold.

So where does your sensor.battery come from?

@pedolsky I am not good at coding, so you may want to ask Sbyx about how his Blueprint works. All I know is that it always returns only the device that has the lowest battery level, whichever device that may be. My specific question and my need is how to embed

{{ state_attr(‘sensor.battery’, ‘min_entity_id’) }}

so that the device name it returns can be used to retrieve an attribute of that device.

{{ state_attr(X, ‘battery_level’) }}

I would truly appreciate it if you, or anyone, can assist me with the code necessary for that to occur. Thank you.

I know how that blueprint works. That’s what I’m trying to explain you: The sensor you are using has nothing to do with that blueprint. That,s why I asked you to post the state attributes of your sensor.

I have dozens of sensors and have no way of knowing in advance which one will be deemed by the Blueprint to have the lowest battery level, so I don’t see how I can provide the state attributes for the sensor that has yet to have the lowest battery level. What I do know is that all of my sensors have the “battery_level” attribute, which is the one that I want. Can you help me get the code corrected version of

{{ state_attr( {{ state_attr(‘sensor.battery’, ‘min_entity_id’) }}, ‘battery_level’) }}

Again: Go to Developer Tools / States, collapse „Set state“ at the top of that site, type in sensor.battery and post what this will show you.

state_class: measurement
min_entity_id: sensor.temperature_furnace_closet_battery
unit_of_measurement: “%”
icon: mdi:battery
friendly_name: Group Minimum - battery devices

Ok. Seems to be a min/max sensor, created via UI helper?

Copy the following into Developer Tools/Template (or into your card):


{% set entity = 'sensor.battery' %}
{{ state_attr(entity, 'min_entity_id') }} is at {{ states(entity) }}%

I assume, it’s a Mushroom Title Card? If so, you can use the variable entity:


{{ entity.attributes.min_entity_id }} is at {{ entity.state }}%

Originally, you asked also for quantity and size. Are that actually attributes of the target battery sensor (e.g. sensor.temperature_furnace_closet_battery )?

@pedolsky First off, your a coding genius and THANK YOU for sharing your time and knowledge with me. This is the title of a simple “Entity card”. I did not realize that one can define and use a variable within a card title. I would like to also get quantity and size, so that I know which batteries will be needed, and those are attributes of this sensor. Even if other sensors do not support those attributes, I want to learn from your wisdom, so I tried

{% set entity = ‘sensor.battery’ %}
{{ state_attr(entity, ‘min_entity_id’) }} is at {{ states(entity) }}% and needs {{ state_attr(entity, ‘battery_quantity’) }} of {{ state_attr(entity, ‘battery_size’) }}

but that fails (likely obvious for you). What is the error of my logic?

battery_quantity and battery_size are attributes of your battery sensor, not of your min/max sensor. Try the following:


{% set entity = 'sensor.test' %}
{% set child = state_attr(entity, 'min_entity_id') %}
{{ child }} is at {{ states(entity) }}% and needs {{ state_attr(child, 'battery_quantity') }} of {{ state_attr(child, 'battery_size') }}

or with a friendly name:

following:


{% set entity = 'sensor.test' %}
{% set child = state_attr(entity, 'min_entity_id') %}
{{ state_attr(child, 'friendly_name') }} is at {{ states(entity) }}% and needs {{ state_attr(child, 'battery_quantity') }} of {{ state_attr(child, 'battery_size') }}

I changed sensor.test to sensor.battery and your code is awesome (and I can now apply this understanding to other needs).

{% set entity = ‘sensor.battery’ %} {% set child = state_attr(entity, ‘min_entity_id’) %}
{{ state_attr(child, ‘friendly_name’) }}
is at {{ states(entity) }}% and uses {{ state_attr(child, ‘battery_quantity’) }}x{{ state_attr(child, ‘battery_size’) }}

You mentioned the mushroom card, but I am unsure of how to add that to the mushroom entry. Would you be willing to reply with that code?

  • type: entity
    entity: sensor.battery
    tap_action:
    action: more-info
    hold_action:
    action: none
    double_tap_action:
    action: none
    use_entity_picture: true
    icon_color: red
    name: Battery
    icon: mdi:battery-30

You have to use the Mushroom Template Card or the Title Card.

Understood. Then I will consider this topic resolved and closed. Thank you for sharing your time and expertise. I hope to be in a position to pay it forward soon.