Kitty Litter Tracking Sensor

Moderator: leecollings

Post Reply
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Kitty Litter Tracking Sensor

Post 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 3265 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 3265 times
Last edited by ben53252642 on Sunday 22 January 2017 17:08, edited 1 time in total.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Re: Kitty Litter Tracking Sensor

Post by Calzor Suzay »

Poop tracker, I love it :lol:
jjnj

Re: Kitty Litter Tracking Sensor

Post 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
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Kitty Litter Tracking Sensor

Post 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.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
randriese
Posts: 2
Joined: Saturday 17 December 2016 9:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Kitty Litter Tracking Sensor

Post by randriese »

this is pure brilliance!
Bernoo
Posts: 6
Joined: Sunday 07 January 2018 22:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.97
Location: Germany
Contact:

Re: Kitty Litter Tracking Sensor

Post 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)
don't drink whisky without water and don't drink water without whisky...
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Kitty Litter Tracking Sensor

Post by ben53252642 »

You probably have the Lua script set to type "ALL" instead of "Device". Look on the events page.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
Bernoo
Posts: 6
Joined: Sunday 07 January 2018 22:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.97
Location: Germany
Contact:

Re: Kitty Litter Tracking Sensor

Post 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
don't drink whisky without water and don't drink water without whisky...
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Kitty Litter Tracking Sensor

Post 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.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
Bernoo
Posts: 6
Joined: Sunday 07 January 2018 22:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.97
Location: Germany
Contact:

Re: Kitty Litter Tracking Sensor

Post 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
don't drink whisky without water and don't drink water without whisky...
askmurphy
Posts: 30
Joined: Friday 03 October 2014 22:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Kitty Litter Tracking Sensor

Post 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
askmurphy
Posts: 30
Joined: Friday 03 October 2014 22:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Kitty Litter Tracking Sensor

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

Re: Kitty Litter Tracking Sensor

Post 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?
askmurphy
Posts: 30
Joined: Friday 03 October 2014 22:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Kitty Litter Tracking Sensor

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

Who is online

Users browsing this forum: No registered users and 1 guest