Need Help to configure "Nut client" on Raspberry 2

Moderator: leecollings

Post Reply
pyrrhus
Posts: 2
Joined: Monday 18 April 2016 19:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Need Help to configure "Nut client" on Raspberry 2

Post by pyrrhus »

Hello !
I have a NAS with a usb plugged UPS on it. I have installed nut client (only the client) on my raspberry to monitor the UPS. I must plug the UPS to the NAS because it's the only device which recognizes my UPS (chinese generic, unfortunately no choice in my country). No way to make it directly work plugged to the raspberry. As I've installed only nut client into my raspberry, /etc/nut was empty. I've created 3 files:

nut.conf

Code: Select all

MODE=netclient
upsmon.conf

Code: Select all

MONITOR login@nas_ip 1 admin password slave
SHUTDOWNCMD "/sbin/shutdown -h now"
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYCMD "/etc/nut/notifycmd"
the notifycmd script:

Code: Select all

#!/bin/bash
#
# NUT NOTIFYCMD script

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin

trap "exit 0" SIGTERM

if [ "$NOTIFYTYPE" = "ONLINE" ]
then
        echo $0: power restored | wall
# curl command to disable my virtual switch "battery"
curl -s "http://ip_domoticz:port/json.htm?type=command&param=switchlight&idx=XX&switchcmd=Off"
        # Cause all instances of this script to exit.
        killall -s SIGTERM `basename $0`
fi

if [ "$NOTIFYTYPE" = "ONBATT" ]
then
        echo $0: 40 minutes till system powers down... | wall
# curl command to activate my virtual switch "battery"
curl -s "http://ip_domoticz:port/json.htm?type=command&param=switchlight&idx=XX&switchcmd=On"
        # Loop with one second interval to allow SIGTERM reception.
        let "n = 2400"
        while [ $n -ne 0 ]
        do
                sleep 1
                let "n--"
        done
        echo $0: commencing shutdown | wall
        sleep 10
        upsmon -c fsd
fi
My UPS is powerful enough to wait 40 minutes before shuting down the nas and the raspberry remotely. I manage a virtual switch "battery" when power loss and power restored to perform operations with blocky.

But there is a special case: if the raspberry lost connection with the ups when it is on battery, the raspberry shut down almost immediately... I think this is a protection behavior, but i'd like to insert a curl command which sends a sms before shutdown, like "power loss and connexion failure with ups" (i know the command itself, this is not the problem) I know I must add something like "DEADTIME" or "NOTIFYFLAG NOCOMM" or "COMMBAD" in upsmon.conf, but not sure what to choose... And what do i have to add in my "notifycmd" file ?

Thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests