Low battery level detection & notification for all battery sensors

@itn3rd77 A very fair question and one I totally missed. Also - I had to learn where the logs are - thanks for that. Now in the below logs, I am real sure some errors were my first attempts at using your blueprint. These entries are from the System Log. Your help is appreciated!

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:285
Integration: Automation (documentation, issues)
First occurred: January 6, 2023 at 3:12:24 PM (184 occurrences)
Last logged: 9:39:44 AM

Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('exclude', OrderedDict([('entity_id', []), ('device_id', '6dc0eb59eaf6c2244bf1b463608d6e94')])), ('actions', [OrderedDict([('device_id', 'adb84ebfcbea70464b0f5eeb8b1412ee'), ('domain', ''), ('entity_id', '')])]), ('time', '15:03:00')]): Integration '' not found. Got <homeassistant.components.blueprint.models.BlueprintInputs object at 0xffffaee70ca0>
Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('time', '14:39:00'), ('actions', [OrderedDict([('device_id', 'adb84ebfcbea70464b0f5eeb8b1412ee'), ('domain', ''), ('entity_id', '')])])]): Integration '' not found. Got <homeassistant.components.blueprint.models.BlueprintInputs object at 0xffffa7a9e9b0>
Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('day', 0), ('time', '14:47:00'), ('actions', [OrderedDict([('device_id', 'adb84ebfcbea70464b0f5eeb8b1412ee'), ('domain', ''), ('entity_id', '')])])]): Integration '' not found. Got <homeassistant.components.blueprint.models.BlueprintInputs object at 0xffff83dc7c40>
Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('time', '14:52:00'), ('actions', [OrderedDict([('device_id', 'adb84ebfcbea70464b0f5eeb8b1412ee'), ('domain', ''), ('entity_id', '')])])]): Integration '' not found. Got <homeassistant.components.blueprint.models.BlueprintInputs object at 0xffff86185000>
Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('exclude', OrderedDict([('entity_id', []), ('device_id', '6dc0eb59eaf6c2244bf1b463608d6e94')])), ('actions', [OrderedDict([('device_id', 'adb84ebfcbea70464b0f5eeb8b1412ee'), ('domain', ''), ('entity_id', '')])]), ('time', '15:03:00')]): Integration '' not found. Got <homeassistant.components.blueprint.models.BlueprintInputs object at 0xffff7e525870>

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:248
Integration: Automation (documentation, issues)
First occurred: January 6, 2023 at 3:03:59 PM (4 occurrences)
Last logged: January 6, 2023 at 3:04:02 PM

Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('time', '14:39:00'), ('actions', [OrderedDict([('device_id', 'adb84ebfcbea70464b0f5eeb8b1412ee'), ('domain', ''), ('entity_id', '')])])]): Integration '' not found. Got <homeassistant.components.blueprint.models.BlueprintInputs object at 0xffff97cb0610>
Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('day', 0), ('time', '14:47:00'), ('actions', [OrderedDict([('device_id', 'adb84ebfcbea70464b0f5eeb8b1412ee'), ('domain', ''), ('entity_id', '')])])]): Integration '' not found. Got <homeassistant.components.blueprint.models.BlueprintInputs object at 0xffff97cb09a0>
Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('time', '14:52:00'), ('actions', [OrderedDict([('device_id', 'adb84ebfcbea70464b0f5eeb8b1412ee'), ('domain', ''), ('entity_id', '')])])]): Integration '' not found. Got <homeassistant.components.blueprint.models.BlueprintInputs object at 0xffff97cb0940>
Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('exclude', OrderedDict([('entity_id', []), ('device_id', '6dc0eb59eaf6c2244bf1b463608d6e94')])), ('actions', [OrderedDict([('device_id', 'adb84ebfcbea70464b0f5eeb8b1412ee'), ('domain', ''), ('entity_id', '')])]), ('time', '15:03:00')]): Integration '' not found. Got <homeassistant.components.blueprint.models.BlueprintInputs object at 0xffff97b7d600>

Looks Like you are not using my version of the Blueprint:

My version is no longer dealing with day as integer or devices in exclude. Which was the URL you used for the Blueprint?

1 Like

Hi,

i have tested the blueprint with notify.persistent_notification and i don´t get anymore errors in the LOGs

is there a possibility you can help with the telegram notification?

This is the automation with the errors in the LOG when NO entities are below the set threshold of 30%

alias: Low battery detection
description: Low battery detection
use_blueprint:
  path: itn3rd77/low-battery-detection-notification.yaml
  input:
    order: name
    threshold: 30
    time: "12:00:00"
    exclude:
      - sensor.sm_g973f_battery_level
      - sensor.sm_t510_battery_level
    actions:
      - service: notify.ha_message
        data:
          title: Batterie LOW
          message: " {{sensors}}"
    message: "[% bullet %] [% sensor %] ([% state %]%)"

and this is the automation where NO errors are thrown when when NO entities are below the set threshold of 30%

alias: Low battery detection
description: Low battery detection
use_blueprint:
  path: itn3rd77/low-battery-detection-notification.yaml
  input:
    order: name
    threshold: 30
    time: "12:00:00"
    exclude:
      - sensor.sm_g973f_battery_level
      - sensor.sm_t510_battery_level
    actions:
      - service: notify.ha_message
        data:
          title: Batterie LOW
          message: " TEST {{sensors}}"
    message: "[% bullet %] [% sensor %] ([% state %]%)"

so the only change i made was, i changed the message
from message: "{{sensors}}" to message: " TEST {{sensors}}"

i think the problem is when no entities are below the set threshold the automation or blueprint are trying to send a notification with nothing in the message field.

possible solution in my opinion as a noob

if there are no entities below the set threshold don´t even send a notification

Home Assistant 2023.1.1
Supervisor 2022.12.1
Operating System 9.4
Frontend 20230104.0 - latest

In normal operations mode e.g. when the automation is triggered by time NO notification is send when there a no entities below the treshold. Are you manually executing the automation and get this error? If you exectute the automation manually no conditions are evaluated from Home Assistant and one condition is “Do not send a notification if the message aka {{sensors}} variable is empty”.

Please test in normal operations mode and report back if there are still errors.

you are right, under normal operations mode e.g. when the automation is triggered by time NO notification is send when there a no entities below the threshold.

now i tested under normal operation mode triggered by time and raised the threshold to 50% for testing,

i have three entities below 50% and now i am getting this error in the LOGs with telegram notification

2023-01-08 10:28:00.303 ERROR (SyncWorker_1) [homeassistant.components.telegram_bot] Error sending message: Can't parse entities: can't find end of the entity starting at byte offset 20. Args: (1051552721, 'Batterie LOW\n⦿ Bad_OG Battery Level (49%)\n⦿ Office Battery Level (46%)\n⦿ Wohnzimmer Battery Level (46%)'), kwargs: {'parse_mode': 'Markdown', 'disable_web_page_preview': None, 'disable_notification': False, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}

with notify.persistent_notification i do not get an error

I would suggest you start with simple text messages and see if this works. Than move up in little steps to see when it failes.

For “Bullet point icon” I would start with an dash “-” and “Detection message” e.g. with the fixed word “Test”. If that works replace “Test” with just “[% sensor %]” and so on …

1 Like

my issue is apparently in the Detection message all parameters work except for the [% sensor %]

the parameters [% bullet %] ([% state %]%) are working but [% sensor %] not

this is how it looks now unfortunately without the name of the sensor which needs a battery replacement

The original author mentioned someting like this:

Some notification providers (e.g. Telegram) expect messages to be valid Markdown. It may help to repace underscore possible underscore characters e.g. using {{sensors|replace("_"," ")}} instead of just {{sensors}}.

i tried to replace {{sensors}} with {{sensors|replace("_"," ")}} but now it does not let me to save it

Looks like a quoting problem. The message should probably look like this: "{{sensors|replace(\"_\",\" \")}}"

3 Likes

THANK YOU!!!

Now it works perfect, all problems solved

@itn3rd77 Wierd. I started here: Automated low battery warnings in under 5 minutes for Home Assistant » The smarthome journey, which led me to here: Low battery level detection & notification for all battery sensors.

And I went here: Github Gist: Home Assistant Blueprint: Low battery level detection & notification for all battery sensors · GitHub

Then on that page to this:

Blueprint Code

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

and installed / imported the blueprint.

Ah - I think I see the problem. I am sure this has happened before…I am need to pay more attention to “who” I am talking to. :flushed: oops! My bad. I will counsel myself in a bit.

That being said - I should use the “My Blueprint” you list in post 231? Yes?

And best to delete the prior install, restart HA and then install your blueprint and start again - yes?

Thanks for confirming. I did that and it works very well, but was wondering if there was a simpler option.

I’m still a newbie on Home Assistant :slight_smile:

@itn3rd77 Am I on the right track here? Thanks !

Not sure what {{sensors}} contains exactly.

What I currently get for {{sensors}} (example): Light sensor EG Kitchen Battery (36 %), Multi sensor OG Bath Battery (72 %)

What I want: get rid of the unnecessary repetitive Battery, which is part of the friendly_name.

  1. Can I achieve that using {{sensors|replace("Battery","")}} ?
  2. Are multiple replaces possible?

@itn3rd77 Blueprint working fantastic. I noticed that I still get notification of my son’s phone even though it’s charging. Is that intended or can it be mended somehow to where if a device is being charged the automation skip it?

Generally you want to exclude phones and other devices that get regularly charged. This Blueprint is really intended to monitor sensors with batteries that need replacing when they run low.

1 Like

Hi,

I’m currently running into issues as some entities don’t have a device_class attribute:

UndefinedError: ‘homeassistant.util.read_only_dict.ReadOnlyDict object’ has no attribute ‘device_class’

By rejecting those enities with missing attributes as suggested in How to handle missing attribute on some entities (binary_sensors) and avoid the UndefinedError I modified the blueprint a bit so it works correctly for my setup:

{% for state in states.sensor | rejectattr('attributes.device_class', 'undefined') | selectattr('attributes.device_class', '==', 'battery') -%}

I created a fork for those who face similar issues: Home Assistant Blueprint: Low battery level detection & notification for all battery sensors · GitHub

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Cheers,
Roman

2 Likes

It is best to send sensors (entitiy) name enclodes in backtick as preformatted text, otherwise special characters in entitiy name will format the Telegram Message like underscore → italic:

message: 'The battery of the sensor(s) `{{sensors}}` is low.'

Telegram Text Format Reference: Telegram Bot API

Example:
grafik

@itn3rd77 Just following up to make sure I am on the right track. Your assistance is appreciated.