Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install questions #4

Open
chriszuckerberg opened this issue Oct 14, 2018 · 34 comments
Open

Install questions #4

chriszuckerberg opened this issue Oct 14, 2018 · 34 comments

Comments

@chriszuckerberg
Copy link

Please, can you tell me how to install this great code?

@dib0
Copy link

dib0 commented Oct 17, 2018

Hi!

To do this in Linux: first clone the repo:
git clone https://github.com/rcastberg/sure_petcare.git

The run:
python3 setup.py install
or
sudo python3 setup.py install

Then the module should be installed.

@chriszuckerberg
Copy link
Author

chriszuckerberg commented Oct 19, 2018 via email

@strix-technica
Copy link
Collaborator

@chriszuckerberg

What must i do? Or how do I properly call the application?

The error you're getting suggests that the API can't see any door devices attached to the account credentials you supplied.

If you want to try to resolve the problem yourself, use sp_cli.py and also the update() method in the main API class as a guide to instantiating the API in an interactive Python interpreter, then examine the data retrieved by each step of the initial update mechanism. You can find the results in the .cache instance attribute.

Beyond that, I'm afraid I can't supply much more support than that in the circumstances. I wanted to develop this API into a more end-user friendly package, but SurePet isn't keen on that last I knew.

@rsewell97
Copy link

Hey, is there any support for windows?

I'm obviously getting the error [WinError 3] The system cannot find the path specified: '/sys/class/net/' . Tried replacing the returned MAC manually, but when I do that it can't find any flaps on my account? Any other pointers?

Cheers and good work!

@rcastberg
Copy link
Owner

rcastberg commented Dec 19, 2018 via email

@dzjr
Copy link

dzjr commented Dec 23, 2018

@chriszuckerberg

What must i do? Or how do I properly call the application?

The error you're getting suggests that the API can't see any door devices attached to the account credentials you supplied.

If you want to try to resolve the problem yourself, use sp_cli.py and also the update() method in the main API class as a guide to instantiating the API in an interactive Python interpreter, then examine the data retrieved by each step of the initial update mechanism. You can find the results in the .cache instance attribute.

Beyond that, I'm afraid I can't supply much more support than that in the circumstances. I wanted to develop this API into a more end-user friendly package, but SurePet isn't keen on that last I knew.

i have the same problem....

i am sure that the email address & PW are right....

can i adjust it manual somewhere?

i tried:
./sp_cli.py --update -e [email protected] -p password
also tried it wiht sudo and without ./ and all other combinations

all times the output is:

is the location of the program maybe the problem?
i have it in ~/domoticz/scripts/Sureflap/sure_petcare
because i want to try to connect i in my domoticz system.

`
Traceback (most recent call last):
File "./sp_cli.py", line 157, in
main( sys.argv )
File "./sp_cli.py", line 77, in main
sp.update()
File "/home/pi/domoticz/scripts/Sureflap/sure_petcare/sure_petcare/init.py", line 337, in update
self.update_device_ids()
File "/home/pi/domoticz/scripts/Sureflap/sure_petcare/sure_petcare/init.py", line 419, in update_device_ids
household['default_flap'] = list(flaps.keys())[0]
IndexError: list index out of range

`

@therefromhere
Copy link
Contributor

@chriszuckerberg , @dzjr which model of catflap do you have?

If it's the new "Cat Door Connect" (https://www.surepetcare.com/en-nz/pet-doors/microchip-cat-flap-connect), as opposed to the original, larger "Pet Door Connect" (https://www.surepetcare.com/en-nz/pet-doors/microchip-pet-door-connect), the current code (at ed59e44) doesn't have its device id.

My pull request #7 should fix that.

@chriszuckerberg
Copy link
Author

Hi!

To do this in Linux: first clone the repo:
git clone https://github.com/rcastberg/sure_petcare.git

The run:
python3 setup.py install
or
sudo python3 setup.py install

Then the module should be installed.

Ok, thank you, great application!
Now it works for incomprehensible reasons. The only change was on my network to release IPv6 on the Fritzbox?
Now I have only the question: Do I always have to do a "sudo sp_cli.py --update" before querying "sudo sp_cli.py ls_pets"?

@chriszuckerberg
Copy link
Author

chriszuckerberg commented Mar 11, 2019

Ok. a day after, the next Problem:

alec@Server:~$ sudo sp_cli.py --update

