Feline GPS: Tracking Cats with Home Assistant

home assistant cat nfc

One of my initial automations in Home Assistant was a Cat Tracker. We allow our cats onto an enclosed back porch on the west side of the house, where they relish basking in the afternoon sun. However, a recurring issue was forgetting whether the cats were indoors or outdoors, or sometimes even forgetting they were outside entirely. Enter the solution: The Cat Tracker. This automation utilizes a Boolean helper, an NFC tag, smart speakers, and a Mushroom Template card to help us keep tabs on our feline companions.

How It Works

  1. An NFC tag is scanned, or a Mushroom template card is used with a hold action to toggle the Cat Tracker Boolean.
  2. When the Cat Tracker Boolean is toggled on, the following actions occur:
    • If it's after sunset, the back porch string lights connected to a smart plug are turned on.
    • An announcement is made every 10 minutes until the Cat Tracker Boolean is toggled off.

Requirements

  • Smart speaker(s)
  • Optional: smart plug or smart light to turn on at sunset.
  • Optional: For announcements, my setup uses ChimeTTS from HACS.
  • Optional: To toggle the Boolean helper, my setup uses an NFC card. A mobile device with NFC and the Home Assistant Companion App are required to set up the NFC tag.
  • Optional: For displaying entities, my setup utilizes the Mushroom Template card from HACS. Other standard cards such as button cards could be substituted.

Creating a Toggle Helper

The purpose of the toggle helper is to track the cats' location (inside or outside) and to trigger and stop the automation. You can create the toggle helper using the steps below:

  1. Navigate to Settings > Devices & Services.
  2. Select Helpers > + Create Helper.
  3. In the Create Helper dialog, choose Toggle.
  4. In the Create Toggle dialog, enter the following details and select Create:
    • Name: Cat Tracker
    • Icon: mdi:cat

If desired, add a button to your Home Assistant dashboard that could be manually triggered. I've included the YAML for my Mushroom Template card bard below:

type: custom:mushroom-template-card
primary: Cat Status
secondary: |-
  {% if is_state('input_boolean.cat_tracker', 'on') %}
    A cat is outside.
  {% else %}
    The cats are indoors.
  {% endif %}
icon: mdi:cat
icon_color: |-
  {% if is_state('input_boolean.cat_tracker', 'on') %}
    red
  {% else %}
    green
  {% endif %}
tap_action:
  action: none
hold_action:
  action: toggle
double_tap_action:
  action: none
entity: input_boolean.cat_tracker

Writing an NFC Tag

Although optional, writing an NFC tag is an easy way to toggle the automation and provides an introduction to what NFC tags can offer for your home automations. They are inexpensive and easy to find on Amazon. The following steps need to be completed using the Home Assistant Companion app on a device capable of NFC.

  1. Go to Settings > Tags.
  2. Click + Add Tag.
  3. In the New Tag dialog, enter the following details and select Create and Write:
    • Name: Cat Tracker NFC
  4. Follow the instructions in the companion app to complete writing the NFC tag.

Create NFC Tag Automation

This step toggle the toggle helper created in the first step. If an NFC tag was not written, this step can be skipped. The following steps can be completed using Home Assistant or the Home Assistant Companion app.

  1. Go to Settings > Tags.
  2. Locate Cat Tracker NFC and select Create automation with tag (🤖 icon)
  3. In the Tag Cat Tracker NFC is scanned dialog automation, select Add Action under Then Do
  4. In the Add action dialog, type/select Input boolean: Toggle
  5. Under Targets, select + Choose entity > Cat Tracker
  6. Select Add Action under Then Do
  7. In the Add action dialog, type/select Call service
  8. In the Service dialog, type/select Logbook: Log
  9. In the Name dialog, type Cat Tracker NFC Tag Scanned Automation
  10. In the Message dialog, type Cat Tracker NFC tag scanned. Toggled cat_tracker boolean.
  11. Click Save

I've included the YAML for the automation below:

alias: Cat Out Reminder
description: Provide an aural reminder that a cat is outside.
trigger:
  - platform: state
    entity_id: input_boolean.cat_tracker
    to: 'on'
condition: []
action:
  - choose:
      - conditions:
          - condition: sun
            after: sunset
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.back_porch_plug_switch
  - repeat:
      sequence:
        - service: chime_tts.say
          data:
            chime_path: /media/j-alert_generic.mp3
            offset: 450
            final_delay: 0
            tts_speed: 100
            tts_pitch: 0
            volume_level: 0.5
            tts_platform: cloud
            message: A cat is on the porch.
          target:
            device_id: f1dbf28b268b6db14ce753df7a065459
        - delay:
            minutes: 10
      until:
        - condition: state
          entity_id: input_boolean.cat_tracker
          state: 'off'
  - service: logbook.log
    data:
      message: "Cat reminder announcement repeated every 10 minutes."
      name: Cat Tracker Automation
mode: single

Create Cat Tracker Automation

Now we get to the meat and potatoes of the automation. This automation turns on lights if toggled on after sunset it turns on the back porch light and then repeats a message on smart speaker(s) every 10 minutes to remind you that your cat is outside.

  1. In your Home Assistant dashboard, click on the "Settings" (the gear icon) in the bottom left corner.
  2. Under the "Automations & Scenes" section, click on "Automations".
  3. Click the "+ Add Automation" button to create a new automation.
  4. In the "Create automation" window click on "Create new automation"
  5. In the top right corner of the automation editor, you'll see an icon with three vertical dots (the "more options" menu); click on these three dots, and then select "Edit in YAML" from the dropdown menu.
alias: Cat Out Reminder
description: Provide an aural reminder that a cat is outside.
triggers:
  - entity_id: input_boolean.cat_tracker
    to: "on"
    trigger: state
conditions: []
actions:
  - choose:
      - conditions:
          - condition: sun
            after: sunset
        sequence:
          - target:
              entity_id: switch.back_porch_plug_switch
            action: switch.turn_on
            data: {}
  - repeat:
      sequence:
        - data:
            chime_path: /media/j-alert_generic.mp3
            offset: 450
            final_delay: 0
            tts_speed: 100
            tts_pitch: 0
            volume_level: 0.5
            tts_platform: cloud
            message: A cat is on the porch.
          target:
            entity_id: media_player.all_speakers
          action: chime_tts.say
        - data:
            name: "Automation: Cat Out Reminder"
            message: Aural reminder played.
          action: logbook.log
        - delay: "00:10:00"
      until:
        - condition: state
          entity_id: input_boolean.cat_tracker
          state: "off"
mode: single

Previous Post