Using Machine Learning to prevent dogs from relieving themselves on your lawn

People in my neighborhood sometimes don’t pick up after their dogs and recently I’ve noticed my lawn has developed a large brown spot right by the sidewalk from where they urinate. Now I’m working on a method to use the smart sprinkler to initiate a Run cycle when a dog steps on my lawn. Using machine learning I was able to build a solution to send a notification to the smart sprinkler to run for a specified amount of time when the confidence level of their being a dog on the lawn is higher than 75%.

It works reliably in the testing I’ve been running. Though my coding skills are a bit lax and there’s some things I’d like to clean up to make it more efficient. I have to say though, it runs extremely fast! In under 200 milliseconds, it detects the dog and begins the run cycle on the sprinklers. Rachio’s hyper fast, responsive API allows the trigger to happen so quickly.

4 Likes

I have not explored home automation, so this is a noobie question. How does your system detect that a dog may be on your lawn? Do you have a motion detector?

1 Like

This is impressive. Are you analyzing footage from an existing security camera? This technology could have many applications with Rachio.

Examples:

Stop watering if you see it’s raining.

Stop watering if you see runoff.

Instead of modeling evaporation loss from a swimming pool, fill when it’s low.

Send an alert if the sprinklers aren’t shooting high enough (clogged filter, broken head, etc.)

Awesome applications Stewart, you could surely do something like that with ML. I’m using a Raspberry PI, the Rachio Public API, and a combination of AWS services. I’m running Amazon Rekognition on a Raspberry PI via AWS IoT. In this application, the object detection API is constantly updating the IoT Logs. I built logic to send a message to a Lambda function when Rekognition detects a dog with a confidence level higher than 70%. The Lambda function is just a bit of Python code that sends a PUT to Rachio’s API to run the specified zone.

To build something like the swimming pool evaporation model, you could use Amazon SageMaker to train a model to recognize what the pool looks like when it’s filled to the optimal level and have it trigger filling when it falls out of that range.

Same with the sprinkler height, you’d just need to feed data to SageMaker for your training model with images or video of the sprinklers at the optimal height and build logic to trigger a function to notify you if anything is out of band with what you specified.

Thinking more about it, the actual training of a model would be a limiting factor for wide adoption of something like the pool level. I’d have to spend some time thinking of a way to like… democratize the ability to train a Sagemaker model. You’d need to have at least some experience with the services. With Rekognition you’re just detecting an object it’s not hard to draw boundaries around an area you’d want to define as your lawn and just trigger an action when the object is detected.

Also, another way to apply this would be to instead of spraying as the dog comes on to the lawn, waiting 5 minutes after to dilute.

I did this a couple years ago with my Smartthings integration. I had a motion sensor aimed at the lawn that my neighbors dog ALWAYS stopped to poop in. Worked like a charm. Took a few days for the owner to realize it wasn’t just a coincidence that Fluffy got soaked evertime she popped a squat in my yard…

1 Like

Nice! I was hoping to get a “Homer Simpson” response and train the owners and the pets to skip my lawn all together.

I need something like this because of the issues I’m having with CATS crapping all over my grass. It’s a mine field every week when I go out to cut the grass.

Now I’m wondering if they make a waterproof Motion detector that works with Homekit? So that if it sense motion it’s turn on that zone. Because you can link up devices like this in Apple’s HOME app. I already have it set where my Garage Door Open’s that the Garage lights also turn on, and when it closes the lights turn off. It really makes it nice when it’s dark out and it’s the main way we come and go from my house.

But if I can set it where the sensor see’s motion in a zone, it turns on that zone. Cats do like like water. I’m going to have to look into that.

Zooz is about the only outdoor motion sensor I know of. It’s a Zwave sensor, so I doubt it works directly with Homekit. Need an ST hub or similar.

Motion sensors don’t allow you to choose which object types will trigger the sprinklers. If you use a motion sensor, you can’t even walk across your own lawn. With this, the probability of a human triggering a response is extremely low. You can definitely program it to work with Cats as they are one of Rekognitions default objects in the object detection API.

https://docs.aws.amazon.com/rekognition/latest/dg/labels-detect-labels-image.html

You can set boundaries and object types within boundaries. Cats begone!

