Howto create battery alert without creating a template for every device

No ends up as:

{
  "name": "blink Front Battery",
  "state_topic": "homeassistant/sensor/blink_front_door_2_battery/state",
  "value_template": "{%- if value_json.value == 'ok' -%} Full {%- else -%} Low {%- endif -%}",
  "icon": "mdi:battery",
  "unique_id": "blink_front_door_2_battery",
  "json_attributes_topic": "homeassistant/sensor/blink_front_door_2_battery/attributes"
}

Ooopps, the hazards of coping and pasting :slight_smile:

My indentation must have triggered line returnsā€¦ Interesting!
Must remember that one! Live & learnā€¦

This package is phenomenal. It caught all my zwave blind, remote, and lock battery levels. Even electric car battery and phones. I also have Wyze sensors and once I let it run the ā€œcreate battery sensor from attributesā€ automation to create them I am now unable to send/receive the notification and getting the following log error:

2021-01-05 12:26:03 INFO (MainThread) [homeassistant.components.automation.battery_persistent_notification] battery_persistent_notification: Running automation actions
2021-01-05 12:26:03 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'

edit: I noticed that the error is only on the persistent and clear automation. I looked into those and saw it references the group of batteries that the package makes. I had that automation turned off. After manually executing it, the group was updated and now I receive notifications again. Iā€™ll leave that one on.

Now to remove batteries I donā€™t care about. Thanks!

1 Like

First, let me thank you for this script. It is something that should be IMO a part of the core HA system.

Iā€™ve got it running and everything seems to be working fine, Iā€™m just struggling with one thing. I have a few entities that contain ā€˜Batteryā€™ in their name, but they donā€™t really represent battery percentage (or level) value. That includes entity called sensor.sm_g965f_charger_type (is it the word ā€˜chargerā€™ that triggers its inclusion?).

Anyway, Iā€™d like to exclude these entities from being processed by the script. I canā€™t use battery_sensor_creation_disabled, because they are not generated by the script. And I canā€™t find counterpart of this configuration element for real entities. Is that even possible, or is there a chance that it could be added? Or is there some other way how this could be done?

Thanks!

Just add your real entity & the new attribute flag for battery-alert to your customize section in configuration.yaml.
I have my customize: broken out into customize.yaml
Iā€™ve added those attribute flags there like soā€¦
configuration.yaml:

####################################################################
# Configure a default setup of Home Assistant (frontend, api, etc) #
####################################################################
default_config:

homeassistant:
  customize: !include customize.yaml

customize.yaml:

sensor.coffee_machine:
  templates:
    theme: ''
    icon_color: 'if (state == ''Off'') return ''slategray''; if (state == ''Not Ready'')
      return ''#FFBF00''; if (state == ''Ready'') return ''lime''; if (state == ''Brewing'')
      return ''orangered'';'

person.daniel_brunt:
  entity_picture: /local/images/Cobra.jpeg

binary_sensor.ecolink_garage_door_tilt_sensor:
  device_class: garage_door

switch.mimolite_switch:
  icon: hass:power
  device_type: garage

sensor.vog_l04_battery_health:
  battery_alert_disabled: true

sensor.vog_l04_battery_level:
  battery_alert_disabled: true

sensor.vog_l04_battery_state:
  battery_alert_disabled: true

sensor.vog_l04_charger_type:
  battery_alert_disabled: true

sensor.browser_mod_2d3872d4_795db051:
  battery_alert_disabled: true
  battery_sensor_creation_disabled: true

sensor.browser_mod_6eba5467_e33aed8e:
  battery_alert_disabled: true
  battery_sensor_creation_disabled: true

sensor.browser_mod_ae7bcb81_077da789:
  battery_alert_disabled: true
  battery_sensor_creation_disabled: true

device_tracker.life360_daniel_brunt:
  battery_alert_disabled: true
  battery_sensor_creation_disabled: true

sensor.brunt_win10_battery_level:
  battery_alert_disabled: true
  battery_sensor_creation_disabled: true

sensor.brunt_win10_battery_remaining:
  battery_alert_disabled: true
  battery_sensor_creation_disabled: true

sensor.canon_mg7500_series_yellow:
  icon: mdi:water
  templates:
    hs_color: "return [255,255,0];        \n"

binary_sensor.4in1_pir_sensor_sensor:
  device_class: motion

light.garage_light:
  device_class: light

Thanks, thatā€™s what I did:

sensor.sm_g965f_charger_type:
  battery_alert_disabled: true

And in the Developer/States view I can see that the attribute was correctly set:

Screenshot 2021-01-06 at 9.54.10

But I still see it among the sensors being monitored (it is in the list displayed after I click on Battery Status label created by the recommended Lovelace yaml snippet).

Do I perhaps need to somehow manually remove the sensor from the list of monitored entities?

Itā€™ll still be listed in that Battery Status list but no alerts will be generated.

Ah, I see. Thanks!

If the package is creating an MQTT sensor that you donā€™t want then add battery_sensor_creation_disabled:

Hello all,

I have not been working with the HA for very long. I just have a question.
I cannot set a time anywhere when testing for the status of the batteries. When does this happen? Is it true that if the battery level falls below a certain percentage that a message is passed on?

Thank you for your response.

Persistent notifications default to every 1/4 hourā€¦

battery_alert.yaml:

################################################
## Automation
################################################
automation:
- alias: battery_persistent_notification
  initial_state: 'on'
  trigger:
    - platform: time_pattern
      minutes: '/15'
      seconds: 00
    - platform: state
      entity_id:
        - input_number.battery_alert_threshold_min
        - input_number.battery_alert_threshold_max

Yes, if between min_alert and max_alert thresholdsā€¦

Hello everyone,
First thanks @NotoriousBDG for this, itā€™s great and I hope one day something like this will be implemented in the core of HA.

I do have one question, maybe because I havenā€™t completely understood how this whole system works.
In the group.battery_status, I have many duplicates. All my aqara sensors appear twice, first the zigbee2mqtt entity, and second the mqtt entity created by this script.
Is it intended ? Looking at the automation code for the group, it seems to pick up every entity with anything related to battery (attributes, icon, name, id, etc)
Does the system need it own entity to work ?
Or can I just ask him to not create a sensor for those entities that already have one ?

Thanks :slight_smile:

I recall there was a change in HA core sometime in 2020 that autogenerated battery entities for the xiaomi integrationā€¦ you can disable them if you want - AFAIK they are only used in the config->integrations-> devices page. Or delete the package created ones and use the auto ones.

Iā€™ve got the package generated ones for my xiaomi integration and auto generated ones for my other zigbee - they all show in the battery group

Hello I added the Battery_allert.yaml. However, my Homamatic devices only show 2% battery. Where or do I have to adjust something so that the values ā€‹ā€‹are displayed correctly

The new zwave-js integration includes some entities on devices that detect low battery levels which are named something like:

binary_sensor.door_and_window_sensor_low_battery_level_3

The correct entity for this same sensor is:

sensor.door_and_window_sensor_battery_level_3

Is there an easy way I could exclude the low_battery_level values from this package? They are being detected for a lot of my devices instead of the correct value. Iā€™m going to look into this soon but figured Iā€™d ask if anyone has any advice before digging in too much.

customize:
  binary_sensor.door_and_window_sensor_low_battery_level_3:
    battery_alert_disabled: true

I get this part, the only problem is that itā€™s around 30 devices with this issue and with every device I will add in the future, it will grow. I know not a lot of people are running the new zwave add-on so Iā€™ll probably be looking into this soon.

Canā€™t nobody help me like I do the Homematic devices which only have high or low states or those which have the battery in volts (2.8 - 2.1 V) ā€¦

You most likely need to make a template for it.