#Template Sensor for low Batteries

1 messages · Page 1 of 1 (latest)

snow bane
#

Hi I'm struggling with a battery template sensor.

I want to list and also count all batteries specified in a helper group (sensor.all_batteries) - where the battery_level is below 20%.

    {{
    expand(state_attr('sensor.all_batteries', 'entity_id'))
    | selectattr('attributes.device_class', '==','battery')
    | selectattr('attributes.battery_level', 'defined') 
    | selectattr('attributes.battery_level', 'lt', 20)    
    | map(attribute='entity_id')
    | list
    }}

The problem is that the following lines are not working:

    | selectattr('attributes.battery_level', 'defined') 
    | selectattr('attributes.battery_level', 'lt', 20)    

If I delete them, all relevant sensors will display (e.g. in a auto-entities-card).

Thanks for your help! 🙏

upbeat tinsel
#

i got you

#
type: custom:battery-state-card
title: Low Battery
secondary_info: last_updated
show_empty: false
sort_by_level: asc
entities: null
filter:
  include:
    - name: entity_id
      value: '*_battery'
    - name: attributes.device_class
      value: battery
  exclude:
    - name: entity_id
      value: '*.state'
    - name: entity_id
      value: '*body*'
    - name: entity_id
      value: '*status*'
    - name: entity_id
      value: '*recharge*'
    - name: entity_id
      value: '*capacity*'
    - name: state
      value: Good
    - name: state
      value: STATUS_GOOD
    - name: state
      value: 'Off'
    - name: state
      value: 'off'
    - name: state
      value: 20
      operator: '>'
#

you need HACS > frontend > battery state card

snow bane
#

I'm trying to use a mushroom template card to display the number of low batteries and link them to a list of low battery entities.

#

@upbeat tinsel thanks for your answer. I don't want to use the battery state card because I can't "count" the number of batteries with low battery_level, don't i?

upbeat tinsel
#

yeah if you want a "count" might not be the way to go

#

my card has "show_empty: false"
so if all batteries are good, there is no battery card/button taking room on homescreen

#

someone else should chime in to help with this exact issue

snow bane
#

@upbeat tinsel that is exactly the solution i already have implemented... but I'm not really happy with it, because it doesn't look that "cool".

For my lights, doors, windows, switches i have a mushroom-template-card with the secondary information of how many entities are "on"...

e.g. my code for the lights.

The light.all_lights entity is a helper group where i put all my lights i want to check here (e.g. not those which turn off automatically after x seconds). So it is super easy to maintanence the entities i want to have in there.

{% if expand(state_attr('light.all_lights, 'entity_id'))| selectattr('state','eq','on')|map(attribute='entity_id')|list|count > 0 %}
  {{expand(state_attr('light.all_lights', 'entity_id'))| selectattr('state','eq','on')|map(attribute='entity_id')|list|count}}
{% else %}
  -
{% endif %}
upbeat tinsel
#

ok..
i have an idea for you.
tap action: navigate
new page : batteries.
battery page: options : sub-view
1 card,
battery-state-card

#

its basically what i did for my doors / windows/ shades

#
tap_action:
      action: navigate
      navigation_path:                /dashboard-mobile/windows
hold_action:
      action: more-info
double_tap_action:
#

use your current mushroom config for the button, but battery-state-card for the list

#

and thanks for the code

snow bane
#

@upbeat tinsel instead of using the battery-state-card you can also use the auto-entity-card to list all batteries below level X and in the predefined group "all_batteries". With "state_color: true" even the icons will colorize automatically.

type: custom:auto-entities
card:
  type: entities
  state_color: true
  title: Batteries
filter:
  include:
    - group: sensor.all_batteries
  exclude:
    - attributes:
        device_class: battery
      state: '> 20'
sort:
  method: state
  reverse: true
show_empty: false
#

But I'm still fighting the count of low batteries... 😉