JB,
I am using a Zooz outdoor sensor with a Samsung SmartThings hub and IFTTT to keep the deer out of my yard. I initially had some problems with IFTTT since the app only allows one condition to trigger but I needed two. It turns out that you need to limit the time the irrigation system turns on so you don’t water your house guests, the mail man or the UPS guy. It took some minor coding (like 6 lines that I copied from someone else) to limit activation to times when deer are frequenting my rose bushes (mostly at night and in the morning) but after a little online research, I got it to work. Turns out it also chases away armadillo’s, skunks, opossums and other small varmints too. I bet it would scare the crap (pun intended) out of cats in your neighborhood. The Zooz sensors are zwave devices so as long as you can get one close enough to the hub to connect the rest of them should daisy chain back to the hub (since zwave devices also act as signal repeaters). If you need specifics on how I modified IFTTT, send me a quick email at jerry@jjappraisal.biz.

1 Like

What are you using to detect motion and identify the size of the critter in your irrigation zone? Cameras?

Yes, I’m using a camera. I’m using a Raspberry Pi with camera module specifically. Most RSTP compatible cameras can feed a stream out to Amazon Kinesis Video Streams. The application is not in any way dependent on the size of the creature or motion for that matter. The Raspberry Pi is sending a video stream to Kinesis Video Streams. The Kinesis Stream is fed into Rekognition, where the object detection is done. Rekognition is constantly analysing the video stream for objects, when the objects I’m interested in appear, I trigger an action. In this case, a Dog on my Lawn.

This is a brief blog post on Amazon Rekognition. It explains how object detection works.

Here’s a little technical detail on getting a video stream from a Raspberry Pi into Amazon Kinesis Streams for analysis by Rekognition.

https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/producersdk-cpp-rpi.html
https://docs.aws.amazon.com/rekognition/latest/dg/streaming-video.html
https://docs.aws.amazon.com/rekognition/latest/dg/labels.html

So for an example of what Rekognition will give you as a response… I ran detect-labels against the image linked here…

http://unisci24.com/data_images/wlls/20/241000-german-shepherd.jpg

In the output below, you can see that detect-labels provides you with a number of details about the object you are detecting with varying levels of confidence. The Class, Species, and Breed (among other things) of the animal are all detailed. There’s even a 55.7% chance that this dog might be a Police Dog. You can imagine that if there’s a particularly pesky rottweiler lighting up your lawn regularly, you can tune it to only trigger if both dog is detected that is a rottweiler. Let me know if this explains it for you.

{
"Labels": [
    {
        "Name": "Mammal",
        "Confidence": 99.40145874023438,
        "Instances": [],
        "Parents": [
            {
                "Name": "Animal"
            }
        ]
    },
    {
        "Name": "Canine",
        "Confidence": 99.40145874023438,
        "Instances": [],
        "Parents": [
            {
                "Name": "Mammal"
            },
            {
                "Name": "Animal"
            }
        ]
    },
    {
        "Name": "Pet",
        "Confidence": 99.40145874023438,
        "Instances": [],
        "Parents": [
            {
                "Name": "Animal"
            }
        ]
    },
    {
        "Name": "German Shepherd",
        "Confidence": 99.40145874023438,
        "Instances": [],
        "Parents": [
            {
                "Name": "Pet"
            },
            {
                "Name": "Animal"
            },
            {
                "Name": "Mammal"
            },
            {
                "Name": "Canine"
            },
            {
                "Name": "Dog"
            }
        ]
    },
    {
        "Name": "Animal",
        "Confidence": 99.40145874023438,
        "Instances": [],
        "Parents": []
    },
    {
        "Name": "Dog",
        "Confidence": 99.40145874023438,
        "Instances": [
            {
                "BoundingBox": {
                    "Width": 0.8466859459877014,
                    "Height": 0.9463058710098267,
                    "Left": 0.07047327607870102,
                    "Top": 0.020711854100227356
                },
                "Confidence": 96.1170425415039
            }
        ],
        "Parents": [
            {
                "Name": "Animal"
            },
            {
                "Name": "Mammal"
            },
            {
                "Name": "Canine"
            },
            {
                "Name": "Pet"
            }
        ]
    },
    {
        "Name": "Police Dog",
        "Confidence": 55.79732894897461,
        "Instances": [],
        "Parents": [
            {
                "Name": "Pet"
            },
            {
                "Name": "Animal"
            },
            {
                "Name": "Mammal"
            },
            {
                "Name": "Canine"
            },
            {
                "Name": "Dog"
            }
        ]
    }
],
"LabelModelVersion": "2.0"
}

@jrjenkinsiv - I’m impressed with the incredible solution.
While I conceptually understand what you’re describing, I am nowhere close to the technical level to be able to code and implement all those components.
I have a similar need, as a few have shared here, to identify non-human critters (deer, turkeys, jackrabbits, etc) and trigger the sprinklers.
Is there a way for a non-techy person to implement your solution?
Alternatively, would you consider providing an implementation for a fee?