Skip to main content

Provides ability to connect and control a PetSafe Smart Feed, Scoopfree, and Smart Door devices using the PetSafe API.

Project description

petsafe-api

Connect and control PetSafe Smart Feed, ScoopFree, and Smart Door devices using the PetSafe API.

BREAKING CHANGE: Version 2.0 uses the new PetSafe API. You will need to request new tokens.

PetSafe will lock your account if you request data more often than once per 5 minutes.

Project rename

This repository is now named petsafe-api and the published package name is petsafe-api on PyPI.

Import paths are unchanged: continue using import petsafe and python -m petsafe.

Acknowledgements

This project builds on the excellent prior work from the original developers:

Thank you to both projects for building the API integrations for existing feeder and ScoopFree functionality. This repository includes all of that previous work, with Smart Door API support added on top.

Installation

pip install petsafe-api

If installing from source code, python setup.py install

Login tokens

You must use tokens to interact with the PetSafe Smart-Feed API.
There are two methods to retrieve tokens:

Get tokens using command line

  1. Execute python -m petsafe [email_address] to request an email code.
  2. Check your email for an email code from PetSafe.
  3. Enter your code to generate tokens.

Get tokens using Python

import petsafe as sf


# replace with your email address
client = sf.PetSafeClient(email="email@example.com")
client.request_code()

# check your email for a code
code = input("Enter email code: ")
token = client.request_tokens_from_code(code)

print("email:", client.email)
print("id_token:", client.id_token)
print("refresh_token:", client.refresh_token)
print("access_token:", client.access_token)

Example usage

List feeders

import petsafe as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_feeders(client)

# print all feeders
for device in devices:
    print(device)

Feed 1/8 cup at normal speed

import petsafe as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_feeders(client)

# get the first feeder
feeder = devices[0]
feeder.feed(amount=1, slow_feed=False)

Get current battery level (0 - 100)

import petsafe as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_feeders(client)

# get the first feeder
feeder = devices[0]
print(feeder.battery_level)

Get current food level

import petsafe as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_feeders(client)

# get the first feeder
feeder = devices[0]
status = feeder.food_low_status

if status == 0:
    print("Feeder has food.")
elif status == 1:
    print("Feeder is low on food.")
elif status == 2:
    print("Feeder is out of food.")

SmartDoor controls

import asyncio

import petsafe as sf


async def main() -> None:
    client = sf.PetSafeClient(
        email="email@example.com",
        id_token="YOUR_ID_TOKEN",
        refresh_token="YOUR_REFRESH_TOKEN",
        access_token="YOUR_ACCESS_TOKEN",
    )

    doors = await client.get_smartdoors()
    door = doors[0]

    # Manually lock the door and refresh its reported state
    await door.lock()

    # Switch back to Smart mode without forcing a refresh
    await door.smart_mode(update_data=False)

    # Or use the client helpers that return the updated door instance
    updated = await client.manual_unlock_smartdoor(door.api_name)
    print(updated.mode)


asyncio.run(main())

get litterboxes

import petsafe as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_litterboxes(client)

# print all litterboxes
for device in devices:
    print(device)

get litterbox activity

import petsafe as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_litterboxes(client)

litterbox = devices[0]
print(litterbox.get_schedule())

rake the litterbox

import petsafe as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_litterboxes(client)

litterbox = devices[0]
litterbox.rake()

modify the litterbox rake timer

import petsafe as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_litterboxes(client)

litterbox = devices[0]
litterbox.modify_timer(15)

reset the litterbox rake count

import petsafe as sf

client = sf.PetSafeClient(email="email@example.com",
                       id_token="YOUR_ID_TOKEN",
                       refresh_token="YOUR_REFRESH_TOKEN",
                       access_token="YOUR_ACCESS_TOKEN")
devices = sf.devices.get_litterboxes(client)

litterbox = devices[0]
litterbox.reset()

Contributing

All contributions are welcome. Please, feel free to create a pull request!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

petsafe_api-3.0.1.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

petsafe_api-3.0.1-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file petsafe_api-3.0.1.tar.gz.

File metadata

  • Download URL: petsafe_api-3.0.1.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for petsafe_api-3.0.1.tar.gz
Algorithm Hash digest
SHA256 4c0f2c342a95a6b588cc49b027b2424a87ba02426bb23bf8a5b765d1b7c6288a
MD5 ab71a341e98bde4fd6b937766adce3d5
BLAKE2b-256 2046a30ae22c8a51965f4f71e3c62d429a31fd88226f03a0e9c9ecc39e94c6cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for petsafe_api-3.0.1.tar.gz:

Publisher: pypi_deploy.yml on ThomasHFWright/petsafe-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file petsafe_api-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: petsafe_api-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for petsafe_api-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 43ae5e810db4eda51c2ec43b7e94e8fecdb30c7214ac8912b61890692af0febf
MD5 74e51d49cefdb05b5a4f1056561108c8
BLAKE2b-256 5d075ce19aee5d2f169ec97d6a497531d4f897bb2f9a4e627cd733df3277961a

See more details on using hashes here.

Provenance

The following attestation bundles were made for petsafe_api-3.0.1-py3-none-any.whl:

Publisher: pypi_deploy.yml on ThomasHFWright/petsafe-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page