LUA script for monitoring water pump

Post Reply
kksu
Posts: 1
Joined: Saturday 13 July 2013 10:42
Target OS: -
Domoticz version:
Contact:

LUA script for monitoring water pump

Post by kksu » Saturday 21 July 2018 17:05

Hi
I am trying to create script for my water pump "safety" (that it wouldn't run dry and destroy it self). I use Sonoff POW to measure pump power usage and to switch off the pump if it have run too long. The Sonoff POW part is working OK (I can see the power usage and switch off the device) in domoticz but I am trying to create script that would turn the Sonoff POW switch off if the pump runs continuously more than 10 min. So I need to monitor the pump's power usage (when it uses more than 300w) as it turn on when water tap is oped and the pressure drops on the pump. Below is my script so far that I am trying to get work can someone more knowledgeable help me on this ?


t1 = os.time()
s = otherdevices_lastupdate['Sonoff POW usage']
-- returns a date time like 2013-07-11 17:23:12

year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)

commandArray = {}

t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))
if (otherdevices_svalues['Sonoff POW usage'] > '300' and difference > 600 and difference < 700) then
commandArray['Sonoff POW switch']= 'Off'
commandArray['SendNotification']='Water pump has been on for 10min pump shutdown !'
print("Water pump shut down")
end

return commandArray

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests