[BETA RELEASE] Whistle 3 Pet Tracker - Presence and Battery DTH

I’ve written a very basic device handler to pull Whistle presence and battery info from Whistle directly into ST, every minute. Due to my very limited programming skills, you need to do a bit of leg work to get a few ID values for the initial setup, explained below. If anyone wants to take this code and run with it, feel free, I will in no way be offended. This hasn’t been extensively tested, but that’s what the community is for.

NOTE: Whistle does not have a supported API. This may break at any time.

https://github.com/swamplynx/SmartThingsGroovy/blob/master/devicetypes/swamplynx/whistle-presence.src/whistle-presence.groovy

  1. Download and install, and publish the device handler in the IDE.

  2. From My Devices in the IDE, create a New Device. You will need to give the device a Name (e.g. Your Pet), pick an arbitrary hex number (e.g. 0101EE) for the Device Network ID, and set the Device Type to “Whistle Presence.”

  3. Go into your ST app and open your new “Your Pet” device. Click the gear, enter your Whistle email and password, and you will see the two values we need to extract from your Whistle account. You can also upload a picture of Fido here if you like.

Whistle Home ID - This is a number that identifies the “Safe Zone” of your house, and where you want the pet to be marked Present by ST.
Whistle Pet ID - This is a number that identifies your pet in your Whistle account.

So how do we get this information? We need to make requests to the Whistle server and view the results.

  1. Downloand Postman for your desktop computer at: Download Postman | Get Started for Free
    This software enables you to make customized HTTP requests and view the results.

  2. First we need to get an access token. We are going to do this by making a HTTP POST request to Whistle with some specific headers, and your Whistle email and password.

First, under the Headers tab, populate the code values below as seen in the following screenshot:

“Accept”: “application/vnd.whistle.com.v4+json”,
“Content-Type”: “application/json”,
“Connection”: “keep-alive”,
“Accept-Language”: “en-us”,
“Accept-Encoding”: “br, gzip, deflate”,
“User-Agent”: “Winston/2.5.3 (iPhone; iOS 12.0.1; Build:1276; Scale/2.0)”

Next, under the Body tap, enter your Whistle email and password as form data as seen in the image below:

Click Send. If done correctly the server will reply with an auth token for your account:

  1. Copy the long auth token (the refresh one is not needed). We are going to use this to make another request to Whistle.

  2. Now we need to get the Whistle IDs for the pet you want to track and home location you want them to be marked present at… First, de-select the email and password body. We don’t need this anymore now that we have an auth token. Go to the Authorization tab, select Bearer Token, and paste your token in.

  3. Here we get the pet ID. Send an HTTP GET (you must change this from POST) to the address shown in the photo below. If done correctly you should get a listing of pets in the response window. Find and copy the “id:” number for the pet you want to link to the ST device. Paste this number into the device preferences in the app or IDE as described above.

  4. Next let’s get the home ID of the Whistle “Safe Place” you want to be considered home for the pet. We need to do this since you can have multiple safe places and we only want to mark the pet present at your actual home. Update the request address to the one below in the photo. You’ll see a list of locations and “id:” number for the location. Find your home, copy the number and paste this number into the device preferences in the app or IDE as described above.

That’s it. You’re done! Enjoy.

5 Likes

I haven’t tried it yet, but will.

One question, you don’t get a “push” with this setup? You only get the information when you check? Right?

Correct. No push. It only updates when it polls the server. I have it set to 2 min on my end currently and it is working great.

1 Like

I can’t seem to get the auth token request to work. I get the error:
{“errors”:[{“message”:“Invalid email address or password”,“code”:“invalid”,“field”:“email”}]}

I know my email address and password are correct because I have logged in\out of the Whistle App multiple times with the values I am using in Postman. Here is the screenshot of the post request and header info:

What am I doing wrong?

Sorry. My initial instructions were wrong. The email and password need to be in the body not the header. I’ll correct the instructions. I also improved the DTH so you don’t need to paste the token in there, but you still need the token to get the pet ID and home ID with Postman.

Good news is I’ve been using it for weeks and it is flawless. I have it refresh every two minutes without issue.

1 Like

After putting the login credentials in the body, I was able to get it to work. It’s been running overnight and this morning I see there are numerous updates for the battery level, so looks like it is working as expected.

Thanks for putting this together. It is a pretty cool integration and will replace the klunky IFTTT solution (which will no longer work since the gmail API is changing March 31) I had been using. I use it for my automated dog house (lights, heater, air conditioner, water sensor) to set it inactive when the dog is not present so that I am not heating or cooling an empty dog house.

