Sureflap Connect - Pet Door

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: [email protected]
  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.

OK so I figured this out myself, based on various comments in the thread but above all, a lot of trial and error investigation. The net of it is that the snippet of config setup originally given by janmatias, does not work as presented (maybe it did at some time and evolving development broke it - whatever).

Anyway, through trial and error I discovered that the only things needed to make this integration work are
username : [email protected]
password: xxxxxxxx
flaps: [xxxxx , xxxxx, ...]
pets: [yyyy, yyyy]

For flaps and pets, ONLY the ids are acceptable. All of the braces ( {} ) , and name fields, are not acceptable.

In trying to get things working in HA, I’ve noticed a lot of cases where advice and code/config snippets and the like are obsolete. It’s a pity there is not a reliable system to purge - or at least identify as obsolete - older posts.

Now to try and get the custom-card-linky or linky-card Lovelace card operational for this. Another “bête noire” I’ve been beating my head up against for days now. Can’t seem to get HA to recognize that these cards even exist on the system…

I’m totally new to this and still can’t get to work…

Which are the exact files I need to put into custom_componants and where can I find them please?

Thanks in advance. Getting the glass cut for the flap tomorrow and want to get this going

Hi,
I’m not exactly the best guy to ask for the procedure, noob that I am. I stumbled around a lot before I got the sensors working (and didn’t take notes! :hot_face:. I’d be afraid to send you down a wrong path. I will go back and look at my integration and see if I can remember how I finally ended up getting it up and running.

I’m struggling with the custom card issue at the moment so this may take a bit of time.

Cheers.

Getting closer

In the log there are a bunch of errors. Not sure where I am going wrong:

Logger: homeassistant
Source: custom_components/surepetcare/sensor.py:125
First occurred: 1:33:42 (72 occurrences)
Last logged: 13:23:42

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 283, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 320, in _async_write_ha_state
    sstate = self.state
  File "/config/custom_components/surepetcare/sensor.py", line 125, in state
    return SureLockStateID(self._state["locking"]["mode"]).name.capitalize()
KeyError: 'locking'
Logger: homeassistant
Source: custom_components/surepetcare/sensor.py:173
First occurred: 1:33:42 (72 occurrences)
Last logged: 13:23:42

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 283, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 323, in _async_write_ha_state
    attr.update(self.device_state_attributes or {})
  File "/config/custom_components/surepetcare/sensor.py", line 173, in device_state_attributes
    voltage_per_battery = float(self._state["battery"]) / 4
KeyError: 'battery'
Logger: homeassistant
Source: custom_components/surepetcare/binary_sensor.py:240
First occurred: 1:33:42 (72 occurrences)
Last logged: 13:23:42

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 283, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 323, in _async_write_ha_state
    attr.update(self.device_state_attributes or {})
  File "/config/custom_components/surepetcare/binary_sensor.py", line 240, in device_state_attributes
    "device_rssi": f'{self._state["signal"]["device_rssi"]:.2f}',
KeyError: 'signal'

Any help would be much appreciated.

I am running Hass.io on a NAS

Thanks for this post. Helped me out man :+1:

1 Like

This is why whenever I find out a solution, it’s always posted back in the thread to help others in the future :slight_smile: