How to list all sensors with attribute = ‘battery_level’

Although they appear in Developer Tools/States, the script don’t work for them…

All of the temperature / humidity sensors

My battery state is not a sensor, but a attribute of a sensor. That’s why I didn’t work for you.
Maybe this is a solution: 🔋 Lovelace: Battery state card

1 Like

Thank you. I’ll try to integrate it.

hi, how to fix this?

{{ states.sensor
  | selectattr('attributes.device_class', 'defined')
  | selectattr('attributes.device_class', 'eq', 'battery')
  | selectattr('state', 'lt', 25) # <- this will not work: TypeError: '<' not supported between instances of 'str' and 'int'
  | map(attribute='attributes.friendly_name' )
  | list }}

I think that some states are a ‘int’ and some ‘str’

Maybe you can use the auto-entities card.

Hello,

even as this seems to be solved, you can use auto-entities card as @LocoLoco proposed.

On the card, you can use code like this:

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - entity_id: '*battery_level*'
  exclude: []
sort:
  method: entity_id

This an easier way for new and unexperienced users and every device with this battery entities will be added automatically.