Background
So after setting up sending SMS messages from my Raspberry Pi (see article here) and integrating this with my openHAB server installation (see article here) the next step is to setup an openHAB rule to send me an sms text when the UPS switches to battery power, and then again when UPS mains power is restored.
Adding rules to openHAB
A rule is required to pass a message text via the smstext and smssend items. The sms.rules rules then trigger an SMS text to be sent to my mobile phone.
$ nano /etc/openhab/rules/ups.rules
Add the following lines:
rule "Power outage"// set SMS text to be sent by ups.rule when the power switches to battery on mains losswhenItem ups_status changed from "OL" to "OB"thenlogInfo("UPS:", "UPS has switched to battery power")smstext.sendCommand("UPS: mains power outage")endrule "Power returned"// set SMS text to be sent by ups.rule when the power switches to mains on mains restorationwhenItem ups_status changed from "OB" to "OL"thenlogInfo("UPS:", "UPS has switched to mains power")smstext.sendCommand("UPS: mains power restored")end
Where OL is a status of the UPS as online and OB is on battery. I also added some information for log entries to the openHAB log.
Testing the openHAB rule
To test I simply remove the power connection to the UPS and voila I receive an SMS to my phone. Plugging it back in I receive another sms text.
Comments
Post a Comment