Set exclude to an empty list [ ] (e.g. remove exclude0 … exclude9) and replace threshold with some number, e.g. 20 or something higher. 101 should give you all sensors.
I just got the same problem: I receive a notification (on my phone from the android application), but no sensor name in it.
I’ve tried with debug template, seems like results are correct : nothing in my case for 20%, and 2 “Battery_123xyz” for 30% but testing script with a 30% threshold still give no sensors (tried replacing underscores and without).
Could you please in the Automation Settings for the automation from this blueprint click on the 3 dots and select Edit as YAML and post the results here?
Can you try instead of a device action instead using “Call Service” with service notify.mobile_app_… and then putting the message there with the {{sensors}} variable?
In the data section you can put: message: 'The battery of the sensor(s) {{sensors}} is low.'
Hum… No, nothing in logs unfortunately
Since I’m discovering HA since a few days only; I cannot exclude I have setup issues, most of my existing sensors has been discovered but not set up at all yet (mainly because I’m not able to differentiate them all ).
Let me know if I can provide extra information; I’ll certainly take another look later. Thank you very much anyways, and merry x-mas!
Instead of listing out 10 sensor inputs to exclude, couldn’t you just use a single target selector since that collects a list of entities of a specific type. Or I guess two target selectors, one for sensors to exclude and one for binary sensors to exclude.
I tried to but couldn´t get it to work. Do I need do copy&paste the whole raw code?
Maybe you can provide the code I have to paste filled with all the variables.
At least it´s not just me so maybe there´s a bug in the blueprint.
You need to copy the pointed code but adapt it a bit. Try with this, change threshold variable according to your needs:
{% set result = namespace(sensors=[]) %}
{% set exclude = [] %}
{% set threshold = 20 %}
{% for state in states.sensor | selectattr('attributes.device_class', '==', 'battery') %}
{% if 0 < state.state | int < threshold | int and not state.entity_id in exclude %}
{% set result.sensors = result.sensors + [state.name] %}
{% endif %}
{% endfor %}
{% for state in states.binary_sensor | selectattr('attributes.device_class', '==', 'battery') | selectattr('state', '==', 'on') %}
{% if not state.entity_id in exclude %}
{% set result.sensors = result.sensors + [state.name] %}
{% endif %}
{% endfor %}
{{result.sensors|join(', ')}}
About the issue itself, I’ve worked on my sensors configuration, names I see in debug seems to be the correct ones, but notification still miss them.
Also, with a 20% threshold, I have no results (I can confirm with debug results) but notification is sent.
I need to apologize: the blueprint is working as intended:
When I set the treshold to e. g. 90 % and trigger the automation, the devices/sensors below that treshold are reported in the notification message.
BUT when I set treshold to 20 % (or a level lower than current devices/sensors states) and trigger the automation manually I get the notification with empty text "Low battery warning for: " as reported in Low battery level detection & notification for all battery sensors
So the question is: is this a normal behaviour of automations triggered manually --> do they always run even the conditions are not met? I think so because I did not receive any notification during the last days when the automation was run at set time daily.
No problem, thanks for the reply. Yes, when manually triggering through the UI, conditions are ignored by default. You can trigger automations manually with conditions in Developer Tools - Services using skip_condition: false.
You are actually correct. I wasn’t sure if it was possible to “abuse” the target selector but I managed to find a way. Therefore last version removes the 10 input selectors again and instead adds a target selector for exclusion instead.
If you are updating the blueprint and had excluded sensors before please add them again using the “Pick Entities” button.
Also, one other small suggestion. The int filter accepts a parameter of a default number. This number is what it returns when asked to convert a non-numeric value to an integer.
So with that you can change this
if 0 < state.state | int < threshold | int
To this
if 0 <= state.state | int(-1) < threshold | int
This way it will only skip alerting you non-numeric sensors with type battery and not for battery sensors with a dead battery