Community discussions

MikroTik App
 
Josephny
Long time Member
Long time Member
Topic Author
Posts: 665
Joined: Tue Sep 20, 2022 12:11 am

UPS monitor voltage script

Mon Oct 21, 2024 11:24 pm

Using the command:
/system ups monitor 0
I see "line-voltage"

as well as lots of other data.

And, when the line voltage drops, I can see log entries:
USB UPS AC power on
I would like to see how low the line voltage dropped during those times. And, ideally, the line voltage every second (or 1/2 second) during the period when the UPS was "on-battery"

Is there a way to record and log this directly, or using a script?

Thank you.
 
NetWorker
Member Candidate
Member Candidate
Posts: 111
Joined: Sun Jan 31, 2010 6:55 pm

Re: UPS monitor voltage script

Tue Oct 22, 2024 12:33 am

I'm supposed to be on my way home already so I'm not going to write it for you.

But I'd do it like this:

:if(ups on battery) do={:log voltage}

Then add it to the scheduler and run it every 00:00:01.

Note that this will be a resource hog and will fill a 1000 entries long log in 15 minutes. Setting the scheduler to every 5 seconds will lessen the impact on the cpu somewhat and allow for about an hour worth of readings.
 
Josephny
Long time Member
Long time Member
Topic Author
Posts: 665
Joined: Tue Sep 20, 2022 12:11 am

Re: UPS monitor voltage script

Tue Oct 22, 2024 2:01 am

I'm supposed to be on my way home already so I'm not going to write it for you.

But I'd do it like this:

:if(ups on battery) do={:log voltage}

Then add it to the scheduler and run it every 00:00:01.

Note that this will be a resource hog and will fill a 1000 entries long log in 15 minutes. Setting the scheduler to every 5 seconds will lessen the impact on the cpu somewhat and allow for about an hour worth of readings.
my problem is I can't find/get the voltage data from the command line
 
Josephny
Long time Member
Long time Member
Topic Author
Posts: 665
Joined: Tue Sep 20, 2022 12:11 am

Re: UPS monitor voltage script

Tue Oct 22, 2024 2:18 am

No "line-voltage"
[admin@371hEX] /system/ups> print proplist=
Flags: X - disabled; I - invalid 
 0    name="ups1" port=usbhid1 offline-time=0s min-runtime=never 
      alarm-setting=immediate 
      model="Back-UPS RS 700G FW:856.L8 -P.D USB FW:L8 -P" serial="0B2252N07530" 
      manufacture-date="2022-12-22" load=8% on-line=yes 
      nominal-battery-voltage=12V 

But, in winbox:
You do not have the required permissions to view the files attached to this post.
 
tdw
Forum Guru
Forum Guru
Posts: 1999
Joined: Sat May 05, 2018 11:55 am

Re: UPS monitor voltage script

Tue Oct 22, 2024 3:04 am

It isn't a property. As an aside I'm not sure why load appears in both properties and monitor values, logically it would only be in the latter with the other measured data.

To display from the command line :put ([/system/ups/monitor 0 once as-value]->"line-voltage")

If you wish to access multiple values store the monitor output in a variable, you can then reference the array elements by name as required.
 
Josephny
Long time Member
Long time Member
Topic Author
Posts: 665
Joined: Tue Sep 20, 2022 12:11 am

Re: UPS monitor voltage script

Tue Oct 22, 2024 3:19 am

It isn't a property. As an aside I'm not sure why load appears in both properties and monitor values, logically it would only be in the latter with the other measured data.

To display from the command line :put ([/system/ups/monitor 0 once as-value]->"line-voltage")

If you wish to access multiple values store the monitor output in a variable, you can then reference the array elements by name as required.
Wow!

Works perfectly.

Any chance you'd explain what this means:

"[monitor 0 once as-value]->"line-voltage"

I'm thinking it's calling on the monitor's array and seeking just the value in the array called "line-voltage" but that is the extend of my (mis-)understanding.
 
Josephny
Long time Member
Long time Member
Topic Author
Posts: 665
Joined: Tue Sep 20, 2022 12:11 am

Re: UPS monitor voltage script

Tue Oct 22, 2024 4:52 am

I have the following working:

:local voltage (([/system ups monitor 0 once as-value]->"line-voltage")/100)

:log info $voltage

But when I include a test for "on-battery" being "true" the script does not work. I wonder if it is a simply syntax error or if I need to convert the array output type (maybe :tostr)?
:if (([monitor 0 once as-value]->"on-battery") = "true") do={

    :local voltage (([/system ups monitor 0 once as-value]->"line-voltage")/100)
    :log info $voltage
}
However, I still need a way for this script to be triggered when there is a UPS "event," so it does not have to be run every x seconds.
 
xrlls
Frequent Visitor
Frequent Visitor
Posts: 85
Joined: Sun Jan 13, 2019 4:43 pm

Re: UPS monitor voltage script

Tue Oct 22, 2024 7:54 am

Do your UPS offer the “on-battery” field? While I see it mentioned in the documentation, https://help.mikrotik.com/docs/spaces/ ... 324130/UPS, my little experience is that the actual UPS implementation on Mikrotik deviates a lot from the documentation. Some of it may be due to the exact model, but some of it is just different.

Anyway, with my BackUPS BX750, I do not see a lot of the fields mentioned in the documentation, including “on-battery”. Instead, I understood the “on-line” field as meaning whether the UPS is operating on AC or battery, but I have only tested with a full disconnect, not partially dropping supply voltage.

As for triggering. MikroTik only supports polling for the vast majority of functionality, except a few cases like DHCP events and MQTT subscriptions.
 
Josephny
Long time Member
Long time Member
Topic Author
Posts: 665
Joined: Tue Sep 20, 2022 12:11 am

Re: UPS monitor voltage script

Tue Oct 22, 2024 12:00 pm

Do your UPS offer the “on-battery” field? While I see it mentioned in the documentation, https://help.mikrotik.com/docs/spaces/ ... 324130/UPS, my little experience is that the actual UPS implementation on Mikrotik deviates a lot from the documentation. Some of it may be due to the exact model, but some of it is just different.

Anyway, with my BackUPS BX750, I do not see a lot of the fields mentioned in the documentation, including “on-battery”. Instead, I understood the “on-line” field as meaning whether the UPS is operating on AC or battery, but I have only tested with a full disconnect, not partially dropping supply voltage.

As for triggering. MikroTik only supports polling for the vast majority of functionality, except a few cases like DHCP events and MQTT subscriptions.
I'm using the BACK-UPS RS 700G and ROS has data in the fields "on-battery" and "on-line"

My guess is that on-battery means that the line (input) voltage is below a threshold and the UPS' battery is supplying the power; on-line means that the line voltage is sufficiently high. (Just a guess.)

I think that the available data varies across makes and models of UPS devices.

For example, I have another site with a model EC850LCD and issuing the command:

:put  ([/system/ups/monitor 0 once as-value]->"on-battery") 
Does not show anything (as opposed to showing "false" or "true").

But:
:put  ([/system/ups/monitor 0 once as-value]->"on-line") 
shows "true"

And:
:put ([/system/ups/monitor 0 once as-value]->"line-voltage") 
works for both models.

At yet another site, I'm using a model CP1500PFCLCDa. Here's values available include "on-line," "line-voltage" and "load" but not "on-battery" or "battery-voltage"

For my specific interest, I don't a good solution available to monitor line-voltage at times when the UPS changes to on-battery because of the need to executed a script so very often.
 
NetWorker
Member Candidate
Member Candidate
Posts: 111
Joined: Sun Jan 31, 2010 6:55 pm

Re: UPS monitor voltage script

Tue Oct 22, 2024 5:27 pm

For what it's worth, I researched the topic of UPS facility in Mikrotik years ago and haven't revisited the subject much. I've settled on having smart upses be used as dumb ones and only use the UPS facility in Mikrotik for the occasional peek at what it is doing.

The reason for why Mikrotik deviates from its own documentation is not on Mikrotik but on APC. Over the years, different models use different protocols (mind you these are proprietary protocols for which Schneider releases little to no documentation) and different models report different variables and field names.

The UPS facility is Mikrotik's best effort at incorporating a way of reading all the different signalling and it works surprisingly well for the most part. What I would really have liked to see is the "reboot" command incorporated for those UPSes that support it. But I understand that Mikrotik have basically given up on this as it is a really big effort for a really small userbase. And that said effort is better spent on other facilities and features for which there's a far higher demand.

Back on topic, you'll need to adapt the script for whatever your make and model UPS is reporting. Some will report "online" when running on mains and not report "on battery" at all. They just stop reporting "online". Others don't report "online" but will report "on battery" when running on batts. Again, this isn't Mikrotik's fault but APCs on how their different models signal.
 
Josephny
Long time Member
Long time Member
Topic Author
Posts: 665
Joined: Tue Sep 20, 2022 12:11 am

Re: UPS monitor voltage script

Tue Oct 22, 2024 5:51 pm

For what it's worth, I researched the topic of UPS facility in Mikrotik years ago and haven't revisited the subject much. I've settled on having smart upses be used as dumb ones and only use the UPS facility in Mikrotik for the occasional peek at what it is doing.

The reason for why Mikrotik deviates from its own documentation is not on Mikrotik but on APC. Over the years, different models use different protocols (mind you these are proprietary protocols for which Schneider releases little to no documentation) and different models report different variables and field names.

The UPS facility is Mikrotik's best effort at incorporating a way of reading all the different signalling and it works surprisingly well for the most part. What I would really have liked to see is the "reboot" command incorporated for those UPSes that support it. But I understand that Mikrotik have basically given up on this as it is a really big effort for a really small userbase. And that said effort is better spent on other facilities and features for which there's a far higher demand.

Back on topic, you'll need to adapt the script for whatever your make and model UPS is reporting. Some will report "online" when running on mains and not report "on battery" at all. They just stop reporting "online". Others don't report "online" but will report "on battery" when running on batts. Again, this isn't Mikrotik's fault but APCs on how their different models signal.
Thank you very much for the detailed explanation and analysis. It makes perfect sense.

In line with the small user base who would greatly want the full smart UPS facilities, my need is not particular great.

I noticed some log entries showing "on battery" (or such) and thought 'I wish I knew exactly what happened to the voltage at the time.

I can easily move on to any number of other projects/problems/ideas/etc.

Thanks again.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], martinclaro and 33 guests