Begging for a SmartApp: A "digital turnstile" (motion sensor with counter)

project_pets

#1

There are a lot of SmartApp developers here, for whom this might be a very easy task and could be able to help one of our pets (if it’s not simple, I’ll dive into the developer kit and try to figure my way around) - I’ve looked for something like this before and haven’t found it:

What I need, is effectively a “digital turnstile” that keeps track of the number of times motion has been seen within a timeframe, and can trigger an alert if there have been too many motion events within a period. Here’s the use-case – one of our cats gets urinary crystals, which can quickly turn into a very serious medical condition if it’s not noticed. We clean the litterbox daily, but we still want to be on top of the situation faster if it starts to flare up … but obviously we can’t sit in the house and watch the litterbox all day.

So what I had done before, was I had a WeMo motion sensor … which (via IFTTT) would advance a custom counter on NumerousApp (which has since been shut down). If that counter ever reached 8 (it was reset nightly), a different rule in IFTTT would send us alerts, change a certain bulb in our house to red, etc. It worked great for a couple years … but NumerousApp went offline a few months ago, so we’ve been flying blind.

This morning, we determined the cat is having a flare-up again (a check of the Nest camera over the litterbox confirms it) so we took him to the vet … and now I’m thinking it’s time I either try to write a SmartApp, or find some generous soul that could whip one together quickly. Roughly speaking, the SmartApp needs to allow the user to:

  1. Define a motion sensor to watch
  2. Define a threshold of what would be too many motion events within the timeframe (i.e.: 8)
  3. Define what that timeframe is (i.e.: 24 hours)
  4. Send alerts

There are two semi-tricky parts in that, though.

First … the motion sensor, needs to have a “cool-down period” after seeing a motion event. If the cat paces around the litter box for a while, they would keep triggering the motion sensor. IFTTT handles this really well with WeMo motion sensors, you just define a “cool down” interval of 5 minutes, 15 minutes, whatever makes sense.

Second … keeping a rolling “last X hours” view requires a lot of keeping stateful information. I couldn’t actually do this with IFTTT+NumerousApp … so what I decided would be perfectly acceptable was simply resetting the counter to zero at midnight, and then a simple “if counter > X then alarm” condition.

Has anyone ever seen a SmartApp here along those lines?


(Bobby) #2

As I was reading through, I was thinking CoRE can do that, but by the end, I agreed that a custom app makes more sense in your case, unless @ady624 can think of a magical way to create a smart variable that takes in consideration the “cool down” period. I am not as versed in CoRE’s variable capabilities.


(Jason "The Enabler" as deemed so by @Smart) #3

@toomer @SBDOBRESCU

This can be done using CoRE. It would take a little variable magic, but it’s forming in my head now.

I’m at work, but when I get home this evening I can certainly help you out.

Do you have CoRE installed? If not, go ahead and install it and take a look around.

This is gonna drive me crazy until I figure it out… But mostly like Adrian will pop in and have it done in a two line post n. Lol


(Bobby) #4

Yeah, I was thinking exactly the same thing. I could put my head to it, but then Adrian would come in and get it done in two lines after I wasted a whole day thinking about this scenario. So I tagged him instead :slight_smile:


(Jason "The Enabler" as deemed so by @Smart) #5

I see it as a challenge where he has the advantage… He wrote the app and can change it lol.

I like to see how much of an exact opposite way we do it…

Him - the easy skynet way.
Me - mere mortal way.


#6

What about something like this in CoRE (rough), need a secondary piston that will reset the variable to zero whenever.


#7

The main problem with that, is there’s no real option for a “cooldown” period for the motion sensor, which is really somewhat necessary to make this work correctly. The motion sensor flicks on and off within a few seconds, if the cat just walks in, goes straight to the box, then walks out … that might be 2 hits. But if he paces around a bit near the box (not unheard of) we could register dozens of hits in a single visit to the box. This makes setting a practical threshold nearly impossible.


#8

I did not think of the cool down period. I worked around this on a similar piston using a variable for delay. It would look something like this… (untested)

IF AvailableMotion changes to active
AND @litterboxDelay is not equal to true

Set number variable {@litterboxCounter} = @litterboxCounter + 1
Set boolean variable @litterboxDelay = true
IF ({@litterboxCounter} is greater than or equal to 8) THEN
Send Push notification 'Message Here'
Wait 5 minutes
Set boolean variable @litterboxDelay = false

( I hate Mondays) #9

Configure the motion sensor so that it recovers from a motion in a longer time period, like 5 minutes. The Aeon motion sensor allows that. I can write an app for you that does the count, but you’d have to configure the motion sensor for that, because using a running window is not an easy feat.

Is your requirement using a running window, like “x times per y hours” where y hours is always relative to now? Or is it “x time since y time” where y is a fixed time that gets reset once in a while? If it’s the latter, CoRE can do it. If it’s the running window, I can help you with a dedicated smartapp.


(Bobby) #10

Good thinking! @toomer if your motion is not configurable, you can always use a virtual motion sensor (uDTH) to overwrite when the sensor goes inactive by always turning it off X minutes later (where X is the amount of time you don’t want to be counted as an event).


#11

I didn’t know the Aeon sensor was adjustable. I don’t have one, but if it would help deliver on my use-case I can certainly pick one up.

“X times in the past Y hours” is ideally the goal (i.e.: >8 visits in any 24 hour window is a noteworthy condition worth looking into). Since that was too complicated to pull off before with what I’d stitched together with WeMo+IFTTT+NumerousApp, I simply landed on “more than 8 visits counted” with a separate IFTTT task that would simply reset the counter to zero every night. That worked well enough overall.


#12

Interesting … from the look of it, that might cover the use case. Then I’d just need a separate task to reset @litterboxCounter to zero nightly. I don’t know a thing about CoRE yet … can variables be shared globally across different “pistons” (hopefully I got the term right)? If not, then that would be a problem - as this code would just increment the counter indefinitely?


( I hate Mondays) #13

Using @eibyer’s suggestion, you could also reset the count at say midnight, then you’d have a fixed time window, not a running one, but it gets you closer to what you need without a custom developed smart app


(Bobby) #14

you got the naming and yes variables can be set globally. You already thinking in @ady624 s tems, so it won’t take you any time to get used to CoRE. It’s really a fun tool.


#15

Ok … well … I’ve been putting it off as long as possible, but it looks like I’ll be diving into CoRE this evening. I’ll post back later with my results - thanks for all the help & ideas so far everyone!


(Jason "The Enabler" as deemed so by @Smart) #16

See, told you! Stupid job! I actually had to work today… First time this year without a nap!