Think you need to clear up first of all what devices you’re trying to track here, those with a battery entity (such as a motion sensor) or those with a battery attribute (such as a mobile phone).
Have a look here at the screen shots of the two different types:
There’s method’s on here for both (trust me, took me a while to get my head around it all but got there!).
Have another crack at it and if it doesn’t work post your config back as that would help understand the problem…(and your use case that you’r e trying to answer).
No cause i tried your example…
I asked where to start and you give me a proposition so i tried that. without luck:)
Willy try the one from @jwelter now
I did clear up what devices to track and they are in a group now.
I do now the difference betwween battery entity and one with a battery attribute
edit: i can’t try the one from jwelter cause thats a script pointing to attributes, but for me the ones i want to track is an entity not an attribute, so it wont work…
sensor:
- platform: template
sensors:
low_batteries:
friendly_name: Low Battery Devices
unit_of_measurement: Entities
icon_template: "{{ 'mdi:checkbox-marked-circle-outline' if states('sensor.low_batteries')|int == 0 else 'mdi:alert-circle-outline' }}"
value_template: >
{%- set ns = namespace(counter=0) -%}
{%- set threshold = 10 -%}
{%- for item in expand('group.battery_levels') -%}
{%- if item.state | int <= threshold -%}
{%- set ns.counter = ns.counter + 1 -%}
{%- endif -%}
{%- endfor -%}
{{ ns.counter }}
attribute_templates:
matched_devices: >
{%- set threshold = 10 -%}
{%- for item in expand('group.battery_levels') -%}
{%- if item.state | int <= threshold -%}
- {{ item.name }} - {{ item.state }}|
{%- endif -%}
{%- endfor -%}
# When a battery in the group drops below a threshold count them.
# It also drops their name and current level in an attribute we use in the notify messages.
and my automation
- id: Lage batterij waarschuwing
alias: System - Low Battery Warning
trigger:
- entity_id: sensor.low_batteries
platform: state
for: 00:01:00
condition:
- condition: not
conditions:
- condition: state
entity_id: sensor.low_batteries
state: '0'
- condition: template
value_template: '{{ trigger.from_state.state != trigger.to_state.state }}'
action:
- data:
message: '{%- set ns = namespace(message = ''The battery level of the following
device(s) are low:\n'') -%} {%- set ns.message = ns.message + state_attr(''sensor.low_batteries'',''matched_devices'').split(''|'')
| join(''% \n'') -%} {{ ns.message }}'
title: '** Battery Level Warning **'
service: notify.mobile_app_nokia_7_plus
mode: single
Hi, your group is called battery_level_monitor but the sensor references battery_levels (I’ve tidied up an earlier post to make that clearer). These need to be the same.
If you’re only wanting entity batteries what you have there then should work. If you’re wanting to include attribute type ones at the same time as entity ones (and I’m sure they’re better ways to do it!) I would change your sensor configuration to be this one (click on the link to get the whole lot):
sorry, I assumed the phone battery was an attribute of the phone entity
Yes, you can do (not sure what I can do but will try ) - send a screen shot of the phone entity as well with its battery attribute to check there’s nothing funky on that!
I see. I have some issue with the trigger not firing, apparently. Running the condition and action in the Developer Tools gets “True” and several results. However, it is never firing.
Here is what I have so far, in the automation.yaml
- id: '1601512052928'
alias: Alert - Low Batteries
description: ''
trigger:
- at: '13:50:00'
platform: time
condition:
- condition: template
value_template: '"{%- set ns = namespace(message = false) -%} {%- set threshold
= 80 -%}{%- for item in states.sensor -%}{%- if "battery" in item.name | lower
and item.state | int < threshold and item.state|int != 0 -%}{%- set ns.message
= (true) -%}{%- endif -%} {%- endfor -%} {{ ns.message}}"'
action:
- data:
message: '"{%- set ns = namespace(message = "The battery level of the following
device(s) is low:\n") -%} {%- set threshold = 80 -%} {%- for item in states.sensor
-%} {%- if "battery" in item.name | lower and item.state | int < threshold
and item.state|int != 0 -%} {%- set ns.message = ns.message + " - " + item.name
+ " (" + item.state + ")\n" -%} {%- endif -%} {%- endfor -%} {{ ns.message
}}"'
title: Low Battery Alert
service: notify.mobile_app_moto_g_7
mode: single
I wrote a test automation that turns on a single light at 1:50pm and it worked fine, so I’m not sure what is going on this with this one. Ideas?
(Post edited…)
I’ve realised that this thread is about Notification on Low Battery Levels.
I was looking for a method to identify low battery levels and (as I should have realised) there are plenty of methods.
In case another newcomer stumbles upon this, here is a very simple solution that even I could implement:
(My original post was: Why on earth isn’t there an integration available that will monitor battery levels? Doesn’t everyone need this etc etc
just another naive newbie post )