Page 1 of 1

How to send notification when UPS state change (power outage)

Posted: Sunday 09 April 2017 18:58
by koowee
Hi,

I have APC UPS and I monitor it state using this thread scripts ( https://www.domoticz.com/forum/viewtopic.php?t=3673 ). It report state every minute, not just if state changes

Code: Select all

2017-04-09 19:27:01	On
2017-04-09 19:26:02	On
2017-04-09 19:25:03	On
2017-04-09 19:24:01	On
The purpose is that I could get a message only when the state changes from ON to OFF or OFF to ON. I have tried this script, but problem is that it thinks that state is changing every time when APC UPS report ON or OFF states. Any ideas what should I change to that script?

Code: Select all

-- Variables
devicename = "UPS state" --Name of the device
tempSensorName = "Living room" --Name of the temperature sensor
tempSensorName2 = "Garden" --Name of the outside temperature sensor


insideTemperature = otherdevices_temperature[tempSensorName] --Temperature is stored to the variable
outsideTemperature = otherdevices_temperature[tempSensorName2]

commandArray = {}

if (devicechanged[devicename]) then
	print(devicename.." power supply script running...")
		 
	if (devicechanged[devicename] == "Off") then
		bodytext = string.format("Power outage detected. Temperature inside of the house is now %.1f°C and outside %.1f°C", insideTemperature, outsideTemperature)
		print(bodytext)
		commandArray['SendNotification']="Domoticz - Power outage detected#"..bodytext.."#0"
	
	elseif (devicechanged[devicename] == "On") then
		bodytext = string.format("Power outage has ended. Temperature inside of the house is now %.1f°C and outside %.1f°C", insideTemperature, outsideTemperature)
		print(bodytext)
		commandArray['SendNotification']="Domoticz - Power outage has ended#"..bodytext.."#0"
	end
end
	
return commandArray

Re: How to send notification when UPS state change (power outage)

Posted: Sunday 09 April 2017 19:03
by Clemen
Change your script so you only update the domoticz device if the status is different

If (YOUR Domoticz device != status)
UPDATE

Re: How to send notification when UPS state change (power outage)

Posted: Monday 10 April 2017 14:55
by koowee
Thanks! That might be easiest way.. Need to check how to do it. Now I run shell script using crontab, which checks few states from UPS and store those values every minute to Domoticz devices