Whistle / Pettracker.com integration

Is there any current integration with Whistle / Pettracker.com so I can determine my pet’s location?

Here’s a hack to make it work. I couldn’t find any way to determine if the pet was outside the zone, so I’m checking the notifications. Make sure you have location notifications turned on at Whistle.

Also, modify PASSWORD, EMAIL, and PETNAME appropriately.

In /etc/hass/scripts/pet_is_home

#!/usr/bin/php
<?php
// API reference from:
// http://jared.wuntu.org/whistle-dog-activity-monitor-undocumented-api/

$data = array("password" => "PASSWORD", "email" => "EMAIL", "app_id" => "com.whistle.WhistleApp");                                                                    
$data_string = json_encode($data);                                                                                   
$ch = curl_init('https://app.whistle.com/api/tokens.json');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string))                                                                       
);                                                                                                                                                                                                                                        
$result = json_decode(curl_exec($ch));
$token = $result->token;
$ch = curl_init('https://app.whistle.com/api/notifications');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");                                                                     
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'X-Whistle-AuthToken:' . $token)
);                                                                                                                   
$notifications = json_decode(curl_exec($ch));
foreach ($notifications as $notification) {
   foreach($notification as $item) {
      if (preg_match('/PETNAME has left/i', $item->message)) {
         echo 'not_home';
         exit;
      } else if (preg_match('/PETNAME is back/i', $item->message)) {
         echo 'home';
         exit;
      } else if (preg_match('/PETNAME is now back/i', $item->message)) {
         echo 'home';
         exit;
      }
   }
}
?>

In sensors.yaml:

##################################################################
## Pet is home
##################################################################
- platform: command_line
  scan_interval: 3600
  name: "Pet is Home"
  command: "/etc/hass/scripts/pet_is_home"
  value_template: '{{ value }}'

Hey I’m really interested in this! Is this still valid? I just drop that scrip in the hass folder?

Yes, it’s still working. The script needs to be made executable, but you can put it anywhere. Just modify the location in the sensor accordingly.

Thanks for replying so many years later! Can you give more detail on how to install this for a noob?
Also how often will the status update of my pets? I want to set up a home/away status so if they leave the sensor gets set to away and a siren goes off in my house. Do you think this is doable? I thought I could do it with Wifi status but the Whistle only checks in on wifi every hour. Thanks!