Flush the toilet reminder help

I have 2 young boys who have an aversion, as I believe most young boys do (and some old boys as well), to flushing the toilet. I recently installed a water meter to track my water consumption more frequently than once an hour through rtl-amr and I had an esp32 “starter” kit laying around and got the idea that I could use the water meter and an ultrasonic distance sensor to detect when someone used the toilet and then if there wasn’t an accompanying water usage afterwards it could send a notification to my phone to remind them to flush the toilet. I’ve tried to come up with a home assistant automation or set of automations but haven’t been able to get anything to work.

Here’s what I was thinking it would do and I’m hoping to get some help with implementation:

  1. If the ultrasonic sensor reads less than 12" for at least 15 seconds (10s polling interval, law of urination says mammals over 3kg take 21 seconds on average to empty their bladder) somebody is using the toilet, I was thinking this would be the trigger to start the automation

  2. Once triggered if the flow rate
    a. doesn’t register a flow greater than 0.0
    b. Doesn’t register an increase in flow rate of at least 1.0 gpm above what the flow rate was when step 1 triggered

Both 2a and 2b have their limitations and are probably going to have cases that don’t get caught (ie. 2a wouldn’t work while someone was showering or the sprinklers were running, 2b fails if the shower/sprinklers are running at the start of the automation but then turn off before flushing). I’m not looking for 100% detection, any caught unflushed poop is a win in my book.

  1. Send a notification to my phone to let me know it’s ass wiping time (another aversion)

I can do step 1 and 3 but the water use part is what I’m struggling with. Even if I assume that this one toilet is the only thing in the house that uses water I can’t figure out how to incorporate that. Anybody have any ideas?

Sincerely,
A Dad definitely not looking for an automation for himself

I wonder if a flushing toilet would trigger a vibration sensor attached or could you place a float valve in clean water tank of toilet instead of your #2. I can’t answer either question; just brainstorming.

And my 4-year-old daughter isn’t any better at flushing toilet than my 7-year-old son.

I would do something like this:

alias: Toilet not flushed notification
description: ""
mode: single
trigger:
  - platform: numeric_state
    entity_id: sensor.distance_to_toilet
    below: 12
    for:
      seconds: 15
condition: []
action:
  - variables:
      start_flow: "{{ states('sensor.watermeter_flow') | float(0) }}"
  - wait_template: "{{ states('sensor.watermeter_flow') | float(0) - start_flow > 1.0 }}"
    continue_on_timeout: true
    timeout: "30"
  - if:
      - "{{ not wait.completed }}"
    then:
      - service: notify.parent_notification
        data:
          message: Stinky water alert

Alright, so I created 3 automations in home assistant. First one watches for any change in US measurement with a condition of < 15" for 15 seconds, toggles on a toggle helper, delays for 1 minute, then turns the toggle off and this automation is set to “Repeat mode” so that as long as the distance is less than 15" it’ll keep the “throne occupied flag” set. Then a second automation triggers on the flag changing from “on” to “off”, delays 5 minutes and then sends the notification. And then finally the third notification is triggered on a flow rate greater than 1.0 gpm with the condition that the flag is still on and it disables the first two automations and stops their progress, waits 2 seconds, and then enable the notification automation and then the enable the presence flag automation.

I’ve tested it a couple times and it’s worked but there are at least two cases I can think of that will “break” it. First is if another water source is running at the same time which I feel is the harder of the two to solve. Second is if someone comes back after the presence flag has turned off but before the notification was sent but I’m not as concerned with that one and feel it has a fairly low probability of occurring.

For the first issue the vibration sensor might work, I’ll give that a look, I have an Aqara zigbee vibration sensor kicking around somewhere. A dedicated flow meter would also work but feels like overkill for this. I’ll get some real world testing with the kids tomorrow, 90% they ask what it is at they’re peeling it off the wall.



Thanks! I’ll try this out, a lot more elegant than what I came up with.

I don’t really understand.
So if you are on the toilet more than one minute then your flag will be deactivated and break your automation.
And if someone (hopefully) washes their hands after being on the toilet then it also breaks the automation.

And don’t post images of your automations.
Paste the text in a code block

I think a good sensor for part 1 could be a presence sensor with zone detection, like Aqara FP2.
I do not have such one myself, so make sure that zone detection actually work with HA before deciding for this option.

1st automation

alias: Toilet Presence flag set
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.ultrasonic_sensor_ultrasonic_sensor
condition:
  - condition: numeric_state
    entity_id: sensor.ultrasonic_sensor_ultrasonic_sensor
    below: 15
action:
  - service: input_boolean.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.toilet_flush_flag
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: input_boolean.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.toilet_flush_flag
mode: restart

Second automation

alias: Flush Notification
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.toilet_flush_flag
    from: "on"
    to: "off"
condition: []
action:
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - service: notify.mobile_app
    metadata: {}
    data:
      message: Somebody forgot to flush the Master toilet
      title: Flush
mode: single

Automation 3

alias: Halt Toilet Notification
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.water_flow_water_flow_rate
    above: 1
condition:
  - condition: state
    entity_id: input_boolean.toilet_flush_flag
    state: "on"
action:
  - service: automation.turn_off
    metadata: {}
    data:
      stop_actions: true
    target:
      entity_id:
        - automation.flush_notification
        - automation.ultrasonic_sensor
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: automation.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: automation.flush_notification
  - service: automation.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: automation.ultrasonic_sensor
mode: single

So if you are on the toilet more than one minute then your flag will be deactivated and break your automation.

No, since the automation is in repeat mode every 10s that the US sensor ticks and the measurement is <15" the action is interrupted and the automation restarts.

And if someone (hopefully) washes their hands after being on the toilet then it also breaks the automation.

The bathroom sink flow rate is typically less than 1 gpm but I just tested it and it peaked at 1.33 gpm so I updated the flush detection to 2 gpm which will also conveniently prevent a running shower from triggering it as well.