DEV Community

Fernando
Fernando

Posted on ā€¢ Edited on ā€¢ Originally published at fdo.cr

37 7 7 3 5

Keeping up with my cat's šŸ’© using a RaspberryPi

As a former dog owner and first time cat dad I was amazed at how cats are "potty trained" practically from birth. I was prepared to deal with the smell when having to clean the litter box. However, I didn't expect their bowel movements (šŸ’©) to carry a punch that would stink up half my apartment.

This might not be the case for everyone, but certainly for me, with an indoor cat in a 2 bedroom apartment without a naturally ventilated place to keep her litter box.

The hero/villain of the story

Her name is Dua and she is a cuddly & playful rescue tortie cat. Dua loves to play with her mouse toys and adores wet food, the latter of which is likely the reason I'm writing this post šŸ˜µā€šŸ’«

Dua sitting on a puff sofa

I have her litter box in my second bathroom's shower. The bathroom has an extractor fan that runs when the bathroom light is on, but she refuses to hasn't figured out how to turn it on and off each time she goes #2... Annoying, right?

Automating the extractor fan

To mitigate the smell I wanted the lights to turn on when Dua goes in her litter box. To do this I put together a few things:

The software that calls the webhook (which in turn triggers the Alexa routine) can be found here:

GitHub logo fdocr / pir_trigger

Script that connects a PIR Sensor to a webhook

PIR Trigger

Script that connects a PIR Sensor to a webhook.

Usage

Clone the repo in a folder, install dependencies and then run in background

# Install requirements
pip install -r requirements.txt

# Run in background
# TODO: Find/Document a better way to do this
TRIGGER_URL="<webhook_url>" python main.py &
Enter fullscreen mode Exit fullscreen mode

Otherwise add TRIGGER_URL = "<webhook_url>" to an .env file and the script will pick it up.

The script writes its own PID to pid.txt so it can be used. Examples:

# Follow output of background process
tail -f /proc/$(cat pid.txt)/fd/1

# Kill process
kill -9 $(cat pid.txt)
Enter fullscreen mode Exit fullscreen mode

Sensor to board connections

Cable diagram here

The script was inspired by this Raspberry Pi Foundation article and uses their suggested example layout. The sensor needs 5v (Vcc) and Ground (Gnd), so PIN 2 and PIN 6 work well. Connect the sensor's output (Out) toā€¦

It works!

Here's what the hardware looks like in action

RPi and motion sensor

RPi and motion sensor

Awful quality GIF of our hero/villain

Awful quality GIF of our hero/villain

šŸ’© Stats

With all of this in place I went a step further and added Opentelemetry to track the stats of how often the routine was being triggered on Honeycomb.

I wanted to know if I was turning on the bathroom lights over false positives from the motion sensor, but after some tests it simply serves the purpose of telling how often she goes in her litter box.

Last 7 days šŸ’© activity

Last 7 days šŸ’© activity

Last 24 hours šŸ’© activity

Last 24 hours šŸ’© activity
 

Interestingly, I can tell she goes in her litter box (# of motion sensor triggers) on average ~8.5 times per day. I don't think many cat owners can say they know this about their feline friends. I do remember and took inspiration from Aaron Patterson doing something similar a long time ago though.

Anyways, that's it. Pura vida!

Image of Timescale

šŸš€ pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applicationsā€”without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post ā†’

Top comments (14)

Collapse
 
michaeltharrington profile image
Michael Tharrington ā€¢

This is freaking AWESOME... and hilarious too! Nicely done, Fernando. šŸ™Œ

Also, while the stats section may seem a bit silly, my wife (a veterinarian as you know) said that when a pet gets blocked it often goes undetected until the pet vomits or shows extreme signs of discomfort. If you're able to see how frequently (or rather infrequently) your cat is going, you're more likely to know if she is no longer regular and then you know to take your cat in for a checkup. So, the stats are kind of a health perk!

Collapse
 
fdocr profile image
Fernando ā€¢

I didnā€™t consider the health/vetā€™s perspective and now feel less silly for keeping track of those stats haha thanks Michael (and Katelyn too lol)! šŸ˜

Collapse
 
peter profile image
Peter Kim Frank ā€¢

Incredible application of IRL observability! šŸ˜…

Collapse
 
towernter profile image
Tawanda Nyahuye ā€¢

Your style of writing is awesome and and very engaging ha ha ha ha

Collapse
 
fdocr profile image
Fernando ā€¢

Thanks! Glad it was a fun read šŸ˜„

Collapse
 
balaliss profile image
balaliss ā€¢

Man, I wish I thought of that when I had a cat. Of course, when I had a cat I was a teenager in middle school and only cared about how many Mama Celeste pizzas I could eat in a sitting. That's brilliant.

Collapse
 
ryencode profile image
Ryan Brown ā€¢

You're not alone in the RAW POWER of your cat's displays of dominance aka:šŸ’©!
Our cat has movements like a beast man! and rarely covers them. Just to tell us who is in charge.

I love the project, great!

Collapse
 
jess profile image
Jess Lee ā€¢

LOL thank you for this.

Collapse
 
fdocr profile image
Fernando ā€¢

šŸ˜

Collapse
 
vulcanwm profile image
Medea ā€¢

interesting post lmao

Collapse
 
greno profile image
Gregg Reno ā€¢

Given the title, I thought you were going to tell us how your cat learned to use the Raspberry Pi šŸ˜œ

Collapse
 
ainmosni profile image
DaniĆ«l Franke ā€¢

Nice idea.

I can heavily recommend you look at home assistant for this kind of stuff. It can make all your automation work locally (so no internet needed, and no amazon data collection) and you could do this with no code (or soldering, if you used zigbee sensors/switches) needed. I've been really enjoying using it for random (and cloudless) home automation stuff, the quality of HA is much better than it has any right to be.

That said, love the idea, and I might have to get a zigbee motion sensor for my cat boxes.

Collapse
 
fdocr profile image
Fernando ā€¢

Home assistant was something I considered and will likely play with in the future. I didnā€™t know about zigbee devices, they seem cool. Thanks for the suggestions!

Good luck trying it out for your cats. I would love to read about that setup in the future if youā€™re ever interested in a write up afterwards šŸ™ŒšŸ¼

Collapse
 
elonsjetn628ts profile image
TravisāŽ· ā€¢

Keeping up with your cat's what?

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More