First rule machine rule: trying to simplify event handling and reduce hub load

My first attempt at rule machine. I'm trying to simplify the event handling to reduce the load.

I thought of using "wait on event" to rewrite the following rule. However, I don't think that model fits what I'm trying to do.

In words, this rule is: if the UPS is on battery and less than 5% battery remains, shut down. However, if the UPS is low but back on mains (this can happen if it restarts after a power failure and the hub restarts as well), watch out for a another power failure occurring before the battery is charged over 5%, and shut down if that happens.

In my attempt to make this simpler, I changed the trigger events, which allowed me to simplify this greatly. Did I do it correctly?

Before

After

Annotation 2020-06-09 105653

Could make the trigger AND , then you can just have it shutdown as the action. This way it only triggers when the battery is <=5 AND reporting on battery mode. This can remove the If statement from your actions to run

on a separate note, how did you get your UPS to report to hubitat? would love to do that with mine as well

1 Like

I don't think that this is possible. Triggers are OR events only unless I missed something.

The UPS is attached by USB to a raspberry pi that is running NUT UPS monitor (among other things). On the Hubitat, I installed @guyeeba s NUT clients Hubitat/Drivers at master · guyeeba/Hubitat · GitHub.

2 Likes

That's my interpretation as well.

Ahh, you're right. It's OR.

Set the trigger to be the battery less than 5, then in the action to run, only have the check for battery vs mains.

Scenario 1: Discharging and less than 5%
: Turn off hub

Scenario 2: Charging and less than 5%
: Leave hub on

Good. That will save me one event subscription.

Cool. Thanks for sharing

Well, I've achieved the ultimate simplification of the rule. I deleted it!

Instead, on the raspberry pi that is running NUT server, I edited /etc/nut/upsmon.conf, changing SHUTDOWNCMD "/sbin/shutdown -h +0" to SHUTDOWNCMD /etc/nut/shutdown.sh and wrote a new executable file, /etc/nut/shutdown.sh with the following lines:

#!/bin/sh
/usr/bin/curl -XPOST 'http://My.Hubitat.Ip.Address:8080/hub/shutdown' > /dev/null
/sbin/shutdown -P +0

This way, it is shut down when my raspberry pi NUT server decides it is time to shut down.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.