Page 1 of 1

Kitty Litter Tracking Sensor

Posted: Sunday 22 January 2017 13:13
by ben53252642
I bought the ScoopFree Ultra kitty litter and added a Z-Wave magnetic door sensor at the end part to sense when the "storage section" opens and closes.

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
Screen Shot 2017-01-22 at 11.11.58 pm.png
Screen Shot 2017-01-22 at 11.11.58 pm.png (64.86 KiB) Viewed 3269 times
Screen Shot 2017-01-22 at 11.12.09 pm.png
Screen Shot 2017-01-22 at 11.12.09 pm.png (238.17 KiB) Viewed 3269 times

Re: Kitty Litter Tracking Sensor

Posted: Sunday 22 January 2017 17:06
by Calzor Suzay
Poop tracker, I love it :lol:

Re: Kitty Litter Tracking Sensor

Posted: Sunday 22 January 2017 17:41
by jjnj
Ha great, i was looking for this. What type of sensir did you create for the cycles?

Sent from my LG-F800L using Tapatalk

Re: Kitty Litter Tracking Sensor

Posted: Sunday 22 January 2017 18:38
by ben53252642
jjnj wrote:Ha great, i was looking for this. What type of sensir did you create for the cycles?

Sent from my LG-F800L using Tapatalk
It's just a counter, also fyi they sell re-usable trays for the ScoopFree on Amazon.

Re: Kitty Litter Tracking Sensor

Posted: Friday 03 March 2017 10:47
by randriese
this is pure brilliance!

Re: Kitty Litter Tracking Sensor

Posted: Thursday 15 February 2018 20:32
by Bernoo
Hello Ben,
i use your simple script, with a virtual switch (to try) and change the names from the sensor and counter in the Script (not more).
But it doesn't work.

In the Stratus Protocoll is this error:
Error: EventSystem: in brennerstarts: [string "commandArray = {}..."]:17: attempt to index global 'devicechanged' (a nil value)

What is wrong?
Thx Bernoo


(Domoticz V3.88.41)

Re: Kitty Litter Tracking Sensor

Posted: Thursday 15 February 2018 21:09
by ben53252642
You probably have the Lua script set to type "ALL" instead of "Device". Look on the events page.

Re: Kitty Litter Tracking Sensor

Posted: Sunday 18 February 2018 20:11
by Bernoo
Hello Ben,
yes, that was wrong, and the error message is gone. But he still does not count. There must be another mistake.
I do not understand that.

Thx for your fast help.

Grettings
Bernoo

Re: Kitty Litter Tracking Sensor

Posted: Sunday 18 February 2018 20:50
by ben53252642
Bernoo wrote: Sunday 18 February 2018 20:11 Hello Ben,
yes, that was wrong, and the error message is gone. But he still does not count. There must be another mistake.
I do not understand that.

Thx for your fast help.

Grettings
Bernoo
If your using a virtual switch for testing, that would only have "On / Off" states.

This line needs to be changed:

if (devicechanged["Kitty Litter"] == 'Closed' and cycletime > 240) then

To:

if (devicechanged["Kitty Litter"] == 'Off') then

I removed the cycle time, basically each time you turn off the test switch it should now + the counter. This is only so you can see it working with the test script, the original script above should work fine with an actual door / contact sensor.

Re: Kitty Litter Tracking Sensor

Posted: Sunday 18 February 2018 21:25
by Bernoo
Ben,
that was it, it works!!! Thank you,
thank you for your help.

I change it after install the Hardware Switch next Week

Grettings
Bernoo

Re: Kitty Litter Tracking Sensor

Posted: Saturday 24 March 2018 18:03
by askmurphy
Nice !
Would be nice if there was a reset-button (virtual on the screen) which could be pressed after cleaning the cat-litter.
How can we do that ?
I have made some hardware for the Cat Robot Litter, will post that as soon it's ready (now in prototype fase, works nice already).
;-) Arthur

Re: Kitty Litter Tracking Sensor

Posted: Monday 26 March 2018 22:03
by askmurphy
I am trying to make a reset button and a counter.

What I want to do is this:
1) a counter which counts every cat litter cycle, that works now.
2) a total counter which counts the total cycles
3) a reset button which reset the counter (1) to 0.

I have made a uservariable:

'KattenbakCyclusTeller Integer'

And I use the script below.

If I add the line 'uservariables['Kattenbakcyclusteller'] = otherdevices_idx['Kattenbakcycles'] ' the script doesn't work anymore.

