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.
This repository is now named petsafe-api and the published package name is petsafe-api on PyPI.
Import paths are unchanged: continue using
import petsafeandpython -m petsafe.
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.
pip install petsafe-api
If installing from source code,
python setup.py install
You must use tokens to interact with the PetSafe Smart-Feed API.
There are two methods to retrieve tokens:
- Execute
python -m petsafe [email_address]to request an email code. - Check your email for an email code from PetSafe.
- Enter your code to generate tokens.
importpetsafeassf# replace with your email addressclient=sf.PetSafeClient(email="email@example.com")
client.request_code()
# check your email for a codecode=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)importpetsafeassfclient=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 feedersfordeviceindevices:
print(device)importpetsafeassfclient=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 feederfeeder=devices[0]
feeder.feed(amount=1, slow_feed=False)importpetsafeassfclient=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 feederfeeder=devices[0]
print(feeder.battery_level)importpetsafeassfclient=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 feederfeeder=devices[0]
status=feeder.food_low_statusifstatus==0:
print("Feeder has food.")
elifstatus==1:
print("Feeder is low on food.")
elifstatus==2:
print("Feeder is out of food.")importasyncioimportpetsafeassfasyncdefmain() ->None:
client=sf.PetSafeClient(
email="email@example.com",
id_token="YOUR_ID_TOKEN",
refresh_token="YOUR_REFRESH_TOKEN",
access_token="YOUR_ACCESS_TOKEN",
)
doors=awaitclient.get_smartdoors()
door=doors[0]
# Manually lock the door and refresh its reported stateawaitdoor.lock()
# Switch back to Smart mode without forcing a refreshawaitdoor.smart_mode(update_data=False)
# Or use the client helpers that return the updated door instanceupdated=awaitclient.manual_unlock_smartdoor(door.api_name)
print(updated.mode)
asyncio.run(main())importpetsafeassfclient=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 litterboxesfordeviceindevices:
print(device)importpetsafeassfclient=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())importpetsafeassfclient=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()importpetsafeassfclient=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)importpetsafeassfclient=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()All contributions are welcome. Please, feel free to create a pull request!