The internet loves cats and they are indeed very cute. But when they’re ‘feline’ in the mood for pooping, there’s a good chance one will paw-se for a short spell in your garden and leave you to clear up the mess.
This article first appeared in The MagPi 82 and was written by David Crookes
That happened to Davide Magni’s cousin, who moved into the house next door to him in Italy. “She spent more than a week cleaning her garden of cat-droppings,” he recalls. “All the cats in the area were using that small piece of land as their litter and I wondered how I could prevent it from happening in my own garden in the future.”
As it happens, Davide was rearranging an irrigation system in his garden when he began to consider a solution. “I started to place sprinklers in key locations, looking for a way to equally wet the whole garden using trial-and-error and activating them manually,” he says, before realising they could serve a dual cat-chasing purpose.
Sprinkle of Pi
The first important thing was automating the system so that it could be used when Davide was away from home or if he forgot to activate it. “I decided to use a Raspberry Pi because I wanted something that would provide APIs and integrate with other Internet of Things devices I have at home,” Davide tells us. “I certainly didn’t want a closed, self-contained system that wouldn’t interact with other devices.”
Luckily, there is an open platform which allows irrigation systems to be controlled: called OpenSprinkler, it supports the Pi, has its own extension board, and is connected to the web for remote access. “It provides everything I need for good irrigation control such as daily programming, a web GUI, and weather-based prediction,” Davide continues. With that in place, it was time to turn his attention to those troublesome cats.
Pi spy cats
Davide’s wife had bought him a Netatmo Presence outdoor smart camera as a Christmas gift. It detects movement, shines a bright light, and records what it sees; it can also distinguish between people, animals, and vehicles. As such, it was the perfect input device.
Initially, he pushed the Netatmo trigger through IFTTT to send a notification that activated the sprinklers, but it took so long that the cats would have done their business and already left. To improve performance, he created an ad-hoc application with Netatmo Connect which receives the camera trigger and sends it to a self-hosted site that runs a small script. This decides if the shower needs activating and sends it to OpenSprinkler.
“I added a callback, a simple PHP script call, that is invoked directly from the camera every time it detects a movement,” says Davide. “The script verifies that the call is valid, checks the system status, sends the activation signal to OpenSprinkler, and logs the event.”
Now, when a cat strays into the garden, the sprinklers kick in within seconds and chase them away, but there are some pitfalls. “For future developments, I’m thinking about being able to keep a small history of events in order to avoid activating a shower if a person and an animal approaches – such as my mum passing with her dog,” he laughs.