sureha icon indicating copy to clipboard operation
sureha copied to clipboard

Request: Ability to set pets home/away from Home Assistant

Open flyize opened this issue 3 years ago • 24 comments

When our cats get out/in the human door, it would be nice to be able to set their status via Home Assistant

flyize avatar May 10 '21 16:05 flyize

I was just thinking...

Is surepy available to an HA script? Until this could be officially implemented, I could just have an input selector that runs surepy when I set it to home/away.

flyize avatar May 10 '21 23:05 flyize

+1 Love to see the ability to do this too. I see some mention of it in the code.

xbmcnut avatar May 12 '21 06:05 xbmcnut

I would absolutely love this! Being able to create an NFC chip to cycle the location would be awesome because our oldest cat just doesn't want to learn how to use the cat flap!

sasgoose avatar Sep 08 '21 10:09 sasgoose

Agreed ... this would be a useful addition!

Gotcha-1980 avatar Sep 08 '21 11:09 Gotcha-1980

available in the dev branch now ;) but you have to enter the pet id for now, sorry ✌️

benleb avatar Sep 09 '21 21:09 benleb

Awesome. Can you share the service call for that?

xbmcnut avatar Sep 09 '21 22:09 xbmcnut

image

I think that shows everything you wanna know :D

benleb avatar Sep 09 '21 23:09 benleb

Thanks, but on the dev version you got me to install (bba9b0d), I'm not seeing that service as an option.

image

xbmcnut avatar Sep 09 '21 23:09 xbmcnut

that change came in a commit after yours, refresh HACS or restart HA and you should be able to update :) (Otherwise, try reinstalling the dev 👍 )

benleb avatar Sep 09 '21 23:09 benleb

Thanks. The problem is when your running a dev version, there is no longer an option to 'reinstall' as the add-on wants you to install the latest current version. So you have to kind of upgrade to 2.3 and then reinstall to have the ability to pick the new dev version.

[EDIT] Apologies, I take that back. Going into the integrations and clicking on the add-on reveals the reinstall option. Picking dev again now.

xbmcnut avatar Sep 09 '21 23:09 xbmcnut

Working great now. For others wanting to do this, I've set up a hold action on this custom-button card to call a script to set the pet as inside.

image

script:
  set_kobe_inside:
    alias: 'Set Kobe Inside'
    sequence:
      - service: sureha.set_pet_location
        data:
          pet_id: '123456' #Kobe's Code
          where: Inside      

And the code for button shown above. Icon changes from green to red when pet goes outside.

entity: binary_sensor.pet_kobe
icon: mdi:cat
layout: icon_name_state
show_name: false
show_state: true
styles:
  icon:
    - color: >
        [[[ if (states['binary_sensor.pet_kobe'].state === 'on') return "green";
        return "red"; ]]]
tap_action:
  action: more-info
hold_action:
  action: call-service
  service: script.set_kobe_inside
type: custom:button-card

xbmcnut avatar Sep 10 '21 00:09 xbmcnut

THIS IS AWESOME!

flyize avatar Sep 10 '21 13:09 flyize

Updated my card above as I forgot to add the service call. Now changed it to a hold_action too.

xbmcnut avatar Sep 10 '21 13:09 xbmcnut

Got mine all setup in NR. This is super sweet. Thanks @benleb

image

flyize avatar Sep 10 '21 14:09 flyize

this reminds me at a project I played with some time ago...

https://github.com/benleb/ad-catrack an appdaemon app which tracks a pet, a cat in my case, with various sensors like our sure flaps but I also used motion and vibration sensors. I put them at "her" places, cat owners know what is meant ;D For example in the garden on her sleeping chair, in her bedbox, ... the intention was to roughly know where to look for her but I can imagine other use cases too... don't vacuum in the room where she is or such things (she doesn't like the vacuum 🤷‍♀️) maybe I should give that project another chance 😕

benleb avatar Sep 10 '21 14:09 benleb

Is it possible to do the opposite here? I.e. when set their home/away status based on if the cat flap says they are inside/outside?

totalitarian avatar Sep 11 '21 10:09 totalitarian

Sorry, not quite sure what you're wanting to do.

xbmcnut avatar Sep 11 '21 10:09 xbmcnut

Hm mounted the flap the wrong way around? 😂

But I think that's a real edge case we shouldn't implement in sureha 😅 But to solve your problem, you could probably do a binary template sensor like {{ not states('binary_sensor.pet_goofy') }}

benleb avatar Sep 11 '21 10:09 benleb

Sorry, not quite sure what you're wanting to do.

I have my pet setup as a ‘person’. I would like her status synced with SureHA. So when the cat flap shows her as outside, the person is marked as away and when the cat flap shows her as inside, she is marked as home. This could be done by creating a device tracker for each pet I guess?

totalitarian avatar Sep 11 '21 12:09 totalitarian

Maybe this? https://community.home-assistant.io/t/sureflap-connect-pet-door/41488/386 https://github.com/pnbruckner/ha-composite-tracker

