Sureflap Connect - Pet Door

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.

Riktigt snyggt @asif. Har du lust att dela med dig av koden för lovelace-kortet?

Sure/Absolut :slight_smile:

These are the custom js and modules I’m using. Please google on how to add custom js and modules to your ui-lovelace.yaml

- type: js
  url: /customcards/lovelace/card-modder.js

- type: module
  url: /customcards/lovelace/circle-sensor-card.js

And here is the Code:

  - type: vertical-stack
    cards:
      - type: custom:card-modder
        style:
          border-radius: 20px
          border: solid 1px rgba(100,100,100,0.3)
          box-shadow: 3px 3px rgba(0,0,0,0.4)
          overflow: hidden
          animation: '[[ sensor.flap_batterystatus.state ]] 2s linear infinite'
          # animation: [[ if(sensor.washer_animation == 'Clean', "blink 2s linear infinite", "none") ]]
        extra_styles: >
          @keyframes 0.0 {
            
            50% {
              outline: 3px solid #389638;
            }
          }
        card:
          type: picture-elements
          image: /local/images/jenna_inside.jpg
          elements:
            - type: image
              entity: sensor.jenna_status
              style:
                top: 50%
                left: 50%
                width: 100%
              state_image:
                "Inside": /local/images/jenna_inside.jpg
                "Outside": /local/images/jenna_outside.jpg
            - type: image
              entity: sensor.jenna_status
              image: /local/images/cat.svg?v1
              state_filter: 
                "Inside": invert(.5) sepia(1) saturate(8) hue-rotate(10deg)
                "Outside": invert(.90)
              tap_action: more-info
              style: {color: white, left: 10%, top: 88%}
            - type: state-label
              entity: sensor.jenna_status
              style: {color: white, left: 10%, top: 95%}
            - type: state-icon
              entity: binary_sensor.lock_status
              tap_action: more-info
              style: {color: white, left: 25%, top: 88%}
            - type: state-label
              entity: binary_sensor.lock_status
              style: {color: white, left: 25%, top: 95%}
            - type: state-icon
              entity: sensor.flap_batterystatus
              tap_action: more-info
              style: {--paper-item-icon-color: green, color: white, left: 40%, top: 88%}
            - type: state-label
              entity: sensor.flap_batterystatus
              style: {color: white, left: 40%, top: 95%}
            - type: state-icon
              entity: binary_sensor.hub_status
              tap_action: more-info
              style: {color: white, left: 70%, top: 88%}
            - type: state-label
              entity: binary_sensor.hub_status
              style: {color: white, left: 70%, top: 95%}
            - type: state-icon
              entity: binary_sensor.flap_status
              tap_action: more-info
              style: {color: white, left: 90%, top: 88%}
            - type: state-label
              entity: binary_sensor.flap_status
              style: {color: white, left: 90%, top: 95%}

      - type: horizontal-stack
        cards:
          - type: custom:circle-sensor-card
            entity: sensor.jenna_outside_time_today
            show_card: true
            name: Jenna outside (today)
            max: 24
            min: 0
            stroke_width: 7
            gradient: true
            units: 'H'
            font_style:
              color: white
              font-size: 1em
            fill: rgba(54, 128, 173, 0.23)
            color_stops:
              3: '#55FF55'
              10: '#5555FF'
              15: '#FF5555'
            style:
              top: 50%
              left: 50%
              width: 50px
              height: 50px
          - type: custom:circle-sensor-card
            entity: sensor.jenna_outside_yesterday
            show_card: true
            name: Jenna outside (yesterday)
            max: 24
            min: 0
            stroke_width: 7
            gradient: true
            units: 'H'
            font_style:
              color: white
              font-size: 1em
            fill: rgba(54, 128, 173, 0.23)
            color_stops:
              3: '#55FF55'
              10: '#5555FF'
              15: '#FF5555'
            style:
              top: 50%
              left: 50%
              width: 50px
              height: 50px

      - type: vertical-stack
        cards:
          - type: entities
            show_header_toggle: false
            entities:
              - entity: sensor.jenna_trips_outside_today
                name: Jenna trips outside (today)
                icon: mdi:chart-line
              - entity: sensor.jenna_trips_outside_yesterday
                name: Jenna trips outside (yesterday)
                icon: mdi:chart-line
3 Likes

Thank you!

1 Like

Nice! Will this be read and write? So we can set the lock status from HA?

Anyone got pointers on getting this working with HA running in docker on Ubuntu ?

Not having any luck figuring it out.

Thank you so much!

Thanks for this, it’s working well for me on a Pi with hass.io :slight_smile:

Sooo, after a battery change in the pet_door and a modem reset (speed upgrade), this happened:

Error while setting up platform sure_petflap
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 126, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/sure_petflap/sensor.py", line 61, in setup_platform
    add_devices([SurePetConnect(username, password)])
  File "/config/custom_components/sure_petflap/sensor.py", line 80, in __init__
    self.update()
  File "/usr/local/lib/python3.7/site-packages/homeassistant/util/__init__.py", line 224, in wrapper
    result = method(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/util/__init__.py", line 224, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/sure_petflap/sensor.py", line 105, in update
    with self.sure:
  File "/config/custom_components/sure_petflap/__init__.py", line 646, in __enter__
    raise SPAPICacheLocked()
custom_components.sure_petflap.SPAPICacheLocked

Any ideas? Worked like a charm before. Thanks to @asif 's write-up.

How’s this?

If you can get this added as an HA component that supports the cat flap and multiple feeders, I’ll buy you a feeder.

I have two of the feeders and they are really excellent. Just like the cat flap. Very well made and thought out. I’m delighted with them and having them integrated with HA as a supported component would be awesome.

Aaaand. Never mind. Seems the cache file got corrupted or something. I changed the location in the init.py and the cats showed up again.

1 Like

Goodday,

When trying to get the pet i got a valid response (fist line)
After this there are a lot of errors.
as expected hass didn’t understand this.
Do i mis some components?

Thanks
Mark

root@Hass01:/home/homeassistant/.homeassistant/sure_petcare# python sp_cli.py ls_pets
Catname (*number*) is Inside
Traceback (most recent call last):
  File "sp_cli.py", line 156, in <module>
    main( sys.argv )
  File "sp_cli.py", line 80, in main
    CMDS[args.cmd[0]]( sp, args )
  File "sp_cli.py", line 110, in cmd_ls_pets
    print( '%s (%s) is %s' % (pdata['name'], pid, sp.get_current_status( pid ),) )
  File "/home/homeassistant/.homeassistant/sure_petcare/sure_petcare/__init__.py", line 761, in get_current_status
    loc = self.get_pet_location( pet_id, household_id )
  File "/home/homeassistant/.homeassistant/sure_petcare/sure_petcare/__init__.py", line 200, in get_pet_location
    raise SPAPIUnknownPet()
sure_petcare.SPAPIUnknownPet
root@Hass01:/home/homeassistant/.homeassistant/sure_petcare# python sp_cli.py ls_pets
Traceback (most recent call last):
  File "sp_cli.py", line 7, in <module>
    import sure_petcare
  File "/home/homeassistant/.homeassistant/sure_petcare/sure_petcare/__init__.py", line 9, in <module>
    import requests
ImportError: No module named requests