Home Assistant integration for OnlyCat catflap

I just ordered a a onlycat catflap as an replacement for our sure petcare catflap (the hub stopped working several times, never liked the “must be online” idea and now the integration does not work).

I’ll am going to start work on a HA integration. I do have small kids, work and so of course, so it’ll be when ever I have time.

3 Likes

Hoi zäme!

I just started using Home Assistant (via a HA Yellow with a Raspberry Pi Compute Module). Previously, I was a Philips Hue user and separately also had a SureFlap cat flap. I now have an OnlyCat flap and am interested in HA integration.

All of this is to say, I’d be happy to contribute if I could be useful. Nice to meet everyone—this is my first post. :stars:

1 Like

Great to see a community building. Would love to help with this.
Looking at the existing files it appears not all files exist?

import OCPlatform from “./OCPlatform”;
import { User } from “…/models/User”;

1 Like

@OnlyCat can you help answer @Iano_D’s question about the missing files?

The OCPlatform file we use is tied to our app’s data storage, so we didn’t include it as part of the standalone example - however you only need a stub version which includes a getDeviceToken method that returns a string device token, which you can get from the app’s Account tab.

class OCPlatform {
    async getDeviceToken() {
            return '[INSERT TOKEN HERE]';
    }

    getPlatforms() {
        return ['home-assistant'];
    }
}

export default new OCPlatform();

(This mechanism will improve over time with proper developer API keys - but the above approach should get you started).

As for models/User.tsx, this will work:

export interface User {
    id: number;
    sub: string | null;
    email: string | null;
    name: string | null;
    description: string | null;
    avatarUrl: string | null;
    userLevel?: 'ADMIN' | null;
}
3 Likes

First of all, thank you for the flap in general, it works like a charm! And also thank you for having a local API on the roadmap, this will be of massive use for me.

For now I finally found some time to look into this and read into HA (HACS) integrations.
Its quite the steep learning curve on how to bootstrap a cloud-push HA integration. I used the blueprint repository from here: integration_blueprint/custom_components/integration_blueprint at main · ludeeus/integration_blueprint · GitHub
With this it is really easy to test in a debug HA instance by just running the scripts/develop script.

So far I’ve just managed to write crude code so that an “OnlyCat” integration can be added to HA using the device token from within the app.
This adds the integration and already connects successfully to the OnlyCat gateway, receiving the userinfo.

Next steps would be to discover devices and properly add them to HA, but so far I didn’t manage to get the API respond to my emitted events like “getDevices” and “getDevice”.

The code is by far not yet ready to be worth a PR, I think. GitHub - Alex-ala/onlycat-home-assistant

3 Likes

First of all, thank you very much @Alex-ala for kicking off this project! :clap:

Regarding the PR, feel free to send it whenever you want, even if the integration is not working yet. At the moment the repo is empty, so any addition we add will be more than welcome.

I’ll try to get it to a very basic state within the next days to open a PR.
Currently I added code to run the communication through a mitmproxy to debug.
But I managed to get commands to work.

I will attach a sanitized mitmproxy flow to the PR to give some examples on the response structure.

1 Like

You said it yourself: “just to give you an idea of their level of commitment, they have agreed to send me a catflap for free with the only condition that I help build the integration with Home Assistant.”

If only the rest of us could get paid in expensive hardware just for posting on forums.

3 Likes

Since my sure Catflap integration seems to have stopped working, I consider bying the OnlyFlap, as soon as the integration is available. How it it developing?
Also noticed there is not much transparancy about the price, except the subscription models. As we have seen with Sure Petcard, it is not a good idea to rely on cloud solutions…

As for the integration, the only feature currently is to show and set the active schedule (that has to be set up via app). But at least this allows automating switching door policies.

Offline support is not yet developed by OnlyCat, same with presence detection (showing if a cat is inside or outside).
Presence detection is “on their roadmap” for when they are done “optimizing the event sequencing”. Got that from their support back in March.

1 Like

Fresh OnlyCat owner here with a big HomeAssistant installation. I would love to see the OnlyCat as an official integration so that I can install it from within HomeAssistant without having to edit files.
I had a Sure PetFlap before and that worked beautifully in HA. I am limited in time but if I can help I can see what I can do.

I honestly don’t know the requirements and process on how to apply for an official bundled HA integration.

With HACS there is no need in editing files manually: https://www.hacs.xyz/
Initial installation may require manual steps depending on your deployment type.
From there, its setup including custom integrations and updates are via UI.

This integration already has a good basic functionality: GitHub - OnlyCatAI/onlycat-home-assistant

1 Like

The requirements to get included as a core integration are outlined in the documentation: Development checklist

As @Alex-ala mentioned, the current functionality is already pretty good, we had some substantial progress in the last couple of weeks. I think we’re currently on a good way to get it included as default repository in HACS soon, at which point you wouldn’t need to manually add the Git repo to HACS anymore, just installing HACS would allow you to install the OnlyCat integration. But looking at the overall development checklist linked above, I think there’s still some way to go until we could apply to become a HASS core integration. There’s still a lot of documentation and tests missing, and most importantly, we would have to extract the entire communication with the OnlyCat API into a separate PyPI package.

