Howto create battery alert without creating a template for every device

@walaj, it didn’t work. deleted any entity related to the package, and after reinstalling it, I can see that every time the script created a topic for a sensor on MQTT, I get that ‘Entity ID’ error message in the log.

Right now I want to do another test. I want to create a sensor via MQTT manually. the same thing the script does, only without the templates. static data… do you know how to do that?

without reading through the package, nope. sorry.

Well… I figured it out. It was my fault all the time. I suspected that the entities are not created from the MQTT for a good reason. And it was because I turned off the MQTT discovery as a tried to figure out another problem from the log messages.

When I started everything from the beginning I noticed the MQTT discovery prerequisite.

Turned it back on and all of them started to work flawlessly! even the custom element card started to work!!!

Thank you @walaj for your patience. your guidance helped me put my thoughts in the right place!

1 Like

YAY!

Congrats. And I didn’t help. Just kept prodding you to test things.

1 Like

I did sidebar notifications for my Zigbee remotes. The icon changes when a battery is either low or empty. You can get the icons as direct download form the materials design website.

Ikea remotes are not very accurate when the battery is almost empty. The lowest value they sent is 16%. For that reason, I consider 21% as “low battery”. If a battery goes down to 16% I consider it empty and has to be replaced.

image

image

- alias: Notification - battery level alert 
  trigger:
  - platform: numeric_state
    above: 17
    below: 22
    entity_id: 
    - sensor.aqara_motion_1_battery_level
    - sensor.aqara_motion_2_battery_level
    - sensor.tradfri_motion_sensor_1_battery_level
    - sensor.tradfri_remote_control_1_battery_level
    - sensor.tradfri_remote_control_2_battery_level
    - sensor.tradfri_remote_control_3_battery_level
    - sensor.tradfri_on_off_switch_battery_level
  - platform: numeric_state
    above: 0
    below: 17
    entity_id: 
    - sensor.aqara_motion_1_battery_level
    - sensor.aqara_motion_2_battery_level
    - sensor.tradfri_motion_sensor_1_battery_level
    - sensor.tradfri_remote_control_1_battery_level
    - sensor.tradfri_remote_control_2_battery_level
    - sensor.tradfri_remote_control_3_battery_level
    - sensor.tradfri_on_off_switch_battery_level
  action:
  - service: persistent_notification.create
    data_template:
      message: >
          {% set value = trigger.to_state.state | int %}
          {% if value <= 17 %}
            Battery level of {{ trigger.to_state.name }} is below {{ trigger.to_state.state | int | round(0) }}% {{ '\n' -}} {{ '\n' -}} 
            ![image](/local/battery-empty-white.png)
          {% else %}
            Battery level of {{ trigger.to_state.name }} is below {{ trigger.to_state.state | int | round(0) }}% {{ '\n' -}} {{ '\n' -}} 
            ![image](/local/battery-low-white.png)
          {% endif %}
      title: Battery level low
      notification_id: "battery"
1 Like

I’ve just installed the script using the code in github. I’ve set up the alert thresholds, but I’m seeing the following in the log:

2020-07-22 16:37:00 INFO (MainThread) [homeassistant.components.automation] update_battery_status_group_members: Running script
2020-07-22 16:37:00 INFO (MainThread) [homeassistant.components.automation] update_battery_status_group_members: Executing step call service
2020-07-22 16:37:00 ERROR (MainThread) [homeassistant.components.automation] update_battery_status_group_members: Error executing script. Service not found for call_service at pos 1: Unable to find service group/set

After following the install and running a “Check Configuration” before restarting, I’m getting this error:

 Invalid config for [group]: [view] is an invalid option for [group]. Check: group->group->battery_view->view.

@pashdown
Remove line 346 completly, that should solve the problem. :slight_smile:

Thanks. I had to remove a number of lines. Doesn’t seem to affect operability.

*** /tmp/battery_alert.yaml	2020-07-22 12:44:04.999560623 -0600
--- battery_alert.yaml	2020-07-22 11:24:05.193243630 -0600
***************
*** 292,304 ****
        <<: *customize
        friendly_name: "Battery Alert"
        icon: mdi:steam
-       control: hidden
  
      group.battery_status:
        <<: *customize
        friendly_name: "Battery Status"
        icon: mdi:battery-charging
-       control: hidden
  
      ################################################
      ## Automation
