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

Moderator: leecollings

Post Reply
koowee
Posts: 62
Joined: Thursday 29 December 2016 18:17
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Finland
Contact:

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

Post 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
Clemen
Posts: 75
Joined: Saturday 05 December 2015 15:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Europe
Contact:

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

Post by Clemen »

Change your script so you only update the domoticz device if the status is different

If (YOUR Domoticz device != status)
UPDATE
koowee
Posts: 62
Joined: Thursday 29 December 2016 18:17
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Finland
Contact:

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

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest