Posting a simple technique in the hope it’s helpful to others
(I feel guilty benefiting from the content here but have not contributed)
I have many (Xiaomi) motion sensors, door sensors, window sensors and buttons around the house
8 of these are important to the automation within my house - I don’t want them to stop working
These sensors all have a little 2032 battery which lasts a long time (a year or more) but I would like to be alerted when the battery is low
These items all have a lowBattery channel that you can code a rule to process/warn/notify
This would result in a lot of duplicated code (which is also a maintenance hassle)
Here is a way to simplify the solution with less code
This introduces a code reuse mechanism (like a subroutine or object method)
- Define an abstract string item
This will be used to receive low battery warning messages
String LowBatteryWarn "Low battery warning handler (non interactive)"
- Define a rule to process low battery warning messages
rule "LowBatteryWarn handler"
when
Item LowBatteryWarn received command
then
var String Msg = "Low battery warning: " + LowBatteryWarn.state.toString()
sendNotification("joe@mail.com", Msg, "lowBattery", "Alert") // to myopenhab.org & mobile
logWarn("lowBattery", Msg)
say(Msg) // Output to google home speaker
end
- For each device define a one line rule to process low battery events
These rules merely set the LowBatteryWarn item string to a message
The LowBatteryWarn item rule will process it as per your requirements/implementation
Make sure each rule has it’s own unique name!
(I’ve only published a subset of my low battery warnings to keep this post shorter)
rule "Front Door - Low battery warning"
when
Item MiMagnet_Front_BattLow changed from NULL to ON
or
Item MiMagnet_Front_BattLow changed from OFF to ON
then
LowBatteryWarn.sendCommand("Front door open/closed sensor")
end
rule "Motion UpStairs - Low battery warning"
when
Item MiMotion_UpStairs_BattLow changed from NULL to ON
or
Item MiMotion_UpStairs_BattLow changed from OFF to ON
then
LowBatteryWarn.sendCommand("Upstairs motion sensor")
end
rule "Temp Bedroom - Low battery warning"
when
Item MiTemp_Bedroom_BattLow changed from NULL to ON
or
Item MiTemp_Bedroom_BattLow changed from OFF to ON
then
LowBatteryWarn.sendCommand("Bedroom temperature sensor")
end
Hope that helps the community