Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request to add support for immediate alert on low battery #3

Open
ptr727 opened this issue Feb 12, 2022 · 3 comments
Open

Request to add support for immediate alert on low battery #3

ptr727 opened this issue Feb 12, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@ptr727
Copy link

ptr727 commented Feb 12, 2022

I'm using your low battery blueprint, thank you.
I'd like to request an option for immediate notification vs. scheduled.
By the time the level is tested the device may no longer have power, and this is critical for e.g. leak sensors.

@tykeal tykeal added the enhancement New feature or request label Feb 12, 2022
@tykeal
Copy link
Owner

tykeal commented Feb 12, 2022

Something tells me that you've got the alert threshold too low in that case. I run my thresholds at 40% for my house and 60% for my short-term rental properties. That gives me the alert that I need to know that the device is almost out of power and the time to make sure I've got the battery on hand.

Trying to run your monitoring alerts too close to the actual power drain point isn't a really good idea! I've been bitten many times by pretty much exactly what you're talking about.

I'll see if I can figure out how to do it, but I'm not actually the original author. All I did was reflow and yamllint the blueprint because the original author's version wouldn't work for me!

If you have some critical devices that you need immediate alerting on when their battery hits certain levels I would also suggest setting up some dedicated alerts on just those.

Finally, and this is from my experience of dealing with IoT batteries for 4+ years, there are many times I've encountered were I'll get an alert at my 60% threshold and the next day the device will be out of juice. Battery estimation, especially in these devices, tends to not be very precise. Additionally, the conditions of where the device are can affect it greatly too.

@ptr727
Copy link
Author

ptr727 commented Feb 12, 2022

I understand your position, although the further your writing progresses, the more you supported my point of the need for instant alerting :)

@tykeal
Copy link
Owner

tykeal commented Jul 16, 2022

I've been looking into this request off and on for a bit. Mostly in conjunction with some work I've been doing for an integration. Unfortunately, there is no way (that I can find) to setup a trigger condition on a variable amount of sensors. Templates used in trigger conditions are only evaluated during automation load. After that, they're set until the next reload.

This would make the automation not work as expected if you have a long running HA that you add a new battery powered sensor to without restarting as it would not be monitored for the instant alerting.

Having done some additional looking at this particular issue, there is a forum post related to what you're wanting here: https://community.home-assistant.io/t/automation-trigger-list-of-devices/212254/2

It's a bit old as it's from July - Aug of 2020.

I played a little bit with some templates to work on it a bit and you might want to consider setting up a template sensor that does something with the following logic (I've written this so you can stick it in the dev tools templating section)

{%- set bs = namespace(batteries=[]) -%}
{%- for s in states.sensor -%}
  {%- if state_attr(s.entity_id, 'device_class') == 'battery' and state_attr(s.entity_id, 'unit_of_measurement') == '%' -%}
    {%- if states(s.entity_id) | int <= 40 -%}
      {%- set bs.batteries = bs.batteries + [ s.entity_id ] -%}
    {% endif %}
  {%- endif -%}
{%- endfor -%}
{{ bs.batteries }}

With a template sensor like that you would be able to write a notification automation if the state of the sensor has any entries in the array.

Unfortunately blueprints don't allow you to define additional entities that are not part of the automation itself, outside of the inputs. So there is no way to create a blueprint based template sensor.

In any case, I'll keep this open for a bit longer to see if I can noodle up a way to do what you want, but it's still escaping me on how to do it via a blueprint without requiring folks to also create a special template sensor which sort of defeats the intent behind blueprints!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants