UPS and Safety Monitor

Hi Chris,

I think I found a good way to read the UPS status in a generic way. In the Windows EvenViewer the UPS logs its events:

  • When power fails and UPS switches to battery, the UPS sets event-id 174 (Battery backup transferred to battery power due to a blackout)
  • When power is restored and UPS is happy again, it sets event-id 61455 (Battery backup transferred to AC utility power.)

The only part being not generic are these two event-ids, but those can be read in the EvenViewer (pull the net-plug and insert again after a few seconds, run eventvwr from the taskbar, in the Event Viewer go to Windows Logbooks -> Application and look for the events left by the UPS.

So if you can read those events and could make two fields in the Generic Driver where the SGP user can enter these event-ids for power loss (I call it “almost-unsafe”, see below) and safe?
It would then be nice to have a third field with a configurable delay in minutes after which SGP should run End-Of-Sequence (EOS) options. On power loss the Safety Monitor should remain safe, but internally turn to almost-unsafe. If event-id 61455 is logged before the end of the delay, no action should be taken (Safety Monitor remains safe throughout the power loss and reverts from the internal almost-unsafe mode to safe). If the delay time expires without power being restored Safety Monitor can move from almost-unsafe to unsafe to allow EOS options.

If this is possible the following set-up should perform a proper shutdown:

  • Set-up the UPS to stay alive as long as possible;
  • Check how long the UPS will support the observatory at the current power consumption (e.g. 25 minutes) and at what time before batteries are drained the UPS will perform shutdown (e.g. 7 minutes);
  • Suppose we need 5 minutes to run EOS options, we set-up Safety Monitor to set the unsafe-trigger after 25-7-5 = 13 minutes of power loss (or a little less to stay on the safe side).

In this way EOS options are run 15 minutes after power loss, unless power is restored before this time. Once the EOS options run there is no point in reverting to safe-mode when power is restored, as SGP has already stopped the sequence and (partially) disconnected equipment.

Question of course is: is it possible to implement the above (so to monitor the eventlog)?

Nicolàs

Thanks for the event log info.

I’ve had a look at the event log on my laptop and can see events when I turn the power off and on. I get two System events each time:

  • Event 105, Kernel-Power - Power source change
  • Event 12, UserModePowerService - this is specific to my hardware.

The obvious things are essentially identical, the same events for power on and power off. Event 105 has EventData that reports if the AcOnLine is true or false. I think the SystemInformation property, which I am using, is already monitoring this event and I don’t see any value in duplicating Microsoft’s work.

Your events seem to be specific to your UPS, and it’s pretty obvious that different power management systems could do this in different ways.

Your request for a lot of additional monitoring and decisions is something I am going to leave to the application. It is in a much better position to know what it needs and provide UI to handle it. The driver will report the instantaneous power state.

I certainly wouldn’t gamble on the power lasting for any longer than neccessary, the 30 seconds or so that the current message box remains active seems about right to me. This should be easy to implement in SGP, if the power is restored then programmatically press the cancel button. Continuing with the sequence until the message box finishes may be worth while.

Hi Chris,

Event 105 is triggered on my laptop as well, number 12 is indeed specific for your laptop.

You wrote:

Your events seem to be specific to your UPS, and it’s pretty obvious that different power management systems could do this in different ways.

That was why I thought having them as input fields in the driver window. Obviously that would also require a pull-down to choose in which logbook they should be detected, while the implementation differs from monitoring event-id 105.

Anyway, I will be patient, hoping that one day this functionality will be an integral part of SGP. Until that time I will have to do with a hard shutdown of my cam in case of a power failure.

Cheers,
Nicolàs

The PowerStatus class has other properties relating to battery status and maybe they are being updated. Here is another version that logs the full PowerStatus properties and uses more of them to set IsSafe to false:

// make a series of decisions depending on the Power Status
if (ps.PowerLineStatus == PowerLineStatus.Offline)
    return false;       // not running on AC power
// these ignore the charging status, when charging they will return false until there is sufficient charge.
 if (ps.BatteryChargeStatus.HasFlag(BatteryChargeStatus.Critical) || ps.BatteryChargeStatus.HasFlag(BatteryChargeStatus.Low))
    return false;       // low or critical bsttery status
if (ps.BatteryLifePercent < 0.8f)
    return false;       // battery life percent lett than 80%
if (ps.BatteryLifeRemaining < 600)
    return false;       // less than 10 minutes

What this means is that if any of these things happen IsSafe will return false:

  • The mains power is off
  • The battery charge state is low or critical
  • The battery life percent is less than 80%
  • The battery life remaning is less thn 10 minutes.

The logging has been updated to record all of these.
What I’m hoping is that a UPS will record it’s battery state and that can be used to signal a shutdown.

Here is the new version
Generic Safety Setup.zip (594.8 KB)

Please try this and report what happens. It is important that you post logs. To do so check the Trace on checkbox. The logs are in Documents\ASCOM\Logs\ASCOM.GenericSafety.txt.

Chris

Hi Chris,

thanks for the update. I tested it and think the PowerStatus class is not set, all lines in the log read:

08:02:11.315 Connected Get True
08:02:11.315 IsSafe PowerLineStatus Online, batteryChargeStatus NoSystemBattery, BatteryFullLifetime -1, BatteryLifePercent 1, BatteryLifeRemaining -1

Straight from the beginning the SafetyMonitor icon in SGP turns red.
Nicolàs

The reason It’s always unsafe is the -1 for batteryLifeRemaining, this means unknown. I have fixed this but it doesn’t solve the problem that the UPS software doesn’t use PowerStatus. I guess it uses ACPI but I don’t see that and it isn’t practical for me to try to do anything blind. It needs a developer with a UPS.

It looks as if something using the PowerStatus, with setup so the unsafe conditions can be set will be useful so I’ll do that and leave it at that.

Hi Chris,

Once that is done, would you be willing to share the source code with us?

Kind regards,
Nicolàs

Hi Chris,

as your generic solution resulted in a driver that did not solve my problem, I decided to install VB yesterday. Now that was far from easy, which surprised me, but today I managed to build a Generic UPS SafetyMonitor following most of the specs I provided a few days ago.

afbeelding

The driver works with the events in the Windows Application Events Logbook (can be accessed via eventvwr).

There are three fields to be filled (the default values are those for an APC Back-UPS in combination with PowerChute):

  • the event-id that specifies when the UPS is on mains (to be determined for your UPS through the eventvwr)
  • the event-id that specifies when the UPS is on batteries (to be determined for your UPS through the eventvwr)
  • the amount of time to wait (in the hope mains will return) until we have to stop the sequence in order to be able to shutdown properly.

If mains returns with that specified time, the driver keeps the safe mode to safe. Only after the time has expired it will turn unsafe and will not return to safe, even if mains returns before the UPS shuts the computer.

The only thing not covered is the complete shutdown of the mount, but that is done using my MountCMD tool on computer shutdown.

The driver can be found on my server: http://www.dehilster.info/docs/GenericUPS-Setup.zip
The MountCMD tool is there too: http://www.dehilster.info/docs/MountCMD.zip

I have tested this driver with SGP doing its stuff with a ZWO ASI1600MM Cool, a 10Micron GM3000 mount and the slaved LesveDome, which all parked and warmed up properly. Hopefully other people on this list will test my Generic UPS Safety Monitor driver and give some feedback on how their UPS’s work. Please note that the driver will not work until the first image has been taken (that is a documented SGP feature). If you wish to postpone imaging, it is best to have two targets in the sequence: one with a single exposure directly taken, the next target being timed.

Nicolàs

Excellent! I’m glad you found a way to do this. It’s far easier if you have the hardware to hand.

You might consider letting the ASCOM people know, they can provide a link to your installer on their downloads site.

Like the seahorse logo.

As for the driver I wrote, I rewrote it to use the Windows SystemInformation.PowerStatus class and use a combination of the LinePower, BatteryStatus, Percent battery remaining and battery time remaining parameters. That will be useful for people using a laptop where the same events are generated for power on and off.

Hi Chris,

I have extended the driver to be able to monitor both the Application and System logbooks. In addition the messages left in there can be tested for a string, just like you had done.

So far it has been tested with two UPS: one from APC and one from CyberPower.

For more info and download of the most recent version, see my website.

Nicolàs

For those using SafetyMonitors I have developed a Hub to connect multiple SafetyMonitors to SGP. More info in this thread:
http://forum.mainsequencesoftware.com/t/multiple-safety-monitors/2135/17

and on my website

http://www.dehilster.info/astronomy/ascom-safetymonitor-hub.php

Nicolàs

For those interested, version 0.2.0 of the SafetyMonitor Hub is now also available from my web-site.

Main change is the way it connects to the underlying SafetyMonitors. The previous version created several unintended and unused instances of the connected SafetyMonitors. In this version no more than a single connection is made to each SafetyMonitor at all times. In addition the current version allows to access the settings of the connected SafetyMonitors, even when these and the Hub are already connected. It has improved status-LEDs and is now provided with tooltips.

Nicolàs

1 Like

Hi Nicolas - just tried your safety monitor from observing conditions driver. Works a charm. Many thanks.

1 Like

Hi @Chris,

Just wanted to update this thread by saying that your safety monitor based on the PowerStatus class works perfectly well with my UPS from Infosec that connects to the PC through a HID interface: https://www.infosec-ups.com/en/ups/z2-ex-1000.html

Thanks! Mikael

1 Like

I plan to test this at some point with an APC UPS. Just a question, did you need to make any changes to the PowerChute software ? I assume the Powerchute software needs to be launched ?
Thanks

Hi Drevonf, no tweaking needed, just install the PowerChute software and run the automatic detection test from the ASCOM driver.

Nicolàs

Hi Mikael,

thanks, I have added the model to my webpage.

Nicolàs

Thank you.

Hi Nicolàs,

In fact, my UPS doesn’t work with your Safety Monitor, as it doesnt log anything I could use in the Event Log. But it does work with the alternative Safety Monitor that @Chris developed as part of this thread. I just wanted to complement this thread by saying that some UPS appear to work well with this alternative, because from the ASCOM webpage and this thread one gets the impression that no UPS works with this safety monitor based on the PowerStatus class. I am hope it is more clear now!

Thanks, Mikael

Hi Mikael,

ok, thanks, I clearly misunderstood and will remove your model from my web-page.
Thanks for clarifying!

Nicolàs