xbmcnut avatar Sep 11 '21 13:09 xbmcnut

Trying to create a script to switch the state. Any script expert around here? Thanks in advance for your help.

switch_sia_state:
  alias: "Switch Sia State"
  sequence:
    - choose:
        - conditions: >
            {{ binary_sensor.pet_sia == 'on' }}
          sequence:
            - service: sureha.set_pet_location
              data:
                pet_id: "!secret sia_id"
                where: Outside
        - conditions: >
            {{ binary_sensor.pet_sia == 'off' }}
          sequence:
            - service: sureha.set_pet_location
              data:
                pet_id: "!secret sia_id"
                where: Inside

yvansandoz avatar Sep 26 '21 09:09 yvansandoz

In the "useful things" section of the Readme I added a toggle location script. But there may be a better way of doing it.

script:
  toggle_thorin_location:
      alias: 'Toggle Thorin location'
      sequence:
        choose:
        - conditions:
            - condition: state
              entity_id: binary_sensor.pet_thorin_2
              attribute: where
              state: 1
          sequence:
            - service: sureha.set_pet_location
              data:
                pet_id: '123456' # Thorin's pet id
                where: Outside
        - conditions:
            - condition: state
              entity_id: binary_sensor.pet_thorin_2
              attribute: where
              state: 2
          sequence:
            - service: sureha.set_pet_location
              data:
                pet_id: '123456' # Thorin's pet id
                where: Inside

sasgoose avatar Sep 26 '21 10:09 sasgoose

@sasgoose Thanks a lot, it works like a charm with your version.

yvansandoz avatar Sep 26 '21 15:09 yvansandoz

And here my combined card for displaying the status and changing the parameters. Tap-hold on the cats with toogle the state as done by @xbmcnut .

image
type: vertical-stack
title: Chatière
cards:
  - type: horizontal-stack
    cards:
      - type: custom:button-card
        entity: binary_sensor.pet_sia
        name: Sia
        icon: mdi:cat
        label: |
          [[[
            return states['sensor.sia_last_state'].state;
          ]]]
        show_label: true
        show_name: true
        styles:
          card:
            - height: 110px
          label:
            - color: gray
            - font-size: 10px
          icon:
            - color: >
                [[[ if (states['binary_sensor.pet_sia'].state === 'on') return
                "green"; return "red"; ]]]
        tap_action:
          action: more-info
        hold_action:
          action: call-service
          service: script.toogle_sia_location
      - type: custom:button-card
        entity: sensor.pet_door_status_template
        show_state: true
        styles:
          card:
            - height: 110px
          state:
            - color: gray
            - font-size: 10px
        state:
          - value: locked_in
            color: rgb(255, 153, 153)
          - value: unlocked
            color: rgb(153, 255, 153)
          - value: locked_out
            color: rgb(255, 153, 153)
          - value: locked_all
            color: rgb(255, 153, 153)
      - type: custom:button-card
        entity: binary_sensor.pet_chilli
        name: Chilli
        icon: mdi:cat
        color: rgb(153, 255, 153)
        state:
          - value: 'off'
            color: rgb(255, 153, 153)
        label: |
          [[[
            return states['sensor.chilli_last_state'].state;
          ]]]
        show_label: true
        show_name: true
        styles:
          card:
            - height: 110px
          label:
            - color: gray
            - font-size: 10px
          icon:
            - color: >
                [[[ if (states['binary_sensor.pet_chilli'].state === 'on')
                return "green"; return "red"; ]]]
        tap_action:
          action: more-info
        hold_action:
          action: call-service
          service: script.toogle_chilli_location
  - type: horizontal-stack
    cards:
      - type: custom:button-card
        entity: sensor.cat_flap_chatiere_cuisine
        name: Unlock
        icon: mdi:clock
        tap_action:
          action: call-service
          service: sureha.set_lock_state
          service_data:
            flap_id: "your flap id"
            lock_state: unlocked
      - type: custom:button-card
        entity: sensor.cat_flap_chatiere_cuisine
        name: Lock In
        icon: mdi:upload-off-outline
        tap_action:
          action: call-service
          service: sureha.set_lock_state
          service_data:
            flap_id: "your flap id"
            lock_state: locked_in
      - type: custom:button-card
        entity: sensor.cat_flap_chatiere_cuisine
        name: Lock Out
        icon: mdi:download-off-outline
        tap_action:
          action: call-service
          service: sureha.set_lock_state
          service_data:
            flap_id: 480566
            lock_state: locked_out
      - type: custom:button-card
        entity: sensor.cat_flap_chatiere_cuisine
        name: Lock All
        icon: mdi:close-octagon
        tap_action:
          action: call-service
          service: sureha.set_lock_state
          service_data:
            flap_id: "your flap id"
            lock_state: locked_all

yvansandoz avatar Sep 26 '21 16:09 yvansandoz