Howto create battery alert without creating a template for every device

Sorry! ive been playing with this and read a load of topics, but im still stuck!

im seeing this log error

Wed May 15 2019 10:40:33 GMT+0100 (British Summer Time)

Error while executing automation automation.battery_sensor_from_attributes. Service not found for call_service at pos 1: (ServiceNotFound(…), ‘Service mqtt.publish not found’)

  1. what card should i be using to show all batteries that are “low” (ive set min to 97 and max to 100 just to give me some results). Note: notifications seem to be working, but i cant work out the card to use?

Running HassIO: 0.92.2 - system health below.
Running Mosquitto broker, where I have enabled the add-on with the following settings.

{
“logins”: ,
“anonymous”: false,
“quiet_logs”: true,
“customize”: {
“active”: true,
“folder”: “mosquitto”
},
“certfile”: “fullchain.pem”,
“keyfile”: “privkey.pem”
}

  • have disabled everything within the network card.
  • i have setup the ACCESS CONTROL LISTS (ACLS)
  • i have added the following to confg.yaml, even though it mentioned this wasnt needed in the mosquitto notes
 mqtt:
   discovery: true
   discovery_prefix: homeassistant
  • i have added the following to automations.yaml, which also works ok.
  • alias: Home Assistant Startup
    id: Home_Assistant_Startup
    trigger:
    • platform: homeassistant
      event: start
      action:
    • service: notify.notify
      data:
      message: Home Assistant is up

RPi info

System Health

arch armv7l
dev false
docker true
hassio true
os_name Linux
python_version 3.7.3
timezone Europe/London
version 0.92.2
virtualenv false

Lovelace

mode storage
resources 0
views 9

hey, how did you add this “low battery levels” card?

That suggests that MQTT isn’t working. Check your logs to see if you can figure out why MQTT isn’t working

That is the persistent notification that’s automatically created by the package.

Thanks for the reply

so MQTT seems to be working ok now.

Sorry, for the 2nd item - i want to show a card, that has all the “low” battery levels shown only - how do i do that?

[NotoriousBDG] do you have plans to add your wonderful work into custom updater? So everyone can automatically have the latest version.

I have the same problem, and I did use the raw link to copy/paste the content of the battery_alert.yaml file. Also tried to download the file from Github and use that one.

Invalid config for [automation]: required key not provided @ data['action']. Got None
required key not provided @ data['trigger']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/

First lines of the configuration.yaml:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: !secret home_latitude
  longitude: !secret home_longitude
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: !secret home_elevation
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: !secret timezone
  customize: !include customize.yaml
  packages: !include_dir_named packages
  auth_providers:
    - type: homeassistant

Thanks! :smile:

That’s not a native feature of the package today. Today it only does persistent notifications and notifications. I can look to add that in a future release.

AFAIK, the custom updater doesn’t support packages. Once it does, I can look at what it would take to add it.

While on the raw link, https://raw.githubusercontent.com/notoriousbdg/Home-AssistantConfig/master/packages/battery_alert.yaml, right click and click save as.

2 Likes

Thanks for the reply. The copy/paste wasn’t the issue. After some debugging, I found the problem.
The package has a conflict with the following line in configuration.yaml:
# automation: !include automations.yaml
For me this is an empty file because I use Node-RED.

hi @NotoriousBDG

I’ve seet this very very cool system up from your examples.
It works very very well, and gives me a lot of great info.
One thing though, ONE of my trådfri controllers (an on / off switch) does not show up on the overview.
I do see the warnings, I’ve changed batteries in it, but for some reason it’s still at 11% which is odd.
Looking in the states I see this:


This is from the battery alert overview.
So I’m a bit unsure on what to do now?
overview

Battery sensors don’t usually update immediately. Is it still showing 11%?

Hi there

Yes, I guessed that it didn’t update that frequent from the other items that has gotten new batteries, but it’s steady at 11%, and has been like that for weeks.

I had this same issue, and then realized I had changed ikea batteries… all from a new package. apparently they were practically depleted, although the expiry date wasn’t near. Changing to a bigger battery brand immediately made the difference…these sensors and switches update immediately after that. could that be the case in your setup too?

it is remarkable how quickly the Ikea sensors deplete their batteries, while the Philips sensors stay at 100% for over 2 years now…

Ok, swapped the batteries to Maxell, and it now shows 100% in the sensor.
But in the ‘battery monitor’ overview, I don’t see the battery sensor shown.


It also shows the battery sensor in the states:

But I don’t see it in the battery overview that was created originally, which I think is quite odd?

I seem to have lost the overview of the batteries that I monitor with this clever addition, is there an easy way to get it back?

Do you see any errors in the logs?

No, none, and the battery sensors are there, I do get warnings, I just don’t see the ‘overview’ card of all the sensors. Do I have to add them manually to a glance card, or?

Ok, I’ve gone through the configuration again.

I found that I didn’t have a mqtt: section any longer, so I readded that.

mqtt:
  broker: core-mosquitto
  discovery: true
  discovery_prefix: homeassistant

I’m not sure if that changes anything, but it looks like some of the controllers popped up that were missing.

Just to be clear, the ‘overview’ I’m talking about is this one:
overview
I’ve changed the Lovelace UI to my own setup, instead of the autogenerated, so I guss that could also be why it’s not showing?

Let me rephrase… have the settings in such a way that if you have a new version of the file and i download it, that i don’t have to put my settings in again. Perhaps if you have like a main package and do an include or set some vars. That way we only have to update the main package and the settings are kept. (or am i doing it wrong?) :slight_smile:

Yes, if you’ve customized Lovelace UI, then you’ll need to configure Lovelace to show them however you wish. Someone posted an example earlier in this thread that should make it easy. I don’t have any experience customizing Lovelace, so I can’t really offer much guidance.

You shouldn’t lose settings on upgrade unless there is a breaking change. What settings did you lose? Do you know which versions you upgraded from and to?

Ok, great, that was just what I wanted to know, the automatic showing only works for the non-customized UI.
So I found the post by @Three with the custom group-card, and that makes it show the sensors immediately, very nice, thankyou @Three
I can see I have quite a few dublets, so I guess I could delete them, and they will pop up again?
Looking in mqtt, I can see a lot of messages about deleting sensors, but I don’t see them being deleted?
This is one;

{ “entity_id”: “device_tracker.life360_adrian”, “battery”: “80”, “delete_battery_sensor”: “homeassistant/sensor/life360_adrian_battery” }

I haven’t sent this one, so it’s something the battery sensor thingy is trying to do itself. But I don’t see them being deleted?

EDIT: Hmm, not sure what happened, I just tried it again, deleting battery sensors, and now they are deleted perfectly, weird?
EDIT2: Ahhh, trailing spaces, when copying from the sensor view, it sometimes takes an extra space, and that will make it fail.