Smart Litter Box (or Smart Cats)

The inevitable overtaking of the community by cats?

3 Likes

Looks like it, yes :slight_smile:

Anacleta (Eclectus female), Dudu (Sun Conure male), Yoshi (Indian RingNeck male)

and our newest member Scarlet the Scotish fold female

5 Likes

Actually Scarlet isn’t our last family member!!
Almost forgot I bought yesterday a Venus flytrap (Dionaea muscipula)

Already busy making her soil moisture sensor, temperature, and lux :smiley:

1 Like

This is a great little project! I have two cats and decided to give this a try. I’m using a spare esp8266 and pir sensor with MQTT. I figured out a way to update the dummy sensor directly from configuration.yaml using mqtt.publish service rather than using external python scripts. It increments the count and posts a card to the Web page each time the sensor trips. I just run the reset automation to zero out the count for now. I plan to add a reset button to the esp at some point.

Posting in case anyone is interested.

  - alias: Count visits to litter box
    trigger:
      - platform: state
        entity_id: sensor.pir
        to: '1'
    condition: 
    - condition: template
      value_template: >
        {% if states.automation.count_visits_to_litter_box.last_triggered is not none %}
          {% if as_timestamp(now()) | int   -  as_timestamp(states.automation.count_visits_to_litter_box.attributes.last_triggered) | int > 300 %} true {% else %} false
          {% endif %}
        {% else %}
        false
        {% endif %}
    action:
      - service: persistent_notification.create
        data:
          title: "Litter Box"
          message: ' {{ now().strftime("%I:%M %p") }} Litter Box Visit! '
      - service: mqtt.publish
        data:
          topic: "dummy/litterbox/count"
          payload_template: '{{ states.sensor.litter_box_visits.state |int +1  }}'
  - alias: Set Litter Box Sensor To Zero On Start
    trigger:
      platform: homeassistant
      event: start
    action:
      - service: mqtt.publish
        data:
          topic: "dummy/litterbox/count"
          payload: 0
6 Likes

My situation was a little bit different. We have one litter tray in our house, and want to check/empty it after every visit to minimise odour.

The tray is conveniently in the same room as my Raspberry Pi, though. So I was able to build my own sensor, with a PIR attached to an Arduino, plug it in to the Pi, and check its state with a serial sensor.

Every second, the Arduino sends a number. 0 means the tray hasn’t been visited. Greater than 0 is the time in seconds since last visit. The sensor also has a button attached - after cleaning the tray you hit the button, and the sensor is reset back to an unvisited state. This makes it a lot easier to track visits.

I have three sensors: One is just the raw readings from the serial device. One parses that reading from seconds to a friendly string. And one uses that string and a custom icon for use in the frontend.

sensor:
  - platform: serial
    name: raw poopmon
    serial_port: /dev/ttyS3
  - platform: template
    sensors:
      poopmon_time:
        friendly_name: "Time when litter tray was last used"
        value_template: >-
          {% set time = states.sensor.raw_poopmon.state | int %}
          {% set minutes = ((time % 3600) / 60) | int %}
          {% set hours = ((time % 86400) / 3600) | int %}
          {%- if time < 60 -%}
            less than a minute
          {%- else -%}
            {%- if hours > 0 -%}
              {% if hours == 1 -%}
                1 hour
              {%- else -%}
                {{ hours }} hours
              {%- endif -%}
            {%- endif -%}
            {%- if minutes > 0 -%}
              {%- if hours > 0 -%}
                {{ ', ' }}
              {%- endif -%}
              {%- if minutes == 1 -%}
                1 minute
              {%- else -%}
                {{ minutes }} minutes
              {%- endif -%}
            {%- endif -%}
          {%- endif -%}
      litter_tray:
        friendly_name: "Eli's litter tray"
        value_template: >-
          {% if states.sensor.raw_poopmon.state|int == 0 %}
            Clean
          {% else %}
            Last used {{ states.sensor.poopmon_time.state }} ago
          {% endif %}
        icon_template: >-
          {% if states.sensor.raw_poopmon.state|int == 0 %}
            mdi:cat
          {% else %}
            mdi:emoticon-poop
          {% endif %}

Automations are done by just looking at the raw readings:

automation:
  - id: 'cat poop notification'
    alias: cat poop notification
    trigger:
      platform: numeric_state
      entity_id: sensor.raw_poopmon
      above: 0
    action:
      service: notify.html5_notifier
      data_template:
        title: "\uD83D\uDCA9 alert"
        message: Litter box has been visited

  - id: 'clean tray notification'
    alias: clean tray notification
    trigger:
      platform: numeric_state
      entity_id: sensor.raw_poopmon
      below: 1
      for:
        minutes: 3
    action:
      service: notify.html5_notifier
      data_template:
        title: "\uD83D\uDE3B alert"
        message: Litter box has been cleaned

I haven’t checked yet, but it should be fairly easy to count visits by just looking for raw_poopmon changing state from 0 to >0.

4 Likes

This needs https://home-assistant.io/components/xiaomi_aqara/ no?

Do you also need the “Xiaomi gateway” for this to work? Just asking because you didn’t mention it specifically, a bit confused.

You need the gateway if you don’t have any other way of getting the sensors in hass. For example, Homey and Smartthings can both take the Xiaomi sensors without the gateway, and I think you can also use the Conbee usb stick.

1 Like

Thats Thinking out side the Litter box LOL
Like the Logic :slight_smile: :beer:

1 Like

I need this :smiley_cat:
Since we have the litterbox where people passes I’m wondering if a internal pir would do the trick? Just have to figure out how to get the electricity close enough…
Where did you all put your motion detectors? :slight_smile:

The litter boxes are kind of hidden away, so that’s not a problem with people passing here.

Ok, thanks for the inspiration. Got it to work beautifully and the daughter gets a hangout message after a few visits. I get a hangout message when someone claims it to be cleaned :smiley:

1 Like

Hallo @teachingbirds !

First of all: THIS IS SUCH A GREAT IDEA! I LOVE IT

Just integrated a adjusted version of your code

to be honest, just a few adjustments :)I did it with a template sensor with input number behind, because of mqtt install problems, and some changes to the settings

Which motion sensor do you use?
Do you show “last time toilet cleaned”? If yes how you do this. Tried to read out the last triggered attribute of the reset automation and reset script, did not work (breaking change sometime between our posts) anyway GREAT WORK

Really would love to see some „cat littering data“ of people who integrated something like this… :cat2: :smile_cat:

GREEZ from Vienna
Martin

1 Like

I’m not showing the latest time it was cleaned, but that is a great idea. Will have to figure that out. I’ve since this post moved this to Appdaemon, so I could probably do it there.

Hey!
Love this idea
I’ve not used a Xiaomi human body sensor before. How does this part work?
Does it attach to the box and sense motion in or? Or something else?
Any chance you can share an image of the setup and parts with the tray please?

It’s really nothing more than setting up the motion sensor so that it detects when the cat moves inside the box. This could be difficult depending on the litter box model and placement. I have large plastic storage boxes without lids for my cats, placed in less visited corners of the rooms. I just placed the motion sensors as far inside the corner as possible and aimed them downwards at the litter boxes.
If you have the enclosed ones with flap door I guess you could use a magnet sensor on the flap door (with some kind of timeout so that it doesn’t register another visit when the cat exits), or a bit more diy with a load cell for sensing when the weight changes.

1 Like

Image of sensor setup completed with cat peeing. :smiley:

5 Likes

ha! thanks!

What sensors do you guys use for this & are they battery powered? Can’t wait to set this up :poop:

I have xiaomi motion sensors.