Local Deployment for SureFlap / SurePetCare Connect using only local MQTT Broker

My manual install isn’t connected to my HA MQTT (as HA requires auth). I’ll have to figure out how to forward messages. But I’d really rather have it all self-contained inside HA.

Wow!

So you have things that are allowed outside, but not out the gate?

Yap. When the farmers work with machines behind the garden we don’t want to have them out. Also we have big issues with idiots walking off-leashed dogs and we don’t want to have them out in the dark (foxes, mertens due to the close forest). So we want to have some control when they are allowed to enter the “big world” … they can go into the screened outdoor area 24/7.

When all looks safe and someone is around (dogs issue), we disable the keepin for the gate flap. 90 mins before sunset the keepin is automatically reactivated (if we don’t do that manually).

1 Like

I hope you have installed a local Mosquitto in your PHL-VM as stated in the setup docs?

In your local PHL-Mosquitto:

default.conf (10.1.1.12 is my HA broker, of yourse you need user “pethublocal” with password “pethublocal” here):

listener 1883 0.0.0.0
protocol mqtt
allow_anonymous true

connection homeassistant
address 10.1.1.12:1883

remote_username pethublocal
remote_password pethublocal

topic pethub/# out 0
topic pethub/# in 0
topic homeassistant/# out 0

tls.conf (the cert files must be in /etc/mosquitto/certs):

#per_listener_settings true
listener 8883 0.0.0.0
allow_anonymous true
protocol mqtt
cafile /etc/mosquitto/certs/AmazonRootCA1.pem
certfile /etc/mosquitto/certs/hub.pem
keyfile /etc/mosquitto/certs/hub.key
#require_certificate true

I hope that helps!

1 Like

Awesome. I’ll try that. Thanks!

This fixed it! Thanks!

However, I’d really love for the HA Addon to work. Anything else we can do to test it @peterl?

If anyone is interested, this is what I came up with to have a button on my Nest Hub to set our cats inside/outside. I couldn’t figure out how to get the timestamp from MQTT, so I created a datetime helper which is used to show how long the cat has been inside/outside. And finally, it notifies my wife when they come and go. :smiley:

1 Like

A quick question
Does the local firmware for the hub also work with the newer Felaqua?
just wondering as i’m looking at getting 2 feeders, a cat door and mabye one or 2 Felaqua’s

You can connect up to 10 devices to the hub. All devices from my experience including the Felaqua works fine on the old and new firmware.

When I turn on the Keepin switch, it seems to turn on, then after a couple seconds delay turn off, then another couple of seconds later, it turns and stays back on.

This is playing havoc with one of my automations. Anyone got any ideas why that’s happening?

Well crap. I rebooted my linux VM hosting pethublocal. It seems the Docker container won’t start and errors out with:

box.exceptions.BoxKeyError: “‘Box’ object has no attribute ‘Update_Mac’”

I was able to resolve this by rerunning the setup. Yay!

But now it seems all my doors are offline

edit: …and everything is back online after I rebooted the hub. Is this likely to happen every time I reboot pethublocal?

Shouldn’t happen. Basically if it fails to load the full json config. I am thinking I really need to refactor the code so it assumes nothing exists.

1 Like

Trying to get this running under a docker container but while in the setup fase I’m facing the following issue:

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): app.api.surehub.io:443
DEBUG:urllib3.connectionpool:https://app.api.surehub.io:443 "POST /api/auth/login HTTP/1.1" 401 69
401 Client Error: Unauthorized for url: https://app.api.surehub.io/api/auth/login <class 'requests.exceptions.HTTPError'>

My network is a Unifi network with an UDM Pro (router) if this info is needed.
Furthermore part of my log below, removed private information:

2022-10-08 11:33:32,095 : [ INFO] : Loading Config file pethubconfig.json
2022-10-08 11:33:32,096 : [ INFO] : Current Deployment Cloud
2022-10-08 11:33:33,483 : [ INFO] : Building from Cloud Configuration, starting DNS check
2022-10-08 11:33:33,483 : [ INFO] : This is *VITAL* as you need to update your internal DNS to point hub.api.surehub.io to this host running PetHubLocal so that the hub connects to this host not the internet
2022-10-08 11:33:33,520 : [ INFO] : External DNS entry for hub.api.surehub.io: 54.81.123.95
2022-10-08 11:33:33,522 : [ INFO] : Internal DNS entry for hub.api.surehub.io: 192.168.20.207
2022-10-08 11:33:37,471 : [ INFO] : Cloud Config: Logging into Surepet to get JWT Bearer Token
2022-10-08 11:33:37,471 : [ INFO] : Cloud Config: Authenticate to retrieve JWT Bearer Token: {"email_address": "", "password": "", "device_id": ""}
2022-10-08 11:33:37,474 : [DEBUG] : Starting new HTTPS connection (1): app.api.surehub.io:443
2022-10-08 11:33:37,996 : [DEBUG] : https://app.api.surehub.io:443 "POST /api/auth/login HTTP/1.1" 401 69
2022-10-08 11:33:43,539 : [ INFO] : Loading Config file pethubconfig.json
2022-10-08 11:33:43,540 : [ INFO] : Current Deployment Cloud

So my server hung up on me, of course while I was travelling. It seems that if pethublocal is offline for too long, the hub just gives up on contacting anything. The only fix then is to reboot the hub.

