Back to Rafa's website
December 22, 2020

How to Feed Your Cat with Siri

I while ago I tweeted a video of me using Siri to feed my cat

Got a new pet feeder and “hacked” it to make it work with Siri/HomeKit.

The cat was not impressed, but whatever, Siri can feed her now. pic.twitter.com/e42FA89vVW

— Rafa (@rafahari) May 6, 2020

Since then several people have asked me how did I make that work, and through the mystical power of procrastination I am now writing a simple how-to guide, 6 months later.

Disclaimer

This is extremely hacky — everytime you log in to the Petkit app in a different device this breaks, but it made for a cool tweet and it's fun.

What we'll need

If you have an Apple Silicon based Mac, then that's the only device we'll need, otherwise we need an iOS device to run the Petkit app… oh yeah and we need the Petkit feeder and app. I should've start there.

Screenshot of a Mac running Charles, Terminal, Paw, Petkit, and Home. Screenshot of petkit in the Mac App Store on Apple Silicon Macs

I've only tested this with the Petkit Element Mini, but I see no reason why it wouldn't work with the other Petkit devices.

There's two parts to this:

  1. Find the right API call by "listening" to our network requests
  2. Add a way to make those calls through Siri or the Home app

Finding the right API call

First thing we need to do is find the right API call. We're going to do this by "listening" to our network requests, trigger a manual feeding with the Petkit app, and finding the right booger.

To listen to the network requests I use an app called Charles, which is available for both macOS and iOS.

Let's start by opening the Petkit app, make sure you're logged in and everything is already set up and proceed to the screen that would trigger a new feeding… AND STOP, NO TOUCHING!

Screenshot of an iPad running the petkit app, in the manual feeding view

Let's now open Charles, make sure the status is set to Active, tap Current Session, and let's hit the little Clear Session icon in the bottom to make it easier to find the right one.

Alright, we can now go back to Petkit, and trigger a new manual feeding. The amount of food that you selected is going to be the amount used for our "smart feedings". Did the feeder dispense food? Good. If it didn't then something's wrong and I'm not qualified to help you any further, go figure that one out first.

Cool, let's now go back to Charles, and BOOM, it should have a bunch of new items in that list… it should look something like this:

Screenshot of Charles with the right API call selected

Tap the one that says http://api.petkt.com and then look for the first one that says latest/feedermini/save_dailyfeed — that's the one, that's our booger! Keep that thing around, we're gonna need it very soon.

Triggering from Siri/Home

There's now two ways we can trigger this via Siri: we can either create a Shortcut, or add it as a device to our Home app via Homebridge.

iOS Shortcuts

Definitely the easiest way is to create a Shortcut — open the Shortcuts app and hit + to create a new Shortcut.

  1. Start by adding a "Text" block, and paste the "Response Body" content in there.
  2. Screenshot of Charles highlighting the body section
  3. Next add a "URL" block with the right URL content from the API call.
  4. And finally, add a "Get contents of URL" block. Hit "Show more" and here you're going to add all the Request Headers… it'll take some time, but make sure you get all of these right. For the Request Body section add the Text block we just created.
  5. Screenshots of Shortcuts with the right configurations Screenshots of Shortcuts with the right configurations

That's hit, run the Shortcut and the your feeder should dispense food!

Adding it as a device in Home, via Homebridge

If you're running Homebridge, we can add the Petkit feeder as a device using the homebridge-http-switch plugin.

  1. Follow the instructions to install and setup the plugin
  2. In your config.json add the appropriate Request Headers
  3. Screenshot of my config.json file
  4. Save your changes and run homebridge
  5. You should now see the new device in your Home app, it's a simple switch/button
  6. Screenshots of the Home app with the new switch
  7. Optionally, you can create a Scene that just triggers the device for an easier Siri trigger (just call the scene something like "Feed the Cat").
  8. Screenshots of the Home app with the scene and device

Troubleshooting

If something is not working, it's very likely that you either wrote down the API call incorrectly. I like to use an app like Paw to assemble and test the API call before, to make sure I got it right.


There you go, a convoluted and complicated way of achieving something pretty nerdy that will definitely break in a couple weeks.