Script for UPS connected to MikroTik
Posted on 08 June 2025 by Mino — 2 min

Recently I discovered a package in RouterOS, which enables you to monitor connected UPS through USB cable. In this post I explain a simple script which sends an email if the electricity goes down.
MikroTik
Writing scripts on MikroTik is a useful feature to automate various tasks. Personally I have 3 scripts, one of which I will explain in a few sentences. Beside the UPS check, I also created a script for checkinf the expiration of my certificates, signed by my own CA (more information in this article) and the other checks if some of the required servers are up or not. This is done through checking the DHCP lease on the DHCP server (I know, this is not the most reliable way, but its the simplest and fastest one in certain conditions).
UPS
As my UPS I use CyberPower BR700ELCD, in which I replace battery every 2-3 years. I manually removed the beeper (warranty is out anyways for the past 5 years), because the sound it made was crazy, mainly if the power was not stable in the middle of the night.
Script
The script itself is run every minute and checks if the on-line
is set to false
. Probably I will also add a low-battery
or run-time-left
check in the near future, but for now this should be sufficient. If the on-line
is false
, then my router sends me an email to the address configured in the environment variables.
{
:global adminMail
/system/ups
:if (![get ups value-name=on-line]) do={
:tool e-mail send to=$adminMail subject="Not on-line UPS" body="Hello,\n\nThe UPS is not powered, remaining few minutes before power outage hits servers"
}
}
Some screenshots for easier configuration:
This configuration can be found under /system/scripts
in the WinBox.
This configuration can be found under /system/UPS
in the WinBox. I also downloaded all the extra packages (including the UPS package) from MikroTiks Website.
This post was written without the help of AI.