Low battery level detection & notification for all battery sensors

Sorry !
No sensor Names are included in the message!, no error in the log!

Thanks will test👍

Ah, okay. Thanks for the clarification. I used “Action type”: Device and chose my cell phone instead of selecting Call service which is not so intuitive (for beginners).

However, after using Call service instead, I still get the same error in the log:

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:517
Integration: Automation (documentation, issues)
First occurred: 10:02:09 PM (2 occurrences)
Last logged: 10:02:09 PM

Blueprint Low battery level detection & notification for all battery sensors generated invalid automation with inputs OrderedDict([('day', '0'), ('actions', [OrderedDict([('service', ''), ('data', OrderedDict([('message', 'Low battery warning for: {{sensors}}')]))])])]): Service does not match format <domain>.<name> for dictionary value @ data['action'][0]['default'][0]['service']. Got None

This is the automation:

use_blueprint:
  path: sbyx/low-battery-level-detection-notification-for-all-battery-sensors.yaml
  input:
    day: '0'
    actions:
      - service: notify.mobile_app_master_iphone_7
        data:
          title: '{{ now().strftime("%H:%M") }} Low battery'
          message: 'Low battery warning: {{sensors}}'
    threshold: '30'
    time: '15:00:00'

Any more suggestions?

1 Like

You can also use the notification via device menu. I am just guessing what has gone wrong from the error message which was indicating that no service was set at all. But that doesn’t match with your input which looks correct? Is that error log still relevant for your current config or just outdated?

Yes, the notification works perfectly fine, both with Devices and Call Service. However, still the error is there in the log after restarting HA. Every time.

I have tried to delete the blueprint via the GUI and added it again, but still the same error.

Looks like there is some leftover automation in your automations.yaml that is causing this.

You were right. For some reason (bug?), it was 3 blocks with “Low battery level…” automations in the file automations.yaml, but in the GUI it was only one. The other two had empty settings on the things that generated the error. After removing them manually with File editor, the errors went away.

Thank you for your suggestions that led to fixing the errors!

@Sbyx Thanks for this really helpful blueprint. I love it.

I have one issue though. I have added my computer and phone to the exclude list. However, when the automation is triggered, I still receive the battery status of my computer and phone.

How can I prevent them from being send?

Edit: whoops, never mind. I used a device instead of entity. It’s working fine! :slight_smile:

1 Like

I am trying to understand your code, but I can’t wrap my head around the above part. What does it do? How should I read it?

As I see it, you check to see if 0 is smaller or equal to state.state. Why would you want 0 == 0? If you have no states, why even bother to continue,

This is inside a loop being tested for all battery-class sensors. If the state value state.state converted to a number | int lies within a range of 0 and the configured threshold (inclusive) then the following line is applied (adding name and value to the list of low-battery sensors). The -1 is a fallback for when the sensor state is not a number for some reason.

Ok, now I see. :slight_smile: Not used to seeing a lot of Yaml code, so sometimes the formatting is a little confusing. But I see what you are doing now. Thanks for explaining.

Nice work. I am loving this whole blueprint thing.

I wonder would it be possible to perhaps add an option to format the {{sensors}} string? So that for example instead of the following appearing in for example a notification:

sensor-name, sensor-name, sensor-name, sensor-name

we might have instead:

sensor-name
sensor-name
sensor-name
sensor-name

Makes it a bit easier to read in a notification.

Although while typing this, I realise I’m getting the big long, hard to read string because I’m setting the battery threshold to 95% in order to get some results during testing. In reality, low batteries would perhaps only occur singly. So this is perhaps a problem that doesn’t really need a solution!

Anyway, great work. Thanks again.

@walkie You can do that change without modifying the blueprint. Instead of {{sensors}} just use {{sensors|replace(", ", "\n")}}

5 Likes

Of course! Should have thought about it. Thank you.

Nice blueprint thank you @Sbyx.

Hi all, I’ve some problems with this BP
“unknown tag !<!input> at line 54, column 20:
day: !input ‘day’”

No issue in HA but only in BP
Could you help me?
Thanx

Nice blueprint, glad this is here now. HA is a still a very steep learning curve for me so these blueprints help alot.
Can i ask if i want to change this blueprint so i can use it to read the moisture sensor for my mi flower, what do i have to change in the yaml file?

1 Like

Well the approach here makes sense if you have many sensors of the same type otherwise a simple automation makes more sense. How many are we talking about? Also you would need to check the state and attributes over the sensor (e.g. via developer tools - states)

For now i have 2 sensors working but i have many more laying around and gonna use when some plant shops are open haha. Would be nice if it works like your automation so i dont have to make seperate automations but then for moisture.

last_successful_update: '2021-01-16T22:16:19.963891+00:00
unit_of_measurement: '%
friendly_name: Dracaena Marginata Moisture
icon: 'mdi:water-percent

sensor.dracaena_marginata_moisture

You can make a normal automation with a trigger like this (taken from one of my automations):

trigger:
  - entity_id:
      - climate.000a9a499967c4
      - climate.000a9a499ef987
      - climate.000a9a499ef9de
      - climate.000a9a499efc3b
      - climate.000a9a499efc5f
      - climate.000a9a499efc75
      - climate.000a9a499efc98
      - climate.000a9a499efc9f
      - climate.000a9a499efd6d
      - climate.000a9a499efd82
      - climate.000a9a499efe71
    platform: numeric_state
    below: '20'

And then you can use {{ state_attr(trigger.entity_id, 'friendly_name') }} to get the sensor / entity that was actually triggering.

2 Likes