There has to be more cat owners in here than me!
I wanted to share my configuration for my “smart litter boxes”. We live in a house, and our cats litter boxes are kind of hidden away and easy to forget. With this I get a notification on my phone after three visits. I have two sets of these files, one for each litter box.
Products used (per litter box): One Xiaomi human body sensor and one cheap 433mhz button from Ebay. You can of course use any kind of pir and even omit the button for using the gui if you want.
First comes the Litter box package with everything except the python scripts.
homeassistant:
customize:
sensor.downstairs_litter_box_visits:
icon: mdi:poop
binary_sensor.motion_sensor_158d0001a24ef1:
friendly_name: Downstairs Litter Box
#-------------------------------------------
sensor:
- platform: mqtt
state_topic: "dummy/downstairslitterbox/count"
name: Downstairs Litter Box Visits
unit_of_measurement: "visits"
#-------------------------------------------
automation:
- alias: Set Downstairs Litter Box Sensor To Zero On Start
trigger:
platform: homeassistant
event: start
action:
- service: python_script.dlitter_reset
- alias: Count visits to downstairs litter box
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor_158d0001a24ef1
to: 'on'
condition:
- condition: template
value_template: >
{% if states.automation.count_visits_to_downstairs_litter_box.last_triggered is not none %}
{% if as_timestamp(now()) | int - as_timestamp(states.automation.count_visits_to_downstairs_litter_box.attributes.last_triggered) | int > 300 %} true {% else %} false
{% endif %}
{% else %}
false
{% endif %}
action:
- service: python_script.dlitter_counter
- alias: Send notification when downstairs litter box is used more than three times
trigger:
- platform: numeric_state
entity_id: sensor.downstairs_litter_box_visits
above: '2'
- platform: state
entity_id: device_tracker.isabellas_iphone_6s
to: 'home'
for:
minutes: 10
condition:
condition: and
conditions:
- condition: time
after: '07:00:00'
before: '23:00:00'
- condition: state
entity_id: device_tracker.isabellas_iphone_6s
state: 'home'
- condition: numeric_state
entity_id: sensor.downstairs_litter_box_visits
above: '2'
action:
- service: notify.ios_isabellas_iphone_6s
data:
title: 'Time to clean!'
message: 'More than three visits to downstairs litter box'
- alias: Reset downstairs litter box visit counter
trigger:
- platform: state
entity_id: binary_sensor.white2
action:
- service: python_script.dlitter_reset
counter = hass.states.get('sensor.downstairs_litter_box_visits')
if counter is None:
value = 0
else:
value = int(counter.state)
hass.states.set('sensor.downstairs_litter_box_visits', value + 1)
Happy to ask any questions (or show pictures of my cats )! I also plan on keeping track of sudden changes in the litter box visits from stats later, could be used to detect if a cat is sick (sudden increase or decrease in litter box visits per day).
I’m not sure if I understand why the first if statement is implemented? Can you elaborate?
The second statement makes sure it only counts movement as a next visit if there are at least 5 minutes between the movement detections, right?
The one with last_triggered is not none? It checks that it actually has been triggered before checking the time. And yes, five minutes between. That potentially could make it miss one visit here and there, but it’s useful to eliminate a long visit counting as several.
Interesting timing on this - our ageing cat had an “accident” yesterday but we think he was just being more persnickity then usual about his litter tray so we need to clean it more often - this idea could help us keep track of him
No worries! First of all you need to enable python scripts by putting “python_script:” in your configuration.yaml. Then I just have them in a folder called “python_scripts” in the same directory as the config.
So its not always easy to see when it’s getting yucky.
This is a great idea!
I think that the Xiaomi sensor would work just fine in there, and hopefully without false positives from passing humans!
This is great. I can set the automation to text my daughters when it’s time to clean their assigned catbox!!! And here’s the required pic of our 2 cats, Bellatrix and Weasley