Sureflap Connect - Pet Door

Holy crap! Many thanks to @benleb and @insertjokehere.

setting pet location is implemented :slight_smile:

1 Like

and also a refresh function for a pets data :v: both should be considered at least “beta” :smiley:

1 Like

@insertjokehere Would you be able to perform some of your wizardry? :smiley:

Yep, I should have a few hours to look at this over the weekend :slight_smile:

@benleb started looking at this, beginning with updating the integration code to work with the current SurePy master branch, and I’m getting an error calling .devices():

Traceback (most recent call last):
  File "/home/william/Programming/home-assistant-core/venv/bin/surepy", line 11, in <module>
    load_entry_point('surepy', 'console_scripts', 'surepy')()
  File "/home/william/Programming/home-assistant-core/venv/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/william/Programming/home-assistant-core/venv/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/william/Programming/home-assistant-core/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/william/Programming/home-assistant-core/venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/william/Programming/home-assistant-core/venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/william/Programming/home-assistant-core/venv/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/william/Programming/surepy/surepy/cli.py", line 41, in wrapper
    return asyncio.run(f(*args, **kwargs))
  File "/usr/lib/python3.8/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/william/Programming/surepy/surepy/cli.py", line 224, in devices
    devices = await sp.devices
  File "/home/william/Programming/surepy/surepy/__init__.py", line 183, in devices
    return await self.get_entities("devices")
  File "/home/william/Programming/surepy/surepy/__init__.py", line 284, in get_entities
    flaps.update(sure_entities[EntityType.PET_FLAP])
KeyError: <EntityType.PET_FLAP: 3>

I’m calling it from the SurePy CLI above, but I get a similar error calling it from the integration. Any ideas?

My current goal is to get things working locally with surepy master - hopefully fix the update_entity issue for Pet binary sensors, then take a look at the new service

oooopsie, working on a fix :v:

should be fixed (in master), thanks!

Hey!
getting this error, is that what is fixed in the next update?

Logger: homeassistant.setup
Source: components/surepetcare/init.py:111
First occurred: 20 January 2021, 10:58:50 (1 occurrences)
Last logged: 20 January 2021, 10:58:50

Error during setup of component surepetcare
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/setup.py”, line 213, in _async_setup_component
result = await task
File “/usr/src/homeassistant/homeassistant/components/surepetcare/init.py”, line 111, in async_setup
CONF_PARENT in device_data
TypeError: argument of type ‘NoneType’ is not iterable