Traceback (most recent call last):
File "/usr/local/bin/sp_cli.py", line 4, in
import('pkg_resources').run_script('sure-petcare==0.1', 'sp_cli.py')
File "/usr/local/lib/python3.6/dist-packages/pkg_resources/init.py", line 750, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/local/lib/python3.6/dist-packages/pkg_resources/init.py", line 1527, in run_script
exec(code, namespace, namespace)
File "/usr/local/lib/python3.6/dist-packages/sure_petcare-0.1-py3.6.egg/EGG-INFO/scripts/sp_cli.py", line 156, in
main( sys.argv )
File "/usr/local/lib/python3.6/dist-packages/sure_petcare-0.1-py3.6.egg/EGG-INFO/scripts/sp_cli.py", line 75, in main
with sp:
File "/usr/local/lib/python3.6/dist-packages/sure_petcare-0.1-py3.6.egg/sure_petcare/init.py", line 646, in enter
raise SPAPICacheLocked()
sure_petcare.SPAPICacheLocked

Solution:
sudo rm .surepet.cache
sudo rm .surepet.cache.lock
sudo sp_cli.py -e [email protected] -p password --update

@staebchen0
Copy link

Hi,
I have two questions about the project:

  1. Can I also use the code without Home Assistant or is it only in connection with the Home Assistant?
  2. Does the project run under Windows 8?

I successfully installed the setup under windows.
Can I connect to the flap now?

@chriszuckerberg
Copy link
Author

Hi,
I have two questions about the project:
1. Can I also use the code without Home Assistant or is it only in connection with the Home Assistant?
2. Does the project run under Windows 8?
I successfully installed the setup under windows.
Can I connect to the flap now?

I run the code directly on Ubuntu 18.04.2 LTS and ask the status via my daschboard via socket connection. It would be desirable that the query is a little faster to view the status faster, but the delay of about 30 seconds is probably due to the server at Sure-Petcare.
Sunny greetings from the Allgäu

@staebchen0
Copy link

I did not install Ubuntu.
At the moment everything should run under Windows and later on the rasberry Pi

I have only recently started working with python.
The installation of the packages was successful.
I do not know exactly how to create a test script, for example, to get the battery status.
Everything is listed in init.py, but I'm not sure how to build the script.

Do you have an example?
I put the test script into the directory ure_petcare-master \ sure_petcare

@chriszuckerberg
Copy link
Author

chriszuckerberg commented Apr 26, 2019

I did not install Ubuntu.
At the moment everything should run under Windows and later on the rasberry Pi
I have only recently started working with python.
The installation of the packages was successful.
I do not know exactly how to create a test script, for example, to get the battery status.
Everything is listed in init.py, but I'm not sure how to build the script.
Do you have an example?
I put the test script into the directory ure_petcare-master \ sure_petcare

Rasperry also works under Linux, just like Ubuntu.
possible arguments are: one of ls_flaps, ls_house, ls_pets, pet_tl, set_hid
Entry in the directory sure_petcare:
./sp_cli.py ls_flaps
comes the message:
Cat Flap (123456) at 1.332V is Unlocked
The battery status is not directly visible. Here you would have to extract the value 1.332V by script and define yourself as good or bad.

For example, I check via a regular thread only if the cat is in the house or out of the house and send with c.write_message ("cat_out") the state to my dashboard. The battery status tells me the normal app, so for me uninteresting.

# Sure-flap
def SureFlap ():
while true:
os.system ("sp_cli.py --update")
time.sleep (10)
proc = poles ('sp_cli.py ls_pets', shell = true, stdout = PIPE,)
output = proc.communicate () [0]
if (output.find ("Outside")> 0):
#print "Sheila outside."
for c in ws_clients:
c.write_message ("cat_out")
else:
#print "Sheila inside"
for c in ws_clients:
c.write_message ("cat_in")
time.sleep (10)

Excuse me, I do not know why the code can not be structured here :-(

@staebchen0
Copy link

staebchen0 commented Apr 26, 2019

Thank you for your help :-)

I have the command: ./sp_cli.py ls_flaps
tried it out

The following message appears:

Sure Petcare Connect CLI

--- * WARNING * ---

etc....

Although I created a user with a readonly role in the household and executed the following commands
sp_cli.py --update -e [email protected] -p xxxxxxx
and then
sp_cli.py --update

Did I forget something else?

@chriszuckerberg
Copy link
Author

chriszuckerberg commented Apr 26, 2019

Thank you for your help :-)

I have the command: ./sp_cli.py ls_flaps
tried it out

The following message appears:

Sure Petcare Connect CLI

--- * WARNING * ---

etc....

Although I created a user with a readonly role in the household and executed the following commands
sp_cli.py --update -e [email protected] -p xxxxxxx
and then
sp_cli.py --update

Did I forget something else?

Please try first with complete rights or with sudo.
I have the experience that you have to do "sp_cli.py --update -e [email protected] -p xxxxxxx" only once, after that "sp_cli.py --update" always goes.
--update seems to read the data from the server and put it in the file ~/.surepet.cache or ~/.surepet.cache.lock which you can read out with sp_cli.py, see my entries above.

The rights are here:
ls -alh in home directory shows
-rw-r--r-- 1 root root 35K Mar 17 11:50 .surepet.cache
-rw-r--r-- 1 alec www-data 4 Mar 17 11:54 .surepet.cache.lock
drwxr-xr-x 8 alec www-data 4,0K Mär 10 10:55 sure_petcare

PS: the e-mail address and the password must be the same as the access data of Surepet.
For me the script worked only after activation of IPv6 on the Fritzbox. Maybe also a source of error?
Test it with: ping6 ipv6.google.com

@chriszuckerberg
Copy link
Author

@staebchen0:
new insights?

@staebchen0
Copy link

Thanks for the hints :-)
I had created the user in the household.

I have packed your sample program into a file and that seems to work.
In the DOS window, however, only the DOS Promt comes back.
But at least there is no warning - Sure Petcare Connect CLI

Why the program no message
print outside or inside is still a mystery to me. I would at least expect an error message if it is not working properly

@staebchen0
Copy link

Ping habe ich ausgeführt und das klappt :-)

@staebchen0
Copy link

The rights are here:
ls -alh in home directory shows
-rw-r--r-- 1 root root 35K Mar 17 11:50 .surepet.cache
-rw-r--r-- 1 alec www-data 4 Mar 17 11:54 .surepet.cache.lock
drwxr-xr-x 8 alec www-data 4,0K Mär 10 10:55 sure_petcare``

da ich kein Linux nutze kann ich den Befehl ja nicht ausführen. Die Dateien habe ich unter Windows nicht gefunden.
(können wir bei Deutsch bleiben?) - ist einfacher ;-)

@staebchen0
Copy link

staebchen0 commented Apr 26, 2019

Hier das Script:

import time
import os
 
# Sure-flap
def SureFlap ():
	while true:
		os.system ("sp_cli.py --update")
		time.sleep (10)
		proc = poles ('sp_cli.py ls_pets', shell = true, stdout = PIPE,)
		output = proc.communicate () [0]
	if (output.find ("Outside")> 0):
		print ("Mila outside.")
		
		for c in ws_clients:
		    c.write_message ("cat_out")
	else:
		print ("Mila inside")
		for c in ws_clients:
			c.write_message ("cat_in")
			time.sleep (10)`

@staebchen0
Copy link

;-) hast du denn noch eine Idee, woran es liegen könnte?

@chriszuckerberg
Copy link
Author

chriszuckerberg commented Apr 26, 2019

;-) hast du denn noch eine Idee, woran es liegen könnte?

Nun ja, das script ist so nicht allein lauffähig, da es eine Funktion def SureFlap (): ist.
Du musst es zum testen so schreiben: https://github.com/chriszuckerberg/mila/blob/master/abfrage.py
Aber sp_cli.py --update bzw. sudo sp_cli.py --update und dann sudo sp-cli.py ls_flaps muss ja erstmal so laufen.

@chriszuckerberg
Copy link
Author

chriszuckerberg commented Apr 27, 2019

-rw-r--r-- 1 root root 35K Mar 17 11:50 .surepet.cache

-rw-r--r-- 1 alec www-data 4 Mar 17 11:54 .surepet.cache.lock
drwxr-xr-x 8 alec www-data 4,0K Mär 10 10:55 sure_petcare``
Die Dateien habe ich unter Windows nicht gefunden.

Nochmal: sp_cli.py --update holt scheinbar die erforderlichen Daten vom SurePet-Server und schreibt sie in die Datei ~/.surepet.cache
Hieraus werden dann wohl die Werte mit zB. sp_cli.py ls_flaps herausgelesen. D.h. wenn du die Datei ~/.surepet.cache nicht hast, kann sp_cli.py mit entsprechendem Kommando nichts finden. M.E. mußt du sicherstellen, das sp_cli.py -e[email] -p[passwort] --update schon mal die ~/.surepet.cache erstellen kann. Die ~/.surepet.cache hat das Attribute "versteckt". Zudem musst du als Email und Passwort dieselben eingeben, wie du zur Anmeldung deiner SurePet-Katzenklappe verwendet hast. Das von mir verwendete Script https://github.com/chriszuckerberg/mila/blob/master/abfrage.py dient mir nur zur Abfrage, ob die Katze draussen oder drinnen ist. Für dich ist es quasi erstmal unrelevant. Du könntest es weiter modifizieren, um später mal die erforderlichen Daten irgendwo anzeigen zu lassen (zB. Batteriespannung, etc.).

@staebchen0
Copy link

Okay, Danke für deine Mühe :-)
Gibt es auch die Möglichkeit die Klappe zu sperren?

Gruß Anja

@chriszuckerberg
Copy link
Author

chriszuckerberg commented Apr 27, 2019

Okay, Danke für deine Mühe :-)
Gibt es auch die Möglichkeit die Klappe zu sperren?
Gruß Anja

Mit diesem GIT denke ich nicht, bin mir aber nicht sicher was über Home-Assistant läuft.
Schau doch mal hier vorbei: https://community.home-assistant.io/t/sureflap-connect-pet-door/41488/39
Grüße Chris

@staebchen0
Copy link

Dank Dir!

@i00
Copy link

i00 commented Jan 23, 2020

Mine fails when calling:

python3 sp_cli.py -e ****@****.*** -p **** --update
Traceback (most recent call last):
  File "sp_cli.py", line 156, in <module>
    main( sys.argv )
  File "sp_cli.py", line 76, in main
    sp.update()
  File "/config/sp/sure_petcare/sure_petcare/__init__.py", line 342, in update
    self.update_pet_status()
  File "/config/sp/sure_petcare/sure_petcare/__init__.py", line 528, in update_pet_status
    response = self._get_data(url)
  File "/config/sp/sure_petcare/sure_petcare/__init__.py", line 560, in _get_data
    'LastData': response.json(),
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.7/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@chriszuckerberg
Copy link
Author

Please try it as root and without a python3 command because it can run itself.

@i00
Copy link

i00 commented Jan 28, 2020

Ok will and let you know, when I get back to Australia.. overseas till Sunday

@i00
Copy link

i00 commented Feb 3, 2020

@chriszuckerberg
Ok without the python3 it worked ... but now how do I read the cache file ...
the file is not intelligible! ... and it's certainly not json as mentioned here:
https://www.home-assistant.io/integrations/surepetcare/

@chriszuckerberg
Copy link
Author

chriszuckerberg commented Feb 3, 2020

You get the data as follows:
Initialize with:
sp_cli.py -e [email protected] -p YourSurepetPassword --update

Data retrieval with:
sp_cli.py ls_house => returns household_id
sp_cli.py ls_flaps => returns flaps-id
sp_cli.py ls_pets => returns pets-id


General instructions:

* First use: sp_cli.py --update -e <email_address> -p <password>

* Subsequently: sp_cli.py --update

After update, you can use any of the following switches to query the status of
your pets, flap or household. Note that --update is mutually exclusive with any
other option (other than --email or --pass).

positional arguments:
cmd One of ls_flaps, ls_house, ls_pets, pet_tl, set_hid

optional arguments:
-h, --help show this help message and exit
-e EMAIL, --email EMAIL
account email address
-p PW, --pass PW account password
--update update cache from Sure servers. Mutually exclusive
with commands/queries.
-c CACHE_FILE, --cache-file CACHE_FILE
Cache file to use if not default

@jimiwester
Copy link

Can anyone tell me how to install this on Rasberry image of Home Assistant?
I understand that there is a linux under it all, but its the "docker" version.
Is this compatible with this HA version?

@rathgar
Copy link

rathgar commented Jun 24, 2020

@jimiwester It's baked in so you just add the integration as you would any other.
Here are the docs for surepetcare integration.

@jimiwester
Copy link

jimiwester commented Jun 24, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests