Sureflap Connect - Pet Door

Fantastic work! Appreciate the implementation of this one, hope to see it in a upcoming release :slight_smile:

Really looking forward to this!

most important sensors implemented :+1:

1 Like

This is such an excellent project. Thank you for your time.

Sure Petcare have a feeder, that discriminates between pets and logs the amount eaten, due for release shortly.

Do you expect to support that too?

Can you sponsor me and my cat such a feeder (you talk about the unreleased „Feeder Connect“ right?) for development? :grin: :sweat_smile:

Hi Guys, For those of you who are running Hass.io, this is the way I got it working.
I’m currently on Version 0.89.2.
Please follow the instructions carefully!

  1. Create a folder called “sure_petflap” within “config\custom_components\
  2. Navigate to “config\custom_components\sure_petflap
  3. Copy and paste the following file: “sure_petflap.py” from the repo to location: “config\custom_components\sure_petflap”. You find the file in the following location of this repo “sure_petcare/home_assistant
  4. Rename the file from: “sure_petflap.py” to: “sensor.py
  5. Copy and paste the following files: “__init__.py” and " “utils.py” from the repo to location: “config\custom_components\sure_petflap”. You find the files in the following location of this repo “sure_petcare/sure_petcare”.
  6. Make the following changes in file “sensor.py”. (The file you renamed in step 4).
    Replace line 5-43 with the following below (If you get any errors. Please copy the code from here to notepad and then from notepad to “sensor.py”):
#def is_hass_component():
#    try:
#        import homeasssistant
#        return True
#    except ImportError:
#        return False

#if is_hass_component():
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD)
import homeassistant.helpers.config_validation as cv

from . import SurePetFlap
from .utils import gen_device_id

import voluptuous as vol

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_USERNAME): cv.string,
    vol.Required(CONF_PASSWORD): cv.string,
})
#else:
    # Assume not running within home assistant.  This *does* mean that you
    # won't be able to run this test script if you have homeassistant
    # installed but, if you do, you're probably running (or can run) this
    # component from within hass anyway.
#    from sure_petcare import SurePetFlap
#    from sure_petcare.utils import gen_device_id

    # dummy dependencies
#    class Entity( object ):
#        pass

#    def Throttle( *args, **kwargs ):
#        def decorator( f ):
#            return f
#        return decorator
  1. Make the following changes in file “__init__.py”.
    Replace line 11-12 with the following below (If you get any errors. Please copy the code from here to notepad and then from notepad to “__init__.py”):

import utils as utils
from .utils import mk_enum

  1. Now your file structure should look like this:
    - custom_components
    | - sure_petflap
    | - | - sensor.py
    | - | - utils.py
    | - | - __init__.py
    And you have made changes to: “sensor.py” & “__init__.py

  2. Now it’s time to setup the platform sensor. Please do not set up any other configurations as for now such as template sensors, groups, binary_sensors etc.
    Set up the following in one of your .yaml files:

sensor:
  - platform: sure_petflap
    username: [email protected]
    password: xxxxxxxxxxx
  1. Restart your hassio. Either from the web or with ssh: hassio homeassistant restart

  2. Navigate to dev-state in your Home Assistant to find the entity. Look for: sensor.surepet_connect

Best of luck!
//Asif

6 Likes

Great write up. Thank you for taking the time.

So, does this only apply to Rpi? I run HA on a mac mini. What will the differences be?

Hi,
It shouldn’t be any difference. As long as you are running Hass.io these instructions should work.
//Asif

Maybe it’s me or maybe 0.90.1 changed something in the custom components but I can’t get it to work :frowning:

First of all, I had to add these lines before the new lines in __init__.py:

import sys
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) )

Just so it would look for utils.py in the ~/.homeassistant/custom_components/sure_petflap/ directory

But that still doesn’t make the component work. I bugs out with the following error:

AttributeError: module 'custom_components.sensor.sure_petflap' has no attribute 'setup_platform'

Anyone any thoughts? (I cloned the repo today: March 24, 2019)

I can confirm that I my guide works with Hass.io version: 0.90.1 Running on RPI.
hmm, have you configured any template sensors etc?
Start with just setting up the surepet platform. Are you still getting that error?

1 Like

Nope, no template sensore, binairy sensors, groups or anything.
Just:

- platform: sure_petflap
username: [email protected]
password: ******

I will retry all the steps from start and see if I made a mistake somewhere

Nope, redone the whole install according to the steps by @asif

The complete error from home-assistant.log:

2019-03-24 21:49:41 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform sure_petflap
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py”, line 124, in _async_setup_platform
task = async_create_setup_task()
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py”, line 89, in async_create_setup_task
None, platform.setup_platform, hass, platform_config,
AttributeError: module ‘custom_components.sensor.sure_petflap’ has no attribute ‘setup_platform’

I tried manually running sp_cli.py which gave no issues at all

Could you upload all your files within the config\custom_components\sure_petflap folder?

Found my booboo… In my environment (virtualenv) custom_components is not located under config but directly under ~/.homeassistant and I had the directory sure_petflap located under custom_components/sensors in stead of under custom_components

Fixed my mistakes and now I have my Sure Catflap connected to HASS :smiley:

1 Like

Thank you! It works perfekt!

1 Like

Härligt :)!!

Thanks for the write up, finally go this up and running in hassio. Can you give me some pointers as how to create a Lovelace card for individual items please or to see the list of items. ATM I can only see the list in devtools/States

1 Like

The feeder arrives today!

I’ll let you know how it performs.

1 Like

This is my config to setup the entities:

sensor:
  - platform: sure_petflap
    username: [email protected]
    password: xxxxx
    
  - platform: template
    sensors:
      jenna_status:
        friendly_name: "Jenna Status"
        value_template: "{{ state_attr('sensor.surepet_connect', 'Jenna') }}"
      flap_battery_status:
        friendly_name: "Sure Flap Battery"
        value_template: "{{ state_attr('sensor.surepet_connect', 'battery') }}"
        unit_of_measurement: '%'
      flap_batterystatus:
        friendly_name: Sure Flap Battery
        value_template: >
          {% if is_state('sensor.surepet_connect', 'unknown') %}
            110
          {% else %}
            {{ states.sensor.surepet_connect.attributes["battery"] | float}}
          {% endif %}
        icon_template: > 
          {% set battery_level_xod1 = states.sensor.surepet_connect.attributes.battery|default(0)|int %}
          {% set battery_round_xod1 = (battery_level_xod1 / 10) |int * 10 %}
          {% if battery_round_xod1 >= 100 or is_state('sensor.surepet_connect', 'unknown') %}
            mdi:battery
          {% elif battery_round_xod1 > 0 %}
            mdi:battery-{{ battery_round_xod1 }}
          {% else %}
            mdi:battery-charging-wireless-outline
          {% endif %}
        unit_of_measurement: '%'

  - platform: history_stats
    name: Jenna outside time (today)
    entity_id: sensor.Jenna_status
    state: 'Outside'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'
  - platform: history_stats
    name: Jenna trips outside (today)
    entity_id: sensor.Jenna_status
    state: 'Outside'
    type: count
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'
  - platform: history_stats
    name: Jenna outside (yesterday)
    entity_id: sensor.Jenna_status
    state: 'Outside'
    type: time
    end : '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    duration:
      hours: 24
  - platform: history_stats
    name: Jenna trips outside (yesterday)
    entity_id: sensor.Jenna_status
    state: 'Outside'
    type: count
    end : '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    duration:
      hours: 24

binary_sensor:
  - platform: template
    sensors:
      lock_status:
        friendly_name: "Sure Flap"
        device_class: lock
        value_template: "{{ not states.sensor.surepet_connect.attributes.locked}}"
        icon_template : >
          {% if states.sensor.surepet_connect.attributes.locked %}
            mdi:lock
          {% else %}
            mdi:lock-open
          {% endif %}
      flap_status:
        friendly_name: "Flap online Status"
        device_class: connectivity
        value_template: "{{ states.sensor.surepet_connect.attributes.flap_online }}"
        icon_template : >
          {% if states.sensor.surepet_connect.attributes.flap_online %}
            mdi:wifi
          {% else %}
            mdi:wifi-off
          {% endif %}
      hub_status:
        friendly_name: "Hub online Status"
        device_class: connectivity
        value_template: "{{ states.sensor.surepet_connect.attributes.hub_online }}"
        icon_template : >
          {% if states.sensor.surepet_connect.attributes.hub_online %}
            mdi:wifi
          {% else %}
            mdi:wifi-off
          {% endif %}

And this is my Lovelace GUI:

8 Likes

Thank you Asif, I shell work my way through this as Im quite new to HA but learning fast, this helps a lot.