surepetcare:
  username: !secret surepetcareemail
  password: !secret surepetcarepw
  feeders: [!secret superpetcarefeederidmitzi, !secret superpetcarefeederidthor, !secret superpetcarefeederidcleo]
  flaps: [!secret superpetcareflapid]
  pets: [!secret superpetcaremitziid, !secret superpetcarethorid, !secret superpetcarecleo

This is great! I have 4 feeders and a catflap, and have successfully added them all into HA. I am able to see when they are in, or out, how long for, and find the battery information.

Here is my lovelace card - I have one for each of my 4 cats!:
image

I notice above that you were looking at adding in the information for the feeders - when they ate, how much, when it was filled etc. But I have not seen anymore regarding this. Is this something that is being worked on?

+1 for feeding info too :slight_smile:

1 Like

Fairly far down the path of building a local instance to have a completely local surepet backend removing the use of their cloud api and app and running everything locally.
Started a new topic in development for those interested in helping with the effort to build a local component.
https://community.home-assistant.io/t/surepet-hub-local-for-pet-cat-door-and-feeder/274494

2 Likes

means you spoof the dns hostname of the api (which is accepted by the hub and ios/android apps!?) and mimic it yourself? nice job :+1:

1 Like

Yes, there are two DNS records you need to spoof. The hub api one and the aws iot mqtt endpoint. That is the main wrinkle is folks will need a semi decent router at home or something they can spoof local dns entries to make it work.

Also none of the control commands have been figured out as the aws iot mqtt endpoint requires a client certificate which can’t yet be easily spoofed but we are planning to snoop the zigbee style Miwi traffic and hopefully send similar style messages to the topic and see what works.

I have sorted out most messages and just now need to figure out how to build a component but for the moment am looking to document the messages with as much detail as possible.

1 Like

Hello! A minor FYI - if you’re running commands via the surepy CLI for 0.4.0 and getting errors on ‘report’ and ‘locking’, your catflap may have disconnected itself from the hub. Simply pressing the ‘cog’ button on the catflap should reconnect it.
The error for locking is as follows:

bash-5.0# surepy locking --device nnnnnn --mode lock

 surepy 🐾 v0.4.0

⠦ setting to 'locked'Can not load data from https://app.api.surehub.io/api/device/nnnnnn/control
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 365, in _put_resource
    response: aiohttp.ClientResponse = await self._session.put(resource, headers=headers, data=data)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 544, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client_reqrep.py", line 890, in start
    message, payload = await self._protocol.read()  # type: ignore
  File "/usr/local/lib/python3.8/site-packages/aiohttp/streams.py", line 604, in read
    await self._waiter
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 367, in _put_resource
    logger.debug("response.status: %d", response.status)
  File "/usr/local/lib/python3.8/site-packages/async_timeout/__init__.py", line 45, in __exit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.8/site-packages/async_timeout/__init__.py", line 92, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/surepy", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/surepy/cli.py", line 39, in wrapper
    return asyncio.run(f(*args, **kwargs))
  File "/usr/local/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.8/site-packages/surepy/cli.py", line 353, in locking
    if await lock_control(device_id=device_id) and (device := await sp.device(device_id=device_id)):
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 315, in lock
    return await self._locking(device_id, SureLockStateID.LOCKED_ALL)
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 334, in _locking
    if response := await self._put_resource(resource=resource, device_id=device_id, data=data):
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 399, in _put_resource
    raise SurePetcareConnectionError()
surepy.SurePetcareConnectionError
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0xb60e8f88>
bash-5.0#

It is also worth noting that the if a feeder is disconnected, it will not cause the same error when running ‘report’; the script completes successfully. This information might be useful to someone I guess. :wink:

@benleb, appreciate the work you’re doing on this! Is there any news of being able to set the cat-flap to curfew mode via the CLI - if that’s something you’re considering doing? Also, if one wanted to, how could we make a charitable donation? :slight_smile:

Hi, just discovered this integration, had been following the rcastberg thread but being a HA noob at the time did not really understand how to do the integration. I have one flap and three cats.

Time has passed, I’ve increased my skill on HA and now would like to get this up and running. Tried the steps you put above, and all goes well until I check the configuration.yaml after adding your snippet (and customizing it with my data). I get the following error when checking the config:

Invalid config for [surepetcare]: [household_id] is an invalid option for [surepetcare]. Check: surepetcare->surepetcare->household_id. (See /config/configuration.yaml, line 51).

I have been over and over my changes to the yaml file and see nothing wrong. here it is (masked my personal info, as I have not yet implemented secrets file, my HA is currently just a sandbox).

surepetcare:
username: [email protected]
password: xxxxxxxx
household_id: xxxxxx
flaps: [{id: 668645, name: Chatiere}]
pets: [{id: 139992, name: Sofa}, {id: 141236, name: Zorro},{id:141396, name: Mimine}]`

Pretty frustrating. Any ideas?

Hi all,

Trying to get this integrated and copied all the files for the custom component but getting this error:

Logger: homeassistant.setup
Source: setup.py:138
First occurred: 20:17:39 (1 occurrences)
Last logged: 20:17:39

Setup failed for surepetcare: No setup function defined.

Any help would be much appreciated. I’m pretty new to HA.
Thanks

Should look like this:

surepetcare:
  username: flyize@xxxxxx
  password: xxx
  flaps: [429xxx]
  pets: [172xxx, 172xxx, 175xxx, 182xxx, 182xxx]

Thanks I’ve got that in my config. I’ve got it as !secret. Could that be effecting it?

surepetcare:
  username: !secret surepetcare_username
  password: !secret surepetcare_password
  flaps: [436xxx]
  pets: [187xxx]  

Thanks for your reply. I must be missing something. That is what mine looks like. However you totally left out the household_id field, which appears to be the item that is giving me trouble. Here’s mine again:

surepetcare: username: [email protected] password: xxxxxxxxxx household_id: xxxxxxx flaps: [{id: 668645, name: Chatiere}] pets: [{id: 139992, name: Sofa}, {id: 141236, name: Zorro}, {id:141396, name: Mimine}]`

EDIT: I realize the format above is not consistent. I’m having trouble with the reply function’s code checker, and it runs it all together. Each line is indeed separated and indented. Like so:
surepetcare:
username: [email protected]
password: xxxxxxxxxx
household_id: xxxxxxx
flaps: [{id: 668645, name: Chatiere}]
pets: [{id: 139992, name: Sofa}, {id: 141236, name: Zorro}, {id:141396, name: Mimine}]`

What > specific < field above is not the way it should be, please? I took this right out of the instructions given above.

Thanks.