--- 292,302 ----
***************
*** 343,355 ****
  ################################################
  group:
    battery_view:
-     view: yes
      entities:
        - group.battery_status
        - group.battery_alert
  
    battery_alert:
-     control: hidden
      entities:
        - input_boolean.low_batteries
        - input_number.battery_alert_threshold_min
--- 341,351 ----

The docs says to add any sensors you do not want to create in customize.yaml. I have added the sensors I do not want to create, but it still shows. I believe a few HA updates back the hide or no show has been deprecated?

## 11. To disable creating a sensor from battery attributes for a specific entity, use customize to
##     set `battery_sensor_creation_disabled` to `true`
##
##     homeassistant:
##       customize:
##         sensor.sensor_with_battery_attibute:
##           battery_sensor_creation_disabled: true

you need to use the “delete a battery sensor” call, to remove it, once it has been created…

Hi. I have manually deleted the sensors with the delete a battery sensor and added the battery_sensor_creation_disabled: true in customize for each of the sensors I want to not show. After a reboot and triggering, the sensors returns. The red boxes are the ones I want to not show.

Also, how to fix the unknown in yellow box below?

customize.yaml

sensor.computer_room_action_battery:
  battery_sensor_creation_disabled: true
sensor.shion_room_action_battery:
  battery_sensor_creation_disabled: true
sensor.motion_hallway_requested_brightness_level_battery:
  battery_sensor_creation_disabled: true  

ok - so you have told it to ignore creating a battery sensor for computer_room_action_battery

now you have to remove the sensor - paste homeassistant/sensor/computer_room_action_battery into the delete a battery sensor box and press enter. You need the total MQTT path… which you can get/check by clicking on the battery to get the extra info popup:
Capture

No idea about the “battery Status” at the top - what extra info do you get - it may be something you have managed to delete, but there is still some residual info…

Something weird maybe happening with my HA. Where do click to check the extra info as you mentioned? Is it here with this screenshot below? If so, clicking any of the battery does nothing. It doesn’t bring me to that pop like yours above. At any rate, I have already added these lines each in the delete a battery sensor. I can confirm that the sensors have been deleted. However, once I trigger them, it reappears.

homeassistant/sensor/computer_room_action_battery
homeassistant/sensor/shion_room_action_battery
homeassistant/sensor/motion_hallway_requested_brightness_level_battery

The unknown in yellow has always been there since I setup the battery_alert. Clicking on it brings me nowhere. Maybe my other option is to delete the db in mqtt? Not sure how to go about with that.

You have to create a custom card for the batteries, instead of using the group.battery_status entity, then you can click on them and get the full MQTT path. It took me a while to figure out too.

      - card:
          show_header_toggle: false
          title: Battery Status
          type: entities
        filter:
          include:
            - entity_id: sensor.*battery*
        sort:
          method: state
          numeric: true
        type: 'custom:auto-entities'

Also remember that lovelace resources are loaded in configuration.yaml now and not ui-lovelace.yaml:

lovelace:
  mode: yaml
  resources:
    - url: /local/community/lovelace-auto-entities/auto-entities.js?v=1
      type: module

I am having the same issue. I am unable to delete some of the sensors I do not want to create. I tried to delete the sensors using the delete a battery sensor for each. Restart HA. However, once I start using the devices, the sensors come back.

How/where do you navigate to the cli for deleting the sensors via mqtt to issue this cmd? My version of mqtt is an add-on install over Hassio.

mosquitto_sub -t “homeassistant/sensor/#” | grep -i pressure

good point - totally forgot about that. Been a while since I set this up.

then they are not correctly being flagged for ‘no battery’.

Check in the states gui:

@walaj
Comparing to your image and mine. I do see battery_sensor_creation_disabled: true. However, I also see delete_battery_sensor: homeassistant/sensor/computer_room_action_battery. Is this the cause? I am seeing that line on all the sensors I do not want to show.

@duceduc Try to install MQTT explorer ( http://mqtt-explorer.com/ ) to confirm and/or delete the devices correctly, that helps me a lot.

Change line 608:
from:

        value_template: "{{ not is_state_attr(trigger.event.data.entity_id, 'battery_sensor_creation_disabled', true) }}"

to

        value_template: "{{ not is_state_attr(trigger.event.data.entity_id, 'battery_sensor_creation_disabled', 'true') }}"