Check battery level

I like to get an notification when one of my devices get low battery.
I did check the internet and did found the next simple setup for checking all devices using “get entitities”
at attributes.battery_level
If i try by pushing the time stamp no results are shown?
It looks like there are no attributes with battery_level? but there are?

What am I doing wrong?

EDIT: I did found it allready. I was using the wrong Home Assistant server

1 Like

can you share the flow?

I did use this solution.
The only problem is, this is only working for Zwave devices.
Not for Zigbee devices:

https://www.reddit.com/r/homeassistant/comments/czqrk0/battery_check_for_ha_using_nodered/

Try this for “other” devices that have a battery as a state:

image

Make a separate flow for “these type of devices”.


`[{"id":"2cf21261.5d395e","type":"template","z":"ae9b31fa.990e9","name":"Battery msg","field":"payloadbattery","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"The battery level for the {{payload.attributes.friendly_name}} is at {{payload.state}}%","output":"str","x":550,"y":1300,"wires":[["6696d38a.0ed394"]]},{"id":"81582b29.b2e13","type":"ha-get-entities","z":"ae9b31fa.990e9","server":"c6b350c5.b8b3c","name":"","rules":[{"property":"attributes.device_class","logic":"is","value":"battery","valueType":"str"},{"property":"state","logic":"lte","value":"30","valueType":"num"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":351,"y":1300,"wires":[["2cf21261.5d395e"]]},{"id":"c6b350c5.b8b3c","type":"server","z":"","name":"Home Assistant"}]`
4 Likes

Thanks!
It works. I didn’t know how to check the state of the device_class.battery
Now I know :+1:

Mark solution for others… :slight_smile:

I tried, but there is no option to select as solution? (looking at the 3 dots but no checkbox)

I worked on the same topic for Zigbee devices. I add a sort the sensor by battery level.

[{"id":"8ca4e8d2.84ae3","type":"inject","z":"a9c3b74b.7a3168","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"86400","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":160,"wires":[["51bb149.aa40a6c"]]},{"id":"57dcc0ab.32cfd8","type":"api-call-service","z":"a9c3b74b.7a3168","name":"Notification: Low battery Warning","server":"31f480d3.0e3b28","version":1,"debugenabled":false,"service_domain":"notify","service":"mobile_app_phone","entityId":"","data":"{}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1740,"y":100,"wires":[[]]},{"id":"e42f9b8e.45e3a","type":"function","z":"a9c3b74b.7a3168","name":"Prep Notification","func":"msg.payload = \n{\n  \"data\": \n  {\n    \"title\": \"Low battery Warning\",  \n    \"message\": msg.payload\n  }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1470,"y":100,"wires":[["57dcc0ab.32cfd8"]]},{"id":"5eb6b271.52402c","type":"debug","z":"a9c3b74b.7a3168","name":"Low battery Warning","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1480,"y":220,"wires":[]},{"id":"f667d0b2.2f4b18","type":"sort","z":"a9c3b74b.7a3168","name":"Sort by battery level","order":"ascending","as_num":false,"target":"","targetType":"seq","msgKey":"","msgKeyType":"elem","seqKey":"payload.state","seqKeyType":"msg","x":860,"y":160,"wires":[["ce46c9e.8e8ac38"]]},{"id":"a57739fe.7143a","type":"split","z":"a9c3b74b.7a3168","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":670,"y":160,"wires":[["f667d0b2.2f4b18"]]},{"id":"51bb149.aa40a6c","type":"ha-get-entities","z":"a9c3b74b.7a3168","server":"31f480d3.0e3b28","name":"Sensors battery lower than 20%","rules":[{"property":"attributes.device_class","logic":"is","value":"battery","valueType":"str"},{"property":"attributes.battery","logic":"lte","value":"20","valueType":"num"},{"property":"entity_id","logic":"is_not","value":".+(_battery_level)$","valueType":"re"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":450,"y":160,"wires":[["a57739fe.7143a"]]},{"id":"f6ba2a6b.4dfa3","type":"join","z":"a9c3b74b.7a3168","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1250,"y":160,"wires":[["5eb6b271.52402c","e42f9b8e.45e3a"]]},{"id":"ce46c9e.8e8ac38","type":"function","z":"a9c3b74b.7a3168","name":"Prep message","func":"var sensor = msg.payload.attributes.friendly_name.replace(\" Battery\",\"\");\nmsg.payload = msg.payload.state + \"% for \" + sensor;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1080,"y":160,"wires":[["f6ba2a6b.4dfa3"]]},{"id":"31f480d3.0e3b28","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

There is my code on GitHub if it’s interest someone:

Hey, It works fine. Is there a way that i could exclude battery sensors from my phone/laptop and so on ?

Greets

I’ve done that in node red. Just excluded the friendly names:

Here is my full node red for this: https://pastebin.com/vKFcA6z3

4 Likes

Hi, thanks for sharing.
I’m a very big newbie with NodeRed.
Can you explain how can I reproduce this for my Xiaomi sensors?
Thanks a million
:beers:

Hi @Andre_Scala and @gidadavid

Sorry I missed your replies.

You need to play with the “get entities node” to list all your batteries.

Just remove battery propriety and check with the debug node what the output.
Without knowing the name, it’s hard to help you.

1 Like

worked great for me, thanks!!!