Created
August 25, 2023 04:13
-
-
Save xbmcnut/6a3afa95e3d8f73807f9b76582031c05 to your computer and use it in GitHub Desktop.
Sureflap cat flap integration complete with dashboard code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- theme: Backend-selected | |
icon: mdi:paw | |
path: sureflap | |
badges: [] | |
cards: | |
- type: grid | |
cards: | |
- type: picture-glance | |
entities: [] | |
title: [] | |
state_image: | |
locked_all: /local/sureflap_fully_locked.jpg | |
unlocked: /local/sureflap_fully_unlocked.jpg | |
locked_in: /local/sureflap_in_only.jpg | |
locked_out: /local/sureflap_out_only.jpg | |
curfew: /local/sureflap_curfew.jpg | |
entity: sensor.pet_flap_laundry_door | |
show_state: [] | |
- type: glance | |
entities: | |
- entity: sensor.laundry_flap_battery_percentage | |
name: Battery | |
- entity: binary_sensor.laundry_door_connectivity | |
name: Flap | |
- entity: binary_sensor.hub_home | |
name: Hub | |
- entity: sensor.pet_flap_laundry_door | |
name: Status | |
icon: mdi:door | |
- entity: sensor.laundry_flap_battery_voltage | |
name: Voltage | |
state_color: true | |
- type: entities | |
entities: | |
- entity: automation.half_lock_cat_door_if_open_after_sunset | |
- entity: automation.unlock_cat_door_at_0600 | |
- entity: automation.announce_when_cat_door_fully_locked | |
- entity: switch.cat_door | |
- entity: sensor.sun_elevation | |
- type: grid | |
cards: | |
- type: button | |
tap_action: | |
action: toggle | |
entity: script.fully_lock_cat_door | |
name: Fully Lock Door | |
icon: mdi:paw | |
- type: button | |
tap_action: | |
action: toggle | |
entity: script.fully_unlock_cat_door | |
name: Fully Unlock Door | |
icon: mdi:paw | |
columns: 2 | |
square: false | |
- type: grid | |
cards: | |
- type: button | |
tap_action: | |
action: toggle | |
entity: script.in_only_cat_door | |
icon: mdi:paw | |
name: In Only | |
- type: button | |
tap_action: | |
action: toggle | |
entity: script.out_only_cat_door | |
name: Out Only | |
icon: mdi:paw | |
columns: 2 | |
square: false | |
- type: grid | |
cards: | |
- type: entities | |
entities: | |
- entity: binary_sensor.pet_tag | |
show_header_toggle: false | |
- type: entities | |
entities: | |
- entity: sensor.test_tag_activity | |
columns: 2 | |
square: false | |
columns: 1 | |
square: false | |
- type: grid | |
cards: | |
- type: picture-glance | |
image: /local/henry.jpg | |
entities: | |
- entity: device_tracker.pet_henry | |
icon: mdi:dog | |
show_state: true | |
- type: grid | |
cards: | |
- entity: device_tracker.pet_henry | |
icon: mdi:dog | |
layout: icon_name_state | |
show_name: false | |
show_state: true | |
styles: | |
icon: | |
- color: > | |
[[[ if (states['device_tracker.pet_henry'].state === | |
'home') return "green"; return "red"; ]]] | |
tap_action: | |
action: more-info | |
hold_action: | |
action: call-service | |
service: script.set_henry_inside | |
type: custom:button-card | |
- type: entity | |
entity: sensor.henry_last_state | |
icon: mdi:wallet-travel | |
- type: entity | |
entity: sensor.henry_trips_outside_today | |
- type: entity | |
entity: sensor.henry_trips_outside_yesterday | |
columns: 1 | |
square: false | |
square: false | |
columns: 1 | |
- type: grid | |
cards: | |
- type: picture-glance | |
image: /local/kobe.jpg | |
entities: | |
- entity: binary_sensor.pet_kobe | |
icon: mdi:cat | |
show_state: true | |
- type: grid | |
cards: | |
- 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 | |
- type: entity | |
entity: sensor.kobe_last_state | |
- type: entity | |
entity: sensor.kobe_trips_outside_today | |
- type: entity | |
entity: sensor.kobe_trips_outside_yesterday | |
columns: 1 | |
square: false | |
square: false | |
columns: 1 | |
- type: grid | |
cards: | |
- type: picture-glance | |
image: /local/heston.jpg | |
entities: | |
- entity: binary_sensor.pet_heston | |
icon: mdi:cat | |
show_state: true | |
- type: grid | |
cards: | |
- entity: binary_sensor.pet_heston | |
icon: mdi:cat | |
layout: icon_name_state | |
show_name: false | |
show_state: true | |
styles: | |
icon: | |
- color: > | |
[[[ if (states['binary_sensor.pet_heston'].state === | |
'on') return "green"; return "red"; ]]] | |
tap_action: | |
action: more-info | |
hold_action: | |
action: call-service | |
service: script.set_heston_inside | |
type: custom:button-card | |
- type: entity | |
entity: sensor.heston_last_state | |
- type: entity | |
entity: sensor.heston_trips_outside_today | |
- type: entity | |
entity: sensor.heston_trips_outside_yesterday | |
columns: 1 | |
square: false | |
square: false | |
columns: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
automation: | |
- alias: "Half Lock Cat Door if open after sunset" | |
id: a6deaf03-0241-45e0-bd49-8498b13fa9dd | |
trigger: | |
- platform: sun | |
event: sunset | |
## postive value is after sunset ## | |
# offset: '00:20:00' | |
# offset: '-00:45:00' | |
## 45 minutes before sunset looks like the above ## | |
- platform: sun | |
event: sunset | |
## postive value is after sunset ## | |
offset: '00:10:00' | |
condition: | |
- condition: state | |
entity_id: sensor.pet_flap_laundry_door | |
state: 'unlocked' | |
action: | |
- service: sureha.set_lock_state | |
data: | |
flap_id: !secret flap_id | |
lock_state: locked_in | |
- wait_template: "{{ is_state('sensor.pet_flap_laundry_door', 'locked_in') }}" | |
timeout: '00:02:00' | |
continue_on_timeout: 'true' | |
- service: media_player.play_media | |
data: | |
entity_id: | |
- media_player.lounge_home | |
- media_player.kitchen_home | |
media_content_id: http://ha.ip.address:8123/local/audio/lock.mp3 | |
media_content_type: 'audio/mp3' | |
- service: browser_mod.navigate | |
data: | |
path: /lovelace-duet/sureflap | |
target: | |
device_id: lenovo-duet5 | |
- delay: 00:00:30 | |
- service: browser_mod.navigate | |
data: | |
path: /lovelace-duet/tablets | |
target: | |
device_id: lenovo-duet5 | |
- alias: "Announce when cat door fully locked" | |
id: 0db3cae1-3a9e-4662-a1aa-baffc66b600e | |
trigger: | |
- platform: state | |
entity_id: sensor.pet_flap_laundry_door | |
to: locked_all | |
action: | |
- service: media_player.play_media | |
data: | |
entity_id: | |
- media_player.lounge_home | |
- media_player.kitchen_home | |
media_content_id: http://ha.ip.address:8123/local/audio/door_locking.mp3 | |
media_content_type: 'audio/mp3' | |
- alias: "Announce when Kobe comes in" | |
id: 14c30678-8aa5-4a3a-a112-7c72879a71e0 | |
trigger: | |
platform: state | |
entity_id: sensor.pete_s_pixel_7_last_notification | |
to: 'Kobe has entered through Laundry Door... Hi Kobe!' | |
action: | |
- service: media_player.play_media | |
data: | |
entity_id: | |
- media_player.lounge_home | |
- media_player.kitchen_home | |
media_content_id: http://ha.ip.address:8123/local/audio/doortrek2.mp3 | |
media_content_type: 'audio/mp3' | |
- alias: "Unlock cat door at 0600" | |
id: a020acf9-a020-442b-a01b-7924a296f4fc | |
trigger: | |
- platform: time | |
at: "06:00:00" | |
# event: sunrise | |
# ## postive value is after sunset ## | |
# # offset: '00:20:00' | |
# offset: '-00:20:00' | |
# ## 45 minutes before sunset looks like the above ##' | |
condition: | |
- condition: state | |
entity_id: sensor.pet_flap_laundry_door | |
state: | |
- locked_all | |
- locked_in | |
- locked_out | |
action: | |
- wait_template: "{{ is_state('binary_sensor.hub_home', 'on') }}" | |
- wait_template: "{{ is_state('binary_sensor.laundry_door_connectivity', 'on') }}" | |
- service: sureha.set_lock_state | |
data: | |
flap_id: !secret flap_id | |
lock_state: unlocked | |
########################################################## | |
script: | |
fully_lock_cat_door: | |
alias: 'Lock cat door' | |
sequence: | |
- service: sureha.set_lock_state | |
data: | |
flap_id: !secret flap_id | |
lock_state: locked_all | |
fully_unlock_cat_door: | |
alias: 'Unlock cat door' | |
sequence: | |
- service: sureha.set_lock_state | |
data: | |
flap_id: !secret flap_id | |
lock_state: unlocked | |
in_only_cat_door: | |
alias: 'Lock in cat door' | |
sequence: | |
- service: sureha.set_lock_state | |
data: | |
flap_id: !secret flap_id | |
lock_state: locked_in | |
out_only_cat_door: | |
alias: 'Lock out cat door' | |
sequence: | |
- service: sureha.set_lock_state | |
data: | |
flap_id: !secret flap_id | |
lock_state: locked_out | |
set_henry_inside: | |
alias: 'Set Henry Inside' | |
sequence: | |
- service: sureha.set_pet_location | |
data: | |
pet_id: '196064' #Henry's Code | |
where: Inside | |
set_heston_inside: | |
alias: 'Set Heston Inside' | |
sequence: | |
- service: sureha.set_pet_location | |
data: | |
pet_id: '196066' #Hestons Code | |
where: Inside | |
set_kobe_inside: | |
alias: 'Set Kobe Inside' | |
sequence: | |
- service: sureha.set_pet_location | |
data: | |
pet_id: '198165' #Kobe's Code | |
where: Inside | |
#################################################################### | |
switch: | |
- platform: template | |
switches: | |
cat_door: | |
friendly_name: Cat Door Template Switch | |
# A value template can only report true or false # | |
value_template: "{% if states('sensor.pet_flap_laundry_door' ) != 'unlocked' %}on{%else%}off{%endif %}" | |
turn_on: | |
- service: sureha.set_lock_state | |
data: | |
flap_id: !secret flap_id | |
lock_state: locked_all | |
turn_off: | |
- service: sureha.set_lock_state | |
data: | |
flap_id: !secret flap_id | |
lock_state: unlocked | |
icon_template: >- | |
{% if is_state('sensor.pet_flap_laundry_door', 'unlocked') %} | |
mdi:door-open | |
{% else %} | |
mdi:door-closed-lock | |
{% endif %} | |
sensor: | |
- platform: template | |
sensors: | |
henry_status: | |
friendly_name: "Henry Status" | |
unique_id: 85381de7-24e7-47c7-9120-e599f49dea00 | |
value_template: "{{ state_attr('binary_sensor.pet_henry', 'where') }}" | |
henry_last_state: | |
friendly_name: "Henrys Last Status" | |
unique_id: 73064570-eb85-49b8-a632-398be6a02cf9 | |
value_template: "{{ state_attr('binary_sensor.pet_henry', 'where') }} since {{as_timestamp(state_attr('binary_sensor.pet_henry', 'since')) | timestamp_custom('%H:%M')}}" | |
kobe_status: | |
friendly_name: "Kobe Status" | |
unique_id: c44e2deb-c0cf-44d6-88ce-413f06fba323 | |
value_template: "{{ state_attr('binary_sensor.pet_kobe', 'where') }}" | |
kobe_last_state: | |
friendly_name: "Kobes Last Status" | |
unique_id: 2f059102-d969-4e77-95c6-73ea20d6fd31 | |
value_template: "{{ state_attr('binary_sensor.pet_kobe', 'where') }} since {{as_timestamp(state_attr('binary_sensor.pet_kobe', 'since')) | timestamp_custom('%H:%M')}}" | |
heston_status: | |
friendly_name: "Heston Status" | |
unique_id: c0417102-dee3-4598-a099-12f05f6deaf5 | |
value_template: "{{ state_attr('binary_sensor.pet_heston', 'where') }}" | |
heston_last_state: | |
friendly_name: "Hestons Last Status" | |
unique_id: a1cbd016-e838-4684-bf0a-1922a0130182 | |
value_template: "{{ state_attr('binary_sensor.pet_heston', 'where') }} since {{as_timestamp(state_attr('binary_sensor.pet_heston', 'since')) | timestamp_custom('%H:%M')}}" | |
tag_status: | |
friendly_name: "Tag Status" | |
unique_id: 6b4bc2b0-4778-44f6-ac87-26c30a8d27de | |
value_template: "{{ state_attr('binary_sensor.pet_tag', 'where') }}" | |
tag_last_state: | |
friendly_name: "Tag Last Status" | |
unique_id: c8e4dfc1-0d1d-4a06-8497-aad7e5c71cd3 | |
value_template: "{{ state_attr('binary_sensor.pet_tag', 'where') }} since {{as_timestamp(state_attr('binary_sensor.pet_tag', 'since')) | timestamp_custom('%H:%M')}}" | |
laundry_flap_battery_voltage: | |
friendly_name: "Laundry Flap Battery Voltage" | |
unique_id: 43cee353-d41e-4b6f-9e8c-f650e8bd7714 | |
value_template: '{{ state_attr("sensor.pet_flap_laundry_door_battery_level", "voltage_per_battery") }}' | |
laundry_flap_battery_percentage: | |
friendly_name: "Laundry Flap Battery Percentage" | |
unique_id: 152e1a37-79ac-4fd4-95fe-df9c8675bd8d | |
value_template: '{{ state_attr("sensor.pet_flap_laundry_door_battery_level", "battery_level") }}' | |
unit_of_measurement: '%' | |
## Test TAG ## | |
# For tracking number of times activity is detected | |
# in last 7 days | |
- platform: history_stats | |
name: Test Tag Activity | |
entity_id: binary_sensor.pet_tag | |
state: 'off' | |
type: count | |
end: '{{ now() }}' | |
duration: | |
days: 7 | |
## Henry ## | |
- platform: history_stats | |
name: Henry outside time (today) | |
entity_id: binary_sensor.pet_henry | |
state: "off" | |
type: time | |
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}' | |
end: '{{ now() }}' | |
- platform: history_stats | |
name: Henry outside time (yesterday) | |
entity_id: binary_sensor.pet_henry | |
state: 'off' | |
type: time | |
end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}' | |
duration: | |
hours: 24 | |
- platform: history_stats | |
name: Henry trips outside (today) | |
entity_id: binary_sensor.pet_henry | |
state: 'off' | |
type: count | |
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}' | |
end: '{{ now() }}' | |
- platform: history_stats | |
name: Henry trips outside (yesterday) | |
entity_id: binary_sensor.pet_henry | |
state: 'off' | |
type: count | |
end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}' | |
duration: | |
hours: 24 | |
# Heston ## | |
- platform: history_stats | |
name: Heston outside time (today) | |
entity_id: binary_sensor.pet_heston | |
state: 'off' | |
type: time | |
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}' | |
end: '{{ now() }}' | |
- platform: history_stats | |
name: Heston outside time (yesterday) | |
entity_id: binary_sensor.pet_heston | |
state: 'off' | |
type: time | |
end : '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}' | |
duration: | |
hours: 24 | |
- platform: history_stats | |
name: Heston trips outside (today) | |
entity_id: binary_sensor.pet_heston | |
state: 'off' | |
type: count | |
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}' | |
end: '{{ now() }}' | |
- platform: history_stats | |
name: Heston trips outside (yesterday) | |
entity_id: binary_sensor.pet_heston | |
state: 'off' | |
type: count | |
end : '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}' | |
duration: | |
hours: 24 | |
## Kobe ## | |
- platform: history_stats | |
name: Kobe outside time (today) | |
entity_id: binary_sensor.pet_kobe | |
state: 'off' | |
type: time | |
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}' | |
end: '{{ now() }}' | |
- platform: history_stats | |
name: Kobe outside time (yesterday) | |
entity_id: binary_sensor.pet_kobe | |
state: 'off' | |
type: time | |
end : '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}' | |
duration: | |
hours: 24 | |
- platform: history_stats | |
name: Kobe trips outside (today) | |
entity_id: binary_sensor.pet_kobe | |
state: 'off' | |
type: count | |
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}' | |
end: '{{ now() }}' | |
- platform: history_stats | |
name: Kobe trips outside (yesterday) | |
entity_id: binary_sensor.pet_kobe | |
state: 'off' | |
type: count | |
end : '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}' | |
duration: | |
hours: 24 | |
## https://youtu.be/qm2FuJNE3BI?list=PL-Vi6N_KaW48xG7GH8xIblPmwmoBwGqOA&t=497 ## | |
utility_meter: | |
# Use the 7 day history of activity | |
# to get daily motion. | |
daily_pet_tag_activity: | |
source: sensor.test_tag_activity | |
cycle: daily |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And here's the end result