Lady Catterton's Automated Cat Alert System
Lady Catterton isn't allowed outside, but she doesn't let that stop her from keeping a close eye on the neighborhood cats that pass by. Here's how she does it completely locally.
Lady Catterton runs Home Assistant OS on a spare HP Mini PC. You can read about how she set it up here: https://www.wswapps.com/books/home-assistant/page/setup-home-assistant-on-a-mini-pc
Lady Catterton runs Frigate NVR as an addon in HAOS to monitor her local cameras and detect objects. You can read about her setup here: https://www.wswapps.com/books/home-assistant/page/frigate-nvr
And finally, Lady Catteron has configured some automations in Home Assistant to let you know any time she spots a fellow kitty. Below is an example of how she does that. She prefers to post to Mastodon, but you can post your important news anywhere. Maybe one day she'll get more creative with her words as well. Kitten steps.
This automation config looks for cat events coming from Frigate on a specific camera only after the event has ended, to ensure we only post about it once. After posting, we delay for 5 minutes to ensure that we don't get too excited and post again right away.
alias: Mastodon - Back Door Cat
description: Posts to Mastodon with cat image when Frigate detects a cat
triggers:
- trigger: mqtt
topic: frigate/events
payload: end
value_template: "{{ value_json.type }}"
conditions:
- condition: template
value_template: >-
{{ trigger.payload_json.after.label == 'cat' and trigger.payload_json.type
== 'end' and trigger.payload_json.after.camera == 'Back_Door' }}
enabled: true
actions:
- variables:
source_filename: >-
{{ trigger.payload_json.after.camera }}-{{ trigger.payload_json.after.id
}}.jpg
enabled: true
- delay: "00:00:03"
- data:
config_entry_id: MASTODON_ACCOUNT_ID_ASSIGNED_BY_HA_HERE
visibility: unlisted
status: >-
A 🐱 just came by the back door!
#cat #homeassistant #frigate
media_description: >-
I'm {{ (trigger.payload_json.after.score * 100) | round(1) }}% sure this
is a cat!
media_warning: false
media: /media/frigate/clips/{{ source_filename }}
action: mastodon.post
- delay: "00:05:00"
mode: single
Randomize messages
Improvements
- can
Randomizerandomize the posted messages abutbit by defining ayaml
file with a list of possible messages to be picked at random. For example, here are some of the intros which are then embedded into the status field when she posts:
cat_intro.yaml
>
{{ [
"Oh Boy!",
"Here kitty kitty.",
"Great Scott!",
"A visitor has arrived!",
"Mrrrp.",
"*Slow Blink*",
"Look!"
] | random }}
Now you can add this file as a variable in your automation:
- variables:
source_filename: '{{ trigger.payload_json.after.camera }}-{{ trigger.payload_json.after.id
}}.jpg'
cat_intro: !include /config/cat_intro.yaml
And put {{ cat_intro }}
in your message anywhere you want one of those random values to appear.
Important Note:
The automation UI in Home Assistant does NOT support these file includes. You must create a new file and manage them in code.
Create a file name like automations_advanced.yaml
and place this automation in there instead. Now inside your main configuration.yaml
file you can add the following lines to load both the UI based automations and the ones in your custom file:
automation: !include automations.yaml
# automations that use !include and cannot be configured in the UI
automation yaml: !include automations_advanced.yaml
This custom automation file will still be visible in the UI with the rest of your automations, but you will only be able to edit them by editing the automations_advanced.yaml
file directly.