PetKit Custom Integration

Just wanted to share a new custom component (integration) that I have been working on for PetKit devices (smart pet feeders, litter boxes, water fountain).

The currently supported devices include:

Feeders:

  • Fresh Element Infinity
  • Fresh Element Solo
  • Fresh Element Mini Pro
  • Fresh Element Gemini
  • Fresh Element

Water Fountain:

  • Eversweet 3 Pro
  • Eversweet 5 Mini
  • Eversweet Solo 2

Litter Boxes:

  • Pura X
  • Pura MAX with/without Pura Air deodorizer

Purifiers:

  • Air Magicube

Some notable features:

  • Setup is done through the UI
  • Monitor your feeders along with control of administering extra manual feedings (allowed feeding amounts are customized based on the feeder that you have)
  • Monitor and control your bluetooth-only PetKit water fountain**
  • All the monitoring and control you’d ever want for your litter boxes and some details that are not even presented in the PetKit app.
  • Entities created for pets on your account - for cats, if you own a PetKit litter box, an extra entity is created that shows the most recent weight as measured by the litter box (works even if you have multiple PetKit litter boxes!)

** Getting up-to-date info and controlling PetKit water fountains requires having the BLE relay enabled in the PetKit app (requires a compatible PetKit device that can connect to the bluetooth-only water fountain).

If you do decide to use this integration, please be sure to read all of the documentation on the GitHub repo!

6 Likes

I just received my Eversweet 3 Pro, and great to see that this integration exists. Great work, thanks for building this!

Since I don’t have any other PetKit products, I am unable to use the BLE relay. In theory, would it be possible to have Home Assistant serve as BLE relay and directly connect to the water fountain via BLE? I was trying to sniff the hex values that the fountain sends, but couldn’t make a lot of sense out of it yet.

2 Likes

It would require reverse engineering their Bluetooth communication followed by either adjusting the current library (petkitaio) or creating a new library that will just handle the Bluetooth communication.

I don’t have any plans on dedicating the time that it would take to do this, but I’m open to PRs once someone has done the legwork to reverse engineer the Bluetooth portion.

If you only have the water fountain then I don’t recommend using this integration for it since you won’t get any updated values (you don’t have a device to relay updated info from the water fountain to petkit’s servers).

1 Like

I did some digging and managed to decode the data that the Petkit water fountain advertises via BLE. I’m not very familiar with BLE, GATT or creating custom components, but posting it here in case someone might find it useful or wants to pick it up.

The first 3 bytes contain the header to indicate the type of message:

  • Command: [250, 252, 253]
  • Stream: [250, 252, 254]

The remaining bytes depend on the type of message and the required payload. For the regular advertised device information (command = 230), this is the interpretation of each byte for the Eversweet Pro 3 water fountain on the latest firmware:

# 1-3 Header (CMD vs Stream)
# 4 Command
# 5 Type
# 6 Sequence
# 7-8 Data Length

# 9 Power
# 10 Mode
# 11 Is Night DND
# 12 Breakdown Warning
# 13 Lack Warning
# 14 Filter Warning
# 15-18 Total Water Pump Runtime
# 19 Filter Percent
# 20 Run Status
# 21-24 Today's Pump Runtime

# 25 Smart Working Time
# 26 Smart Sleep Time
# 27 Light Switch
# 28 Light Brightness
# 29-30 Light Schedule Start Time
# 31-32 Light Schedule End Time
# 33 DND Switch
# 34-35 DND Start Time
# 36-37 DND End Time
# 38 ?? (Unknown)

I created a sample Python script to demonstrate the decoding of the bytes, and how to derive other information (i.e. today’s purified water or energy usage) from these values. For other models, there are some small differences in the interpretation.

I haven’t looked into other commands or sending data to the water fountain, but that would probably be the next step.

2 Likes

Looks similar to how I’m currently building BLE messages which are relayed via their BLE relay. Reverse engineering that part of their app was a pain in the ass and more work than I care to admit.

Thanks for the help, working perfectly since I added the TZ=‘Europe/Amsterdam’ environment variable within the k3s yaml config.

Is there any way to get the feeding plan within this integration btw?
It would actually be I think the single thing I would still need the app for.

Are you referring to viewing the current schedule or being able to modify (add/delete) the current schedule?

Both would be nice, seeing when the last successful feeding was done could also be useful.

That would require building out custom service calls and making each unique to the feeder in question - something that will require a decent amount of extra work. It was never implemented since feeding schedules tend to be set and not changed often, if at all. If a modification needed to be done, logging into the app is faster than taking time to create service calls to modify schedules / ensure the user input is valid.

Regarding if feedings were successful: Unfortunately, the mini pro feeder doesn’t report back a key/value for the number of scheduled feedings and of those scheduled how many have dispensed. All of the other feeders do which allows users of those to monitor if scheduled feedings dispensed. There may be a workaround for the mini pro, but I haven’t looked into it.

Well thanks anyway for looking into it, the integration is already really good, would just make it even better :innocent:

@matanza I looked into it a bit more and may release a BLE portion sometime down the road. I’ve gathered enough info from sniffing out BLE packets between the app and phone + looking at their source code that it should be possible. As a side note: Command 213 is sent to retrieve the deviceId & serial number, 200 is sent to get hardware & firmware, and, as you mentioned, 230 has the majority of the current settings. Command 200 will need to be sent as how the data from 230 is parsed depends on both the device typeCode as well as the firmware version. There is also a 86 and 84 command which won’t be needed with a direct BLE connection since that is part of a security check prior to uploading data to their servers.

1 Like

Woohoo this is awesome! :slight_smile: Thanks for considering this - and let me know if there is any sniffing / decoding work I can help with.

If you were like me and are confused about the BLE relay, basically BT devices that normally can’t communicate over WiFi because they are BT only, can piggyback to other Petkit devices via BT and then use their WiFi to talk to the app and HA.

Here is Petkits video showing how to set up. https://www.youtube.com/watch?v=wVDf6W47Gkw

1 Like

Hi,Unfortunately, it’s not working; I’ve tried everything, but nothing works. This is my configuration: Configuration.yaml

# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes
#====================
#=== management Petkit
#====================
petkit:
  username: [email protected] # This is the primary (main) account
  password: *********
  # api_base: http://api.petktasia.com/latest/  # it doesn't work I'm in Europe
  
  api_base: http://api.petkt.com/latest/ # my country is Italy; I think it's correct as a server
  
  # feeding_amount: 20 # It doesn't matter if I wear it
#=====================
homeassistant:
  packages: !include_dir_named packages
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

If I go to search for Entities, I find:

Entity: sensor.feedermini_100020207_state
Status: Offline
Attributes: state: 2 desc: Next feeding: 06:30 status: wifi: ssid: Leonardo da Vinci bssid: f**********8 rsq: -80 pim: 0 ota: 0 overall: 2 offlineTime: 1691051784421 errorPriority: 0 desiccantLeftDays: 0 feeding: 0 food: 1 batteryStatus: 0 runtime: 1060 batteryPower: 4 desiccantTime: 0
 shared: null icon: mdi:information friendly_name: state baby food dispenser

Another thing, is it normal that when I add the Petkit integration, it responds: This device cannot be added from the user interface You can add this device by adding it to your ‘configuration.yaml’ file. See the documentation for more information."

If you have any further questions or need assistance with this configuration, please feel free to ask.

Hi, you are not using my integration here. Instead you’re trying to setup another PETKIT integration. In order to use my integration you have to delete the one you have installed (both what you have in your configuration.yaml regarding PETKIT and the PETKIT integration from your custom_components folder).

My integration repo is linked at the top of this thread and has setup instructions/extra info.

Thank you RobertD502, it WORKS now. I hadn’t added the files to the custom_components directory, so when I was going through the setup, it was telling me to manually configure the configuration.yaml file (that was the old procedure, which no longer works).

I’m thinking of getting one of these water fountains, I’ve read through the comments but couldn’t work out it out.
Would I be unable to integrate the fountain as it would be the only petkit device I have?

Correct. Getting updated data/controlling the water fountain requires a Petkit device that acts as a BLE relay.

@RobertD502 Thanks for this. I installed it last night. I have 2 of the Petkit PuraMAX. So far works well.

If you need me to test or try something let me know.

1 Like

What other devices would I need to have to make this integration work?
In other words, what are the PETKIT devices that can work as proxy?

Best regards
Nuno