Giter Site home page Giter Site logo

sureflap's Introduction

PowerShell SureFlap API Examples

Consume the SureFlap REST API via PowerShell

The device in question: https://www.surepetcare.com/en-gb/pet-doors/microchip-pet-door-connect

Getting Started

Create a SureFlapConfig.ps1 based on the -dist copy in the repo, and put your SureFlap credentials in it.

The script behaviour is mostly self evident. If, like me, you just want to grab a quick snapshot of the state of the device and where your cats are, use the Get-SureFlapStart.ps1 file - this will return an object with everything you need.

It appears to be a pretty well constructed and fully featured REST API. I even managed to accidentally create new objects by POSTing when I meant to GET, and it responds to DELETE correctly too.

Notes

Currently the scripts don't do any checking to see if the parameters are missing so die if they're not provided.

For example, you need to pass the ID of a pet to this:

.\Get-SureFlapPetLocation.ps1 <ID_of_Pet>

and either the household ID, or the ID of a user to:

.\Get-SureFlapUser.ps1 -householdID <householdID> or .\Get-SureFlapUser.ps1 -userID <userID>

Get-Locations.ps1

If you have multiple cat flaps, you can define the flaps, and where they lead (which rooms/zones they connect).

Edit Get-Locations.ps1 and add rows at the top for each pet flap you have.

Format is:

( device_id, "location-inbound", "location-outbound", "name-of-petflap" )

for example: ( 123456, "house", "garden", "backdoor")

leave the final $null row (this makes sure it works when you've manually set pet's inside/outside state)

You can list your flap IDs with: .\Get-SureFlapDevice.ps1 | ?{$_.product_id -gt 1} | Select id, name

Thanks

Thanks to alextoft and his sureflap project for the initial pointers. Further bits of the API were discovered by fiddling with the site itself at https://surepetcare.io.

sureflap's People

Contributors

hdurdle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sureflap's Issues

Invoke-RestMethod : {"error":{"message":[""]}}

Hi,

First thank you for these ps scripts... its working fine... except for the 2 files where i get error messages...
Is it just me? Any tips on how to resolve these?

I have PowerShell running on a RasPi2 Raspbian image...
And i also want to mention, that i have 2 pets in my household, just in case this is maybe related to...

PS /etc/openhab2/scripts/sureflap> ./Get-SureFlapPetLocation.ps1

id          : 10431
name        : EddyMurphy
share_code  : xxxxx
timezone_id : 320
version     : NQ==
created_at  : 19.09.18 16:51:46
updated_at  : 28.12.18 17:41:25
timezone    : @{id=320; name=(UTC+02:00) Europe/Berlin; timezone=Europe/Berlin; utc_offset=7200; created_at=03.08.17 10:35:34; updated_at=03.08.17
              10:37:15}
users       : {@{id=xxxx; owner=True; write=True; version=MQ==; created_at=19.09.18 16:51:46; updated_at=19.09.18 16:51:47}}

Invoke-RestMethod : {"error":{"message":[""]}}
At /etc/openhab2/scripts/sureflap/Get-SureFlapPetLocation.ps1:19 char:8
+ $res = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers -Con ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Method: GET, Re...repetcare.io
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Outside
PS /etc/openhab2/scripts/sureflap> ./Get-SureFlapUser.ps1
Invoke-RestMethod : {"error":{"message":[""]}}
At /etc/openhab2/scripts/sureflap/Get-SureFlapUser.ps1:19 char:8
+ $res = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers -Con ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Method: GET, Re...rShell/6.2.0
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

any Help will be much appreciated...

Thank You!

SetPetLocation do not work anymore

Hi Guys,

I used your scrips often in the past - they are working very smoothly, thank you very much!
But today I have an issue:
I want to set a petlocation and using the script "Set-SureFlapPetPosition". The Pet-ID is 13756.

param (
	[string]$petID,
	[string]$where = 1 #  1 = inside (default), 2 = outside
)
# usage: .\Set-SureFlapPetPosition.ps1 pet_id [where]

. ./Get-SureFlapHousehold.ps1

$uri = $endpoint + "/pet/13756/position"

$headers = @{}
$headers.Add("Authorization","Bearer $token" ) | Out-Null

$postParams = @{
 "where" = "1"
 "since" = (Get-Date -format "2018-07-02T15:50:00+00:00")
} | ConvertTo-Json

$postParams

$res = Invoke-RestMethod -Method Post -Uri $uri -Headers $headers -Body $postParams -ContentType "application/json"
$res.data

After running this script, I get the following error message:

Invoke-RestMethod : {"error":{"message":[""]}}
In C:\Users\Andi\Documents\Dokumente\Katzen\Katzenklappe\API\PowerShell\Set-SureFlapPetPosition.ps1:21 Zeichen:8
+ $res = Invoke-RestMethod -Method Post -Uri $uri -Headers $headers -Bo ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I do not know, what's the reason why the script do not work anymore. It would be really great if someone could help me to find a solution.

Thanks.

Best regards,
Andreas

Question: can you also lock the flap?

Hello,
I'm looking for a very quick way to lock and unlock the cat flap via Api.
Is that also possible with ps?
I use python 3.7 under Windows for my program

regards
Anja

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.