You should really reword the intro to this post and remove the official integration link. It’s really easy to glance at this and think the thread is regarding that particular repo. You should just title it, like, Cloudless Local SureFlap / SurePetCare Connect integration or whatever. Just makes the whole thing stand out on it’s own for people that might be kinda skimming pages looking to see what is already out there built.

Anyone else’s just randomly stop working? Nothing out of the ordinary as far as I can tell. @peterl any chance you’re still around?

edit: Seems it was this. Thanks @jacotec

Hi! I’m new to Home Assistant and I was very glad to see a replacement for the Sure petcare cloud suite that has caused me so much frustration.

I am in the process of setting up the docker version in Portainer on my unraid server and I have assigned the container a static IP and set up DNS poisoning on my router. I had version 2.201 before and I followed the instructions on how to downgrade, but the hub never stop blinking. It aternate left right green LEDs for 10 sec then alternating red left right for 10 sec and does that over and over again.

Is it safe to restart the hub or the container? Is this standard procedure? In the container terminal I can see the firmware files up to no. 76 has been uploaded.

I just realized that I don’t think there’s a way to set a pet as inside only with this, is there? Holy shit, one of our indoor only cats could have been using this the whole time!

@peterl

No there is no way to set curfews for individual pets with Pethublocal from my understanding.

How can I change the curfew times? If I go to the IP of my PHB instance i get to the server UI but the columns is all empty even though everything works in HA as expected.

Has anyone had this issue when running pethublocal setup? (I have <> some of the personal content.)

What seems to be happening is when I ask the script to download the firmware, it downloads an empty .bin file which obviously doesn’t have the xor key so the 2.43 firmware bin can’t be configured with it, the script then fails. is there something I can do from myside to help this along?

I have managed to get the pethublocal app running and it is passing data to the MQTT but I suspect this is from the .config file and not from the hub.

By the way Peter, Fantastic work and cant wait to use it

  • C

INFO:pethublocal:Loading Config file pethubconfig.json
INFO:pethublocal:Current Deployment Cloud
Use exist SurePetCare Cloud (C) or build empty Local config (L) C/L ? C
INFO:pethublocal:Building from Cloud Configuration, starting DNS check
INFO:pethublocal:This is VITAL as you need to update your internal DNS to point hub.api.surehub.io to this host running PetHubLocal so that the hub connects to this host not the internet
INFO:pethublocal:External DNS entry for hub.api.surehub.io: 54.87.205.181
INFO:pethublocal:Internal DNS entry for hub.api.surehub.io: x.x.x.x <>
Is the Internal DNS updated to point to this host Y/N?
Y

Start File start-20230110-025407.json download new start Y/N? Y
INFO:pethublocal:Check Token Expiry JWT {‘iss’: ‘https://app.api.surehub.io/api/auth/login’, …’} <>
INFO:pethublocal:JWT Token Expiry 2024-01-07 12:59:53
INFO:pethublocal:Cloud Config: Using JWT Bearer Token to download configuration
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): app.api.surehub.io:443
DEBUG:urllib3.connectionpool:https://app.api.surehub.io:443 “GET /api/me/start HTTP/1.1” 200 1605
INFO:pethublocal:{‘devices’:…}}} <>
INFO:pethublocal:Cloud Config: Download successful response: <Response [200]>
DEBUG:pethublocal:Adding Pet <>
DEBUG:pethublocal:Adding Pet <>
INFO:pethublocal:Start parsed and saved to config
Download Credentials and Firmware for Hub (highly recommended)? Y/N Y
INFO:pethublocal:Current Hub Firmware 233.364
INFO:pethublocal:Downloading Current Firmware for H010-064xxxx
INFO:pethublocal:SureHub Host hub.api.surehub.io IP Address: 44.198.20.107
INFO:pethublocal:Firmware already downloaded H010-0646816-1.177-00.bin
INFO:pethublocal:Your device has been upgraded to version 233.364 and since it isn’t running 2.43 this version the Hub now checks the server certificate is legitimate before connecting (boo! :frowning: ) so you will need to downgrade the hub to 2.43 which for the moment is easy as holding the reset button underneath the hub when the DNS is poisoned to point to PetHubLocal (Yay!)
Traceback (most recent call last):
File “/home/pi/.local/bin/pethublocal”, line 8, in
sys.exit(cli())
File “/home/pi/.local/lib/python3.7/site-packages/click/core.py”, line 1130, in call
return self.main(*args, **kwargs)
File “/home/pi/.local/lib/python3.7/site-packages/click/core.py”, line 1055, in main
rv = self.invoke(ctx)
File “/home/pi/.local/lib/python3.7/site-packages/click/core.py”, line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/pi/.local/lib/python3.7/site-packages/click/core.py”, line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/pi/.local/lib/python3.7/site-packages/click/core.py”, line 760, in invoke
return __callback(*args, **kwargs)
File “/home/pi/.local/lib/python3.7/site-packages/click/decorators.py”, line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/pi/.local/lib/python3.7/site-packages/pethublocal/cli/init.py”, line 72, in setup
pethubconfig = config_load(True, force)
File “/home/pi/.local/lib/python3.7/site-packages/pethublocal/functions.py”, line 385, in config_load
xor_key, long_serial = find_firmware_xor_key(serial_number, BOOTLOADER)
File “/home/pi/.local/lib/python3.7/site-packages/pethublocal/functions.py”, line 1200, in find_firmware_xor_key
record_count = int(header[2], 16)
IndexError: list index out of range