Each time the cat uses the kitty litter it updates a counter in Domoticz so I can tell when the kitty litter needs changing (after x cycles):
The device name for the magnetic door sensor is: Kitty Litter
The device name for the counter sensor is: Kitty Litter Cycles
You may need to change the "Closed" to "Open" depending on your setup, it's a pretty simple script.
Code: Select all
commandArray = {}
time = os.date("*t")
counter = otherdevices_svalues['Kitty Litter Cycles']
counter = tonumber(counter)
t1 = os.time()
s1 = otherdevices_lastupdate['Kitty Litter Cycles']
year1 = string.sub(s1, 1, 4)
month1 = string.sub(s1, 6, 7)
day1 = string.sub(s1, 9, 10)
hour1 = string.sub(s1, 12, 13)
minutes1 = string.sub(s1, 15, 16)
seconds1 = string.sub(s1, 18, 19)
t2 = os.time{year=year1, month=month1, day=day1, hour=hour1, min=minutes1, sec=seconds1}
cycletime = (os.difftime (t1, t2))
if (devicechanged["Kitty Litter"] == 'Closed' and cycletime > 240) then
counter = counter + 1
commandArray['UpdateDevice'] = otherdevices_idx['Kitty Litter Cycles'] .. '|0|' .. tonumber(counter)
end
return commandArray