2 Likes

Great to hear! I hope to have some time in the next month to figure out how to add code to parse the list of home and pet IDs in the account, so that the song and dance with Postman is no longer necessary, but that’s still beyond my rudimentary programming skills at this point.

For those using this DTH, I recently pushed an update to try to remediate an issue where the automatic refresh function keeps crapping out. I’m going to continue to monitor, but you should update from the GitHub to incorporate the additional scheduler.

Just wanted to say thanks for the effort. Since Google changed some of their APIs the IFTT integration hasn’t worked. Just installed this and anxious to give it a shot.

Thanks again!

1 Like

This is awesome. One comment and one question. The step above appears to be wrong - this should be a GET, not a POST (I got 502 bad gateway from the POST).

You mentioned updating the refresh rate. Where do you configure this? I didn’t see it in settings in the app, nor the device. Did you mean you modified in the code when creating the DTH?

Thanks a ton for making this available!

1 Like

I clearly need to up date the instructions…

The refresh rate is hard coded to be every minute now. I found this to work well with ST’s scheduler and the Whistle servers, so I removed the option in the device.

You’re correct on the POST/GET. I went dyslexic for a second in the instructions and flipped them.

Glad you got it working!

You built, documented, and are providing free support for a nifty integration of a device into SmartThings - I’m not complaining at all :slight_smile: And yeah - I got it working without much trouble.

A couple other notes, not about the integration but general experience:

  • mine is logging 1% battery decrement every 24 minutes. That projects to 2400 minutes from 100% to empty, which is 40 hours, which is disappointing since I need to charge every night (my log looks like that was in the home wifi zone, but perhaps there are boundaries I don’t understand).
  • the whistle app seems suuuuuper annoying. It was sending me notices like every 2 minutes telling me my cat was home. Ugh. I didn’t seem to be able to control this, but it’s much better to just be able to fold this into my regular ST system and notifications.
  • this was the first time I bothered to actually look at a device handler. They seem super easy and maybe now some day I’ll work on one.

Not ST related at all, but seems like your Whistle might have issues connecting to your WiFi. When it is on WiFi properly it sips battery. Mine last close to 7 days with at least two walks/run with my dog. The Whistle notifications take two factors to trigger. One, it has to fall off the WiFi beacon, then two it has to be out of the geofence. The geofence isn’t super accurate, so it helps if your WiFi is strong and your fence area is on the larger size.

Thank you - I reached out to Whistle support but haven’t heard back yet. The burndown rate was really surprising to me and I’m glad to hear this could be a (hopefully transient / soluble) misbehavior.

I’m only getting one update per day at 5am. How do I change polling time?

It sounds like the whistle is losing connection with your Wi-Fi. That explains both the battery drain and the constant notifications.

If you feel your 2.4 MHz Wi-Fi is strong, get in touch with Whistle support. They have some diagnostics they can look at.

It’s written to poll every minute. What are you seeing in your live logs? In the app you will only see an update if the presence changes.

It’s been totally rock solid for me since I wrote it. I only use the Classic app, so no idea if it works in the new app.

Here’s a look at the log, it’s only polling at around 5am.

[2020-07-10 4:54:58.877 AM EDT
8 hours ago ]COMMAND poll poll command was sent to Sawyer true
[2020-07-10 4:54:58.867 AM EDT
8 hours ago ] DEVICE presence present Sawyer has arrived true
[2020-07-10 4:54:58.810 AM EDT
8 hours ago ]DEVICE battery 10 Sawyer battery is 10% true
[2020-07-09 5:01:29.459 AM EDT
1 day ago ]COMMAND poll poll command was sent to Sawyer true
[2020-07-09 5:01:29.447 AM EDT
1 day ago ] DEVICE presence not present Sawyer presence is not present true
[2020-07-09 5:01:29.414 AM EDT
1 day ago ] DEVICE battery 45 Sawyer battery is 45% true
[2020-07-08 4:54:26.168 AM EDT
2 days ago ] COMMAND poll poll command was sent to Sawyer true
[2020-07-08 4:54:26.152 AM EDT
2 days ago ]DEVICE presence present Sawyer presence is present false
[2020-07-08 4:54:26.135 AM EDT
2 days ago ] DEVICE battery 47 Sawyer battery is 47% true
[2020-07-07 4:56:08.461 AM EDT

Try clicking the refresh button on the main screen of the device. I have the runEvery1Minute (poll) command under the refresh function, so if you have never clicked that the schedule poll may have never been applied and the 5am poll is just ST doing its thing.

That did it! Thanks!

1 Like