Rule for devices battery level ?
-
Hi
Wanted to create a rule for monitoring the battery level of Z-Wave devices on my Vera hub.
I can select the battery level as the trigger OK.
But not sure how to handle the Reaction to send an alert / notification ?
If in the triggers I have multiple devices monitored for their battery level
How could I create say a TTS announcement or text alert that mentions the name of the device who's battery level has dropped below 10% ? The device that has triggered the rule.
I'd rather not have to create an individual rule for each device etc.
Any ideas?
Thanks
-
toggledbitsreplied to cw-kid on Apr 11, 2021, 10:35 PM last edited by toggledbits Apr 11, 2021, 6:45 PM
@cw-kid One of my to-do list tasks for expressions is to be able to create a list of devices that match a test. Until that comes, you can just build your own array of battery-operated devices like this (lets call this
battery_device_list
) :Then, you can reduce that list to all of the devices that have battery < 10%:
That leaves you with an array of the entities that have low battery. Use another expression to convert that into a comma-separated list of entity names:
Your rule just checks to see if that
battery_low_names
(a string now) expression is not empty, and runs whatever notifications you want to run if it is not. You can include thebattery_low_names
variable in the text of your email or other notification, too. -
Thanks for the detailed reply. I will try and follow your suggestions.
So would these expressions be Global ones? Or ones within the rule?
Also as you don't natively support Telegram messenger I am not sure how I could insert the name of the device in to a HTTP request.
-
Its working I think, I set up the expressions as Global ones.
And my rules trigger is Expression value > battery_low_names > is NOT Null
As a test I have used the MSR internal Alert in the rules reaction
But I don't think I can insert ${{ battery_low_names }} in to a HTTP request for either Telegram messenger or TTS to Google Home speaker via Node-Red etc.
-
This works for me - having previously set up the accounts at CallMeBot.
The Request URL is: http://api.callmebot.com/text.php?source=web&user=@username&text=${{message}}
It just sends a text that is the content of message.
-
-
I seem to have a problem with my trigger however
Its triggering the reaction when I don't want it to do so.
I need to make the value of the expression "battery_low_names" null when no devices are below the battery level of 10% etc.
I've tried adding in a ? in to the expression but it doesn't seem to be working
join( each id in battery_low_list: getEntity(id)?.name, ', ')
EDIT:
This seems to work instead adding "? id: null" to the end of the expression.
join( each id in battery_low_list: getEntity(id).name, ', ') ? id: null
EDIT 2:
Maybe it doesn't work because now its not putting in the devices name in the expression value
EDIT 3:
I then tried changing the trigger altogether to this, but it doesn't work and becomes true anyway.
Likewise with this one:
Maybe there is a bug? All of these are going true and running the reaction when I expect them not to do that
-
toggledbitsreplied to toggledbits on Apr 12, 2021, 4:11 PM last edited by toggledbits Apr 12, 2021, 12:14 PM
@toggledbits said in Rule for devices battery level ?:
(a string now) expression is not empty,
Details.
Also these can be rule expressions, they do not need to be global.
-
Thanks I've changed the expressions to local rule ones instead and its all still working.
-
How can I make this rule re-trigger ?
Say I don't immediate go replace the battery on the device mentioned, can I have the rule run the alerts / notifications each day or week until I have done it and changed the batteries ?
Also can the alerts also state what the battery level percentage actually is ?
Thanks
-
@cw-kid said in Rule for devices battery level ?:
How can I make this rule re-trigger ?
Wrap the condition in a group and put the group in "pulse" output mode with the timing you want.
@cw-kid said in Rule for devices battery level ?:
Also can the alerts also state what the battery level percentage actually is ?
Yes, but I'm going to leave it as an exercise for the reader. Level of difficulty: moderate.
-
cw-kidreplied to Ian on Apr 14, 2021, 9:44 AM last edited by cw-kid Apr 14, 2021, 5:48 AM
Thanks Ian that works, my Telegram text message now has the number% at the end of the message now.
However this messes up the Google Home TTS announcement sent via node-red, if I have a "%" in the expression. So I had to change it to the word "percent" instead and now the TTS sounds correct when spoken.
join( each id in battery_low_list: getEntity(id).name + " " + "at" + " " + int(getEntity(id).attributes.battery_power.level * 100) + " percent", ', ')
-
@toggledbits said in Rule for devices battery level ?:
Wrap the condition in a group and put the group in "pulse" output mode with the timing you want.
Like this?
Seems to be working and the alerts are repeating every 60 seconds now. I will just set this to 24hrs I think.
-
@toggledbits said in Rule for devices battery level ?:
One of my to-do list tasks for expressions is to be able to create a list of devices that match a test.
This is very useful, is it released yet or still on the to-do list?
-
toggledbitswrote on Sep 26, 2021, 9:54 PM last edited by toggledbits Sep 26, 2021, 5:55 PM
Still on the to-do list, but I think I'm close to figuring out what I want it to do. These things get harder with time: the more people use them, the more etched in stone they become, so making a "first guess" and completely changing things later isn't really something I want to do a lot of. If I can get something good on the first try, that's the way...
Here's what I'm thinking...
First, the
matchEntities()
function would quickly narrow down the set, in a manner similar to the filters on the Entities page and the Entity Picker:living_room_sensors = matchEntities( { controller: 'vera', capability: [ 'binary_sensor', 'value_sensor'' ], group: 'Living Room' } )
This would return an array of entities. From here, you could use an
each
statement to further filter any deep refinements. This expression would take the above array of sensors in the Living Room and pick out those that are battery powered and have battery level under 50%:low_battery_living_room = each e in living_room_sensors: e.attributes.battery_power?.level <= 0.5 ? e : null
I'm liking this approach because the function could do the bulk reduction of potential hundreds of entities down to a manageable list, and then the final filtering of the list can be done with expressions for maximum flexibility.
Any thoughts about that?
-
@toggledbits That would do it for me, is the
matchEntities()
function already available in Expressions? I get no error but no matter what I do the Expression always returns an empty array.
I'd expect this to contain at least something:matchEntities( { controller: 'vera', capability: 'humidity_sensor' } )
-
No, it's not yet available.