But as mentioned, I think installing HACS should be easy enough for interested users. Would be great to get some feedback from other users about what they’d want to see from the integration!

1 Like

Just got my OnlyCat Flap yesterday and installed the integration right away. Works great. Thank you!

1 Like

Hi @markusdlugi and @Alex-ala

I’m in the process of moving over from SurePet to OnlyCat with some hardware in the mail even as I write this. I’m really keen to jump in as soon and get involved however possible on the development side of things. I have a career background as a software developer and a strong passion of open source software. Not wanting to step on any toes, but passionate about helping out where possible, especially given how much support OnlyCat has shown the Home Assistant Community.

To that end, is there anything in particular you see as being something you could do with an extra set of hands on? Otherwise some things that came to mind were:

  1. Cracking into some of the “Limitations” currently shown in the README on the repo. They appear to mostly be around the creation and modification of door profiles. Question here - Do these limitations exist due to lack of developer time or due to limitations in what we have access to from the OnlyCat API?
  2. Looking into Local API, however I know that’s at something of a stand-still pending Local API development on the OnlyCat side.
  3. Writing of documentation and tests as mentioned in your comment above @markusdlugi? You indicate these would go a long way towards improving candidacy for HASS integration. I’m happy to jump onto those.
  4. Decoupling of the OnlyCat API client code from the rest of the codebase. Also mentioned in the above message that seems to be something on the TODOs. I can also see it being helpful when LocalAPI support gets added in.
  5. Tech debt, if any. Point me at it and I’ll do what I can :slight_smile:

Let me know if there’s anything in particular from the list above that jumps out at either of you, otherwise I’ll just pick something and raise a PR when possible.

Thanks again to both of you for the incredible work you’ve been doing thus far. It’s jaw dropping how far this integration has come in this span of time thanks to your efforts.

-W

1 Like

Hey @WMTaylor3 thanks for helping out!
For the limitations listed in the Readme, these are not blocked by OnlyCat per-se. In theory we shoud be able to do what the app is able to do. I currently don’t have all the websocket commands at hand, maybe some are already in there (like the image/video of an event), maybe some might have to be found via a mitm proxy or reaching out to OnlyCat.

Local api is a topic that is blocked until OnlyCat develops that functionality into the device firmware. I’ve not heard (nor asked for) an update on this topic.

Personally I prefer a HACS integration over a HASS builtin due to these restrictions and the process of getting it updated. Its easier to run custom versions or develop faster via HACS. But if having the integration added to the offcial HomeAssistant components is what we should go for, there’s a bit work to do. Tests in general might help (I’ve run into the first issues with not testing it and causing side-effects). We’re at the very start of this and speaking for myself, I have little experience in how tests are usually built in this kind of project.

Firstly, great work with the integration so far. I’m considering one of these devices to replace a now-broken SureFlap.

A local API really is the killer feature here. Being able to continue to use it if the company goes bust, changes their subscription pricing/model, starts removing features, etc. is essential for a premium product like this, especially from a start-up.

It’s fantastic that they’ve said they want to create one but the proof is in the pudding. Someone in the company might realise there’s very little money in it and decide not to bother.

Thanks for the quick response @Alex-ala. Sorry my own took so long. Busy work week.

In that case I think I’ll get started on the list of current “limitations” in the GitHub repo. Might try my hand at creation and modification of door profiles.

Cheers :slight_smile:

API for managing device transit policies seems pretty easy to use (payload-wise). I think the complexity here will be around surfacing it in the Home Assistant UI using native controls.

As anyone who has made a policy in the app knows, it’s super customizable, allowing both in and out modes of any policy to be either locked, unlocked, microchip specific etc.

Feels like this is beyond the ability of the switches and option selects that one gets within the home assistant “Device” window.

Anyone have any brainwaves on how this could present to the user? My immediate thoughts would be some kinda super basic web form, much as how some Add-ons do. Could more or less mimic the UI presented in the OnlyCat app. Feels a bit heavy though.

Hoping to discuss alternative ideas, if any :slight_smile:

Edit: another, perhaps better, thought…

Taking inspiration from the Shelly Integration (screenshotted below) where a single hardware “Device” has multiple “SubDevices”. Perhaps policies could each be their own “SubDevice” under the Cat-flap Device?

Then for each of the SubDevices (policies) there could be a selector for “Entry Mode” and a selector for “Exit Mode”.

Options in each selector being “Full Lock”, “Full Unlock”, and “Microchip specific”.

Then each microchip the device knows about with be listed as a toggle. Toggled on would allow transit for that microchip when the selector is set to “Microchip Specific”.

There are a few issues here though, such as “I’m not sure how that would scale to multiple cat flaps in one house” I’m also not sure how creation of brand new policies would work in this layout.

Again, I’m not a UX designer, so happy to brainstorm and workshop.