I hope somebody can help a little ?

Regards,

;-) Arthur


-------
commandArray = {}
time = os.date("*t")
counter = otherdevices_svalues['Kattenbakcycles']
counter = tonumber(counter)

t1 = os.time()
s1 = otherdevices_lastupdate['Kattenbakcycles']
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["Kattenbaksensor"] == 'On' and cycletime > 240) then
counter = counter + 1
-- value=0
value = counter
commandArray['UpdateDevice'] = otherdevices_idx['Kattenbakcycles'] .. '|0|' .. tonumber(value)
-- uservariables['Kattenbakcyclusteller'] = otherdevices_idx['Kattenbakcycles']
end

return commandArray

Re: Kitty Litter Tracking Sensor

Posted: Thursday 29 March 2018 22:47
by jjnj
askmurphy wrote: Monday 26 March 2018 22:03 I am trying to make a reset button and a counter.

What I want to do is this:
1) a counter which counts every cat litter cycle, that works now.
2) a total counter which counts the total cycles
3) a reset button which reset the counter (1) to 0.

I have made a uservariable:

'KattenbakCyclusTeller Integer'

And I use the script below.

If I add the line 'uservariables['Kattenbakcyclusteller'] = otherdevices_idx['Kattenbakcycles'] ' the script doesn't work anymore.

I hope somebody can help a little ?

Regards,

;-) Arthur


-------
commandArray = {}
time = os.date("*t")
counter = otherdevices_svalues['Kattenbakcycles']
counter = tonumber(counter)

t1 = os.time()
s1 = otherdevices_lastupdate['Kattenbakcycles']
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["Kattenbaksensor"] == 'On' and cycletime > 240) then
counter = counter + 1
-- value=0
value = counter
commandArray['UpdateDevice'] = otherdevices_idx['Kattenbakcycles'] .. '|0|' .. tonumber(value)
-- uservariables['Kattenbakcyclusteller'] = otherdevices_idx['Kattenbakcycles']
end

return commandArray
Did you manage to get this working?

Re: Kitty Litter Tracking Sensor

Posted: Friday 30 March 2018 19:38
by askmurphy
It works !

Look at this:

Kattenbak-code:

Code: Select all

-- You probably have the Lua script set to type "ALL" instead of "Device". Look on the events page.
commandArray = {}

time = os.date("*t")
counter = otherdevices_svalues['Kattenbakcycles']
counter = tonumber(counter)

totalcounter = otherdevices_svalues['Kattenbakcycle-totaalteller']
totalcounter = tonumber(totalcounter)

t1 = os.time()
s1 = otherdevices_lastupdate['Kattenbakcycles']
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["Kattenbaksensor"] == 'On' and cycletime > 60) then
counter = counter + 1
totalvalue = totalcounter + 1

    table.insert (commandArray, { ['UpdateDevice'] = otherdevices_idx['Kattenbakcycles'] .. '|0|' .. tonumber(counter) } )
    table.insert (commandArray, { ['UpdateDevice'] = otherdevices_idx['Kattenbakcycle-totaalteller'] .. '|0|' .. tonumber(totalvalue) } )

end

return commandArray
Kattenbak-reset code:

Code: Select all


-- You probably have the Lua script set to type "ALL" instead of "Device". Look on the events page.
commandArray = {}

if (devicechanged["Reset kattenbak teller"] == 'Group On') then
       table.insert (commandArray, { ['UpdateDevice'] = otherdevices_idx['Kattenbakcycles'] .. '|0|' .. tonumber(0) } )
      --  table.insert (commandArray, { ['UpdateDevice'] = otherdevices_idx['Kattenbakcycle-totaalteller'] .. '|0|' .. tonumber(0) } )
--   commandArray['UpdateDevice'] = otherdevices_idx['Kattenbakcycles'] .. '|0|' .. tonumber(9)
  -- commandArray['UpdateDevice'] = otherdevices_idx['Kattenbakcycle-totaalteller'] .. '|0|' .. tonumber(9)
end

return commandArray
Hardware:

234 Kattenbakcycle-totaalteller 00082234 1 Kattenbakcycle-totaalteller General Custom Sensor
231 Reset kattenbak teller 00014137 1 Reset kattenbak teller Light/Switch
230 My Sensors 00000001 0 Kattenbaksensor Light/Switch AC
224 Kattenbakcycles 00082224 1 Kattenbakcycles General Custom Sensor

I will post all details on thingiverse next week, I will let you know that here.