petkit icon indicating copy to clipboard operation
petkit copied to clipboard

Feature Request: Petkit Fit P3 Tracker Support

Open rvincemt opened this issue 2 years ago β€’ 17 comments

Obtaining Fitness Data from these trackers can help greatly. I can offer to work closely and test this one out.

rvincemt avatar Feb 07 '22 17:02 rvincemt

Capture related API requests and responses.

al-one avatar Feb 10 '22 08:02 al-one

POST /latest/discovery/device_roster HTTP/1.1 Host: api.petktasia.com X-Session: 1898263f755244e0aa910928986781bbkFYkyU2MS6ubnwT2eB79 Content-Type: application/x-www-form-urlencoded Accept: / X-Location: 121.053307,14.572200 X-Timezone: 8.0 F-Session: 1898263f755244e0aa910928986781bbkFYkyU2MS6ubnwT2eB79 Accept-Language: en-PH;q=1, fil-PH;q=0.9 Accept-Encoding: gzip, deflate X-Api-Version: 8.7.2 X-Client: ios(15.3.1;iPhone12,5) Content-Length: 12 User-Agent: PETKIT/8.7.2 (iPhone; iOS 15.3.1; Scale/3.00) X-TimezoneId: Asia/Manila X-Img-Version: 1 X-Locale: en_US Connection: keep-alive

--EOF-1646078192501- Response-Header:<<--EOF-1646078192501- HTTP/1.1 200 OK Date: Mon, 28 Feb 2022 19:44:01 GMT Content-Type: application/json;charset=utf-8 Content-Length: 1011 Cache-Control: no-cache Proxy-Connection: keep-alive

--EOF-1646078192501- Request-Body:<<--EOF-1646078192501- day=20220301 --EOF-1646078192501-

Response-Body:<<--EOF-1646078192501- {"result":{"p3d":{"enable":1},"t4":{"enable":1},"r2":{"enable":1},"p3c":{"enable":1},"aqr":{"enable":1},"p3":{"enable":1},"w5c":{"enable":1},"cozy":{"gearsTotal":6.0,"enable":1,"tempunit":0,"sTempMin":10,"isShowDeviceSafetyClause":0,"gearsOffset":3.0,"sTempMax":42},"feeder":{"isShowDeviceSafetyClause":0},"h2":{"enable":0},"tools":[{"type":"walkpet","data":{}},{"type":"weight"},{"type":"remind","data":{}}],"d3":{"enable":1},"d4":{"enable":1},"w5n":{"enable":1},"w5":{"enable":1},"devices":[{"type":"P3","data":{"createdAt":"2022-02-06T09:20:09.000Z","syncTime":"2022-02-28T19:37:08.000Z","lowBattery":0,"name":"Cotton's Activity Monitor","autoSync":1,"id":100000852,"battery":90,"firmware":52,"relation":{"petIds":["100398102"],"userId":"100288508"},"typeCode":1,"hardware":1}}],"k2":{"enable":1},"go":{"hasMarks":0,"maxMarksPerRoute":30,"markEnabled":1},"k3":{"enable":1},"aq":{"enable":1},"feedermini":{"isShowDeviceSafetyClause":0},"w4x":{"enable":1},"appbanner":[],"t3":{"enable":1},"aq1s":{"enable":1}}} --EOF-1646078192501-

rvincemt avatar Feb 28 '22 20:02 rvincemt

Method: POST Protocol-Version: HTTP/1.1 Protocol: http Host: api.petktasia.com File: /latest/discovery/device_roster Remote-Address: 47.74.226.166 Client-Address: 192.168.1.13 Start-Time: 2022-03-01T03:44:10.329+08:00 Request-Begin-Time: 2022-03-01T03:44:10.330+08:00 Request-Time: 2022-03-01T03:44:10.330+08:00 Response-Time: 2022-03-01T03:44:10.824+08:00 End-Time: 2022-03-01T03:44:10.824+08:00 Request-Header-Size: 612 Response-Header-Size: 249 Request-Body-Size: 12 Response-Body-Size: 1011 Request-Body-Decoded: false Response-Body-Decoded: false Request-Header:<<--EOF-1646078192502- POST /latest/discovery/device_roster HTTP/1.1 Host: api.petktasia.com X-Session: 1898263f755244e0aa910928986781bbkFYkyU2MS6ubnwT2eB79 Content-Type: application/x-www-form-urlencoded Accept: / X-Location: 121.053307,14.572200 X-Timezone: 8.0 F-Session: 1898263f755244e0aa910928986781bbkFYkyU2MS6ubnwT2eB79 Accept-Language: en-PH;q=1, fil-PH;q=0.9 Accept-Encoding: gzip, deflate X-Api-Version: 8.7.2 X-Client: ios(15.3.1;iPhone12,5) Content-Length: 12 User-Agent: PETKIT/8.7.2 (iPhone; iOS 15.3.1; Scale/3.00) X-TimezoneId: Asia/Manila X-Img-Version: 1 X-Locale: en_US Connection: keep-alive

--EOF-1646078192502- Response-Header:<<--EOF-1646078192502- HTTP/1.1 200 OK Date: Mon, 28 Feb 2022 19:44:07 GMT Content-Type: application/json;charset=utf-8 Content-Length: 1011 Cache-Control: no-cache Proxy-Connection: keep-alive

--EOF-1646078192502- Request-Body:<<--EOF-1646078192502- day=20220301 --EOF-1646078192502- Response-Body:<<--EOF-1646078192502- {"result":{"p3d":{"enable":1},"t4":{"enable":1},"r2":{"enable":1},"p3c":{"enable":1},"aqr":{"enable":1},"p3":{"enable":1},"w5c":{"enable":1},"cozy":{"gearsTotal":6.0,"enable":1,"tempunit":0,"sTempMin":10,"isShowDeviceSafetyClause":0,"gearsOffset":3.0,"sTempMax":42},"feeder":{"isShowDeviceSafetyClause":0},"h2":{"enable":0},"tools":[{"type":"walkpet","data":{}},{"type":"weight"},{"type":"remind","data":{}}],"d3":{"enable":1},"d4":{"enable":1},"w5n":{"enable":1},"w5":{"enable":1},"devices":[{"type":"P3","data":{"createdAt":"2022-02-06T09:20:09.000Z","syncTime":"2022-02-28T19:37:08.000Z","lowBattery":0,"name":"Cotton's Activity Monitor","autoSync":1,"id":100000852,"battery":90,"firmware":52,"relation":{"petIds":["100398102"],"userId":"100288508"},"typeCode":1,"hardware":1}}],"k2":{"enable":1},"go":{"hasMarks":0,"maxMarksPerRoute":30,"markEnabled":1},"k3":{"enable":1},"aq":{"enable":1},"feedermini":{"isShowDeviceSafetyClause":0},"w4x":{"enable":1},"appbanner":[],"t3":{"enable":1},"aq1s":{"enable":1}}} --EOF-1646078192502-

rvincemt avatar Feb 28 '22 20:02 rvincemt

Method: POST Protocol-Version: HTTP/1.1 Protocol: http Host: api.petktasia.com File: /latest/p3/deviceData Remote-Address: 47.74.226.166 Client-Address: 192.168.1.13 Start-Time: 2022-03-01T03:44:10.329+08:00 Request-Begin-Time: 2022-03-01T03:44:10.329+08:00 Request-Time: 2022-03-01T03:44:10.330+08:00 Response-Time: 2022-03-01T03:44:10.858+08:00 End-Time: 2022-03-01T03:44:10.858+08:00 Request-Header-Size: 602 Response-Header-Size: 217 Request-Body-Size: 12 Response-Body-Size: 64 Request-Body-Decoded: false Response-Body-Decoded: false Request-Header:<<--EOF-1646078192502- POST /latest/p3/deviceData HTTP/1.1 Host: api.petktasia.com X-Session: 1898263f755244e0aa910928986781bbkFYkyU2MS6ubnwT2eB79 Content-Type: application/x-www-form-urlencoded Accept: / X-Location: 121.053307,14.572200 X-Timezone: 8.0 F-Session: 1898263f755244e0aa910928986781bbkFYkyU2MS6ubnwT2eB79 Accept-Language: en-PH;q=1, fil-PH;q=0.9 Accept-Encoding: gzip, deflate X-Api-Version: 8.7.2 X-Client: ios(15.3.1;iPhone12,5) Content-Length: 12 User-Agent: PETKIT/8.7.2 (iPhone; iOS 15.3.1; Scale/3.00) X-TimezoneId: Asia/Manila X-Img-Version: 1 X-Locale: en_US Connection: keep-alive

--EOF-1646078192502- Response-Header:<<--EOF-1646078192502- HTTP/1.1 404 Not Found Date: Mon, 28 Feb 2022 19:44:07 GMT Content-Type: application/json; charset=utf-8 Content-Length: 64 Proxy-Connection: keep-alive

--EOF-1646078192502- Request-Body:<<--EOF-1646078192502- id=100000852 --EOF-1646078192502- Response-Body:<<--EOF-1646078192502- {"error":{"code":97,"msg":"App is out of date, please upgrade"}} --EOF-1646078192502-

rvincemt avatar Feb 28 '22 20:02 rvincemt

Method: POST Protocol-Version: HTTP/1.1 Protocol: http Host: api.petktasia.com File: /latest/p3/deviceAllData Remote-Address: 47.74.226.166 Client-Address: 192.168.1.13 Start-Time: 2022-03-01T03:44:10.329+08:00 Request-Begin-Time: 2022-03-01T03:44:10.329+08:00 Request-Time: 2022-03-01T03:44:10.330+08:00 Response-Time: 2022-03-01T03:44:10.902+08:00 End-Time: 2022-03-01T03:44:10.902+08:00 Request-Header-Size: 605 Response-Header-Size: 248 Request-Body-Size: 31 Response-Body-Size: 742 Request-Body-Decoded: false Response-Body-Decoded: false Request-Header:<<--EOF-1646078192502- POST /latest/p3/deviceAllData HTTP/1.1 Host: api.petktasia.com X-Session: 1898263f755244e0aa910928986781bbkFYkyU2MS6ubnwT2eB79 Content-Type: application/x-www-form-urlencoded Accept: / X-Location: 121.053307,14.572200 X-Timezone: 8.0 F-Session: 1898263f755244e0aa910928986781bbkFYkyU2MS6ubnwT2eB79 Accept-Language: en-PH;q=1, fil-PH;q=0.9 Accept-Encoding: gzip, deflate X-Api-Version: 8.7.2 X-Client: ios(15.3.1;iPhone12,5) Content-Length: 31 User-Agent: PETKIT/8.7.2 (iPhone; iOS 15.3.1; Scale/3.00) X-TimezoneId: Asia/Manila X-Img-Version: 1 X-Locale: en_US Connection: keep-alive

--EOF-1646078192502- Response-Header:<<--EOF-1646078192502- HTTP/1.1 200 OK Date: Mon, 28 Feb 2022 19:44:07 GMT Content-Type: application/json;charset=utf-8 Content-Length: 742 Access-Control-Allow-Origin: * Cache-Control: no-cache Proxy-Connection: keep-alive

--EOF-1646078192502- Request-Body:<<--EOF-1646078192502- day=20220301&deviceId=100000852 --EOF-1646078192502- Response-Body:<<--EOF-1646078192502- {"result":{"activityRecord":{"playSum":0,"total":440,"walkSum":440},"calorieRecord":{"activityCalorieSum":0,"basicCalorieSum":47,"total":47},"data24":[2684,3860,28190,1680,4559,2550,3135,1337,2382,0,7503,3705,2938,1813,365,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],"day":20220301,"sleepDetail":{"day":20220301,"deepSleep":1550,"deepSleeps":[[4020,4250],[5870,6020],[7600,7960],[9530,9780],[11400,11960]],"lightSleep":8260,"lightSleeps":[[310,1570],[2760,4020],[4610,5870],[6340,7600],[8270,9530],[10140,11400],[12270,12970]],"total":9810}}} --EOF-1646078192502-

rvincemt avatar Feb 28 '22 20:02 rvincemt

Method: POST Protocol-Version: HTTP/1.1 Protocol: http Host: api.petktasia.com File: /latest/p3/deviceData Remote-Address: 47.74.226.166 Client-Address: 192.168.1.13 Start-Time: 2022-03-01T03:44:10.406+08:00 DNS-Duration: 0 Connect-Duration: 122 Request-Begin-Time: 2022-03-01T03:44:10.529+08:00 Request-Time: 2022-03-01T03:44:10.529+08:00 Response-Time: 2022-03-01T03:44:11.088+08:00 End-Time: 2022-03-01T03:44:11.088+08:00 Request-Header-Size: 602 Response-Header-Size: 248 Request-Body-Size: 12 Response-Body-Size: 814 Request-Body-Decoded: false Response-Body-Decoded: false Request-Header:<<--EOF-1646078192502- POST /latest/p3/deviceData HTTP/1.1 Host: api.petktasia.com X-Session: 1898263f755244e0aa910928986781bbkFYkyU2MS6ubnwT2eB79 Content-Type: application/x-www-form-urlencoded Accept: / X-Location: 121.053307,14.572200 X-Timezone: 8.0 F-Session: 1898263f755244e0aa910928986781bbkFYkyU2MS6ubnwT2eB79 Accept-Language: en-PH;q=1, fil-PH;q=0.9 Accept-Encoding: gzip, deflate X-Api-Version: 8.7.2 X-Client: ios(15.3.1;iPhone12,5) Content-Length: 12 User-Agent: PETKIT/8.7.2 (iPhone; iOS 15.3.1; Scale/3.00) X-TimezoneId: Asia/Manila X-Img-Version: 1 X-Locale: en_US Connection: keep-alive

--EOF-1646078192502- Response-Header:<<--EOF-1646078192502- HTTP/1.1 200 OK Date: Mon, 28 Feb 2022 19:44:07 GMT Content-Type: application/json;charset=utf-8 Content-Length: 814 Access-Control-Allow-Origin: * Cache-Control: no-cache Proxy-Connection: keep-alive

--EOF-1646078192502- Request-Body:<<--EOF-1646078192502- id=100000852 --EOF-1646078192502- Response-Body:<<--EOF-1646078192502- {"result":{"activityCalorie":0,"autoSync":1,"basicCalorie":47,"battery":90,"batteryUpdatedAt":"2022-02-28T19:37:06.000Z","createdAt":"2022-02-06T09:20:09.000Z","data":[2684,3860,28190,1680,4559,2550,3135,1337,2382,0,7503,3705,2938,1813,365,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],"firmware":52,"hardware":1,"id":100000852,"lowBattery":0,"mac":"a4c1381cc3e1","name":"Cotton's Activity Monitor","relation":{"petIds":["100398102"],"userId":"100288508"},"secret":"c645c012","sn":"26211113H20609","soundId":0,"syncTime":"2022-02-28T19:37:08.000Z","typeCode":1,"updatedAt":"2022-02-28T19:37:08.000Z","voltage":2825}} --EOF-1646078192502-

rvincemt avatar Feb 28 '22 20:02 rvincemt

Rest of the API requests and responses: https://pastebin.com/vY97pvdb

rvincemt avatar Feb 28 '22 20:02 rvincemt

Upgrade and try.

al-one avatar Mar 10 '22 15:03 al-one

It's working and pulling data! Although if you don't mind, is there some way that we can modify the values reported from seconds to hours:minute format?

Thanks. !

image image

rvincemt avatar Mar 13 '22 05:03 rvincemt

@rvincemt You can use template.

al-one avatar Mar 14 '22 10:03 al-one

@rvincemt Just did it few days ago, in case you need it. (can't get code format display correctly, so check the screenshot).

ζˆͺεœ– 2022-03-17 δΈ‹εˆ12 26 17

bluefoxlee avatar Mar 17 '22 04:03 bluefoxlee

Is there any way to gather data from these locally without having to open the app and tap each cat?

barrelltitor avatar Jan 19 '23 09:01 barrelltitor

@barrelltitor Right now, I don't think so, since the collars are bluetooth-only - your phone talk to them, gets the information, and uploads to the PetKit cloud. If someone sniffs out the communication and manage to talk to the collar directly from HA, then maybe it's possible to bypass that and do it all locally, but....... seems like a headache, looking from the outside, for such a niche device 😞

igorsantos07 avatar Feb 15 '23 23:02 igorsantos07

@al-one I would suggest you also update the README with a list of supported devices (or device types, so you don't have to update it every time PetKit releases a new iteration). By quickly checking it, I thought this repo only supported the feeders (mainly because there's a feed option in the sample config).

Otherwise, thanks!!

igorsantos07 avatar Feb 15 '23 23:02 igorsantos07

@igorsantos07 the solution was...messy. Multiple android devices to cover the zones the pets would be with tasker automations to actually go on the app and press the sync button, but it works for now. Figured to share in case anyone else wanted this automated

barrelltitor avatar May 14 '23 10:05 barrelltitor

LOL that's quite dirty, indeed. How did you come up with that? Is it possible to identify if the collars are in range, so Tasker can fire the clicking? This could definitely become a post in the forums :)

I've been (very slowly) looking into hacking the communication protocol with the collars, so it would be possible to grab more information (the stat history instead of just the current number of most stats) and break free from the app. From what I could see, the lack of information is an issue coming from their API, so there's no way this extension would go around that.

igorsantos07 avatar May 17 '23 20:05 igorsantos07

@igorsantos07 I was using tasker already for some other things and I figured since I already had a tablet on the wall might as well use it.

If you have devices that can send bluetooth scans(maybe even the HA device itself) and do things if they detect a device(might be possible to do it from tasker too, not sure), as long as it finds the collars it can just see if they're in range and then fire the tasker action using autoremote, and you can send the data to HA to process, or try using tasker to do it, though HA getting the raw data would be better imo, you can make a webhook template device like that

I'd be very interested in any progress you make on that. I know it's not a very widely used device, but it would be very useful.

You could also try maybe asking petkit themselves if they can provide some information for that, or try decompiling the app as someone suggested on the forum.

barrelltitor avatar May 25 '23 11:05 barrelltitor