Tracking Sump Pump (Idle + Run with details)

Hi there,
Been using HA for several years now, but recently moved to a home with a Sump Pump. I want to monitor my Sump Pump running. I’ve used a zwave aeotec which monitors power and I’ve created a logging file with 2 automations. One which writes a record when the current goes up above 0.5 Amp (turns on) and one which writes a record to a File when it goes below 5 amps (normal running is 8-9 Amps. I then have a log file of the transactions.

I’ve written a powershell which can process this log and create single run transactions of how long it ran and how long between runs (idle time). I then built a sensor which reads the last line of that log to show the last run and other details in the HA UI.

I can run my powershell on a separate schedule (windows task scheduler), but was wondering about whether I should approach this as either a Python script to run with the “off” automation or should I be able to use a Template to manage the calculations every “off” cycle to check since the last off (Idle + Run).

Eventually then I’d like to have a file which I can use to graph and trend for say last x days, last x months… some trending which helps me understand the cycles of water flow around the house.

1 Like

@brian.walker I just found this as I am on a similar quest. And I got real excited when I saw powershell mentioned as that’s my native tongue :slight_smile:

You didn’t say what you want to achieve. putting this on “paper”, my ultimate goal is to report a couple things:

  1. Number of times sump ran last hour, last day, last 7 days & last month
  2. Total run time hour, day, week, month
  3. Whether hourly and daily trend is up or down
  4. Avg amount of current used per run and its trend

#1 would be my first priority and #4 would be a good second as it might help diagnose a failing pump.

Saying all this, this looks like a template problem for HA - not sure we need external code. Of course, I know very little about templates, so I’m starting to study them.
I was given this code on the Everything Smart Home discord by @davecrane21 as a starting place. I think it shows that the history_stats platform can track and store the usage so long as we build the right “sensors”. I’ll be doing some work on this this week.

platform: history_stats
    name: All lights on Today
    entity_id: light.all_inside_lights
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

  - platform: template
    sensors:
      all_lights_on_today_minutes:
        unit_of_measurement: minutes
        value_template: >-
          {{ state_attr('sensor.all_lights_on_today', 'value') }}

I’ve managed to put together some automation writing to a text file from a sensor on the Aeotec plug so when it begins to draw power (ON) it writes to the log and then when it goes back to (OFF) stopping to draw power it writes again to the log. I then do have a powershell that reads the log file and creates my run times from the ON to OFF and I get a single log.

Running time: 01/08/2022 13:03:14 is 7 seconds since last run 78 min ago
Running time: 01/08/2022 14:15:02 is 6 seconds since last run 71 min ago

I could create now a running csv that I can use to graph and analyse and have been planning to put the weather conditions with it, but would like to have Home Assistant sense the on and the off and write to the log but have not yet figure all that out.

Certainly interested as I’d like to eventually have some running profile of my sump pump. I’m planning to install two float switches to sense the on off during the pumping (normal working range), but also a high level that tells me the pump likely has failed. I’m trying to find a linear sensor that would tell me the depth of the water as I’d love to do the math and predict the overflow. Of course I realize that in a power outage I’m going to need some type of UPS or battery to at least keep the sensors running and figure out how to notify me if I’m not at home (call the neighbors :slight_smile: ). I can think of a backup generator and how to remotely start it in a power failure… lots of scenarios to consider before I finish my basement.

Welcome to the journey.

1 Like

This was much simpler than I thought. The solution is two parts using a template sensor to record a running/on state plus a history_stats sensor that records the time or count of times it ran.
First a template sensor that detects the running state and logs it. I did this using this simple template code

- name: "Sump running"
    state: "{% if states('sensor.bsmt_sump_smartenergy_metering')|float(0) > 0  %} true {% else %} false {% endif %}"

This gets the value of the metering state, converts it to float and sets the “sump_running” state to true if it is greater than 0 and false otherwise.

The second part of this is a sensor using the history_stats platform that transforms the state into a count for the day.

- platform: history_stats
    name: sump run count today
    entity_id: sensor.sump_running
    state: "true"
    type: count
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    duration:
      hours: 24

This tracks the number of times it has run during the current day.
If you wanted instead to track the run time for the day, this would do it:

- platform: history_stats
    name: dehumid run time today
    entity_id: sensor.dehumid_running
    state: "true"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    duration:
      hours: 24

The difference is the type of time instead of count

2 Likes

One more point on this. If you want to track one day’s/week’s/month’s usage vs the next, you can use utility meter integration for this as it can track more than energy. I defined this to track dehumidifier run time month to month
Given the history_stats definition above, add this:

utility_meter:
  monthly_dehumid_power:
    source: sensor.sengled_e1c_nb7_728e6b03_smartenergy_metering_summation_delivered
    cycle: monthly

this will give monthly stats for the sensor. The cycle is adjustable (day, week, month, year)

1 Like

@uSlackr thanks for the dev work till here. I will pull it all together and add some remarks for beginners, I also fixed some bad indentations and spaces, that resulted in errors on my system.

Into the template part of the configuration.yaml (or if you have included a templates.yaml, then there) goes:

# Sump Pump running stats#
  - sensor: 
    - name: "Sump running"
      state: "{% if states('sensor.smartplug_name_energy_power')|float(0) > 0  %} true {% else %} false {% endif %}"

you have to replace sensor.smartplug_name_energy_power with your pump metering entity. Watts and Amps are okay, but watt is preferable, bigger change, but even 0.001A is more than zero, so make sure your metering device is calibrated. With my nous A1 with tasmota I see 0 Watts and 0.02a all the time :slight_smile: so check what you pick for a sensor.

Next step:

Into the Sensor part of the configuration.yaml (or if you have included a sensors.yaml, then there) goes:

#sump pump history run count#
- platform: history_stats
  name: sump run count today
  entity_id: sensor.sump_running
  state: "true"
  type: count
  start: "{{ now().replace(hour=0, minute=0, second=0) }}"
  duration:
    hours: 24


#sump pump history run time#
- platform: history_stats
  name: sump run time today
  entity_id: sensor.sump_running
  state: "true"
  type: time
  start: "{{ now().replace(hour=0, minute=0, second=0) }}"
  duration:
    hours: 24

And finally the monitoring via the utility_meter thing. same applies as above, it goes into configuration.yaml, of if you included a utility_meters.yaml, then there:

utility_meter:
  monthly_sump_pump_power:
    source: sensor.smartplug_name_energy_total
    cycle: monthly

where you have to replace the sensor.smartplug_name_energy_total with your own delivery metering device, not the current consumption!

In this whole setup, I miss a “stuck float switch” check.

If the consumption goes down due to sucking air and still running, or if it is on for way longer than usual, it should trip an alarm, same goes for unusual long times with no consumption. So the average consumption over the past 7 days should be tracked in relation to the average of the last 2 days, if it varies significantly downward, there should also be an alarm. Ill add this when Im done and have proven it working. Why, my float gets suck about once a month, and then I need rubber boots to fix it and have to clean up afterward. If HA would alert me half a day earlier compared to the the water sensor, I would just need to walk to the pump and tuck on the cable to fix it.

3 Likes

Good write up. The stuck float should be easy. Write an automation that triggers on sensor.sump_running with a duration of, say, 30 seconds. The duration will be site specific. In my house, the sump rarely runs more than 10-15 seconds at a time. (which is why I count runs instead of duration for my history stats)

Thanks for the idea how to handle it.

For me its an issue, in the 90s as we added a basement, but that finished floor level is a couple of centimeters below the rest of the self draining house basement level.

So flooding is no big issue, everything is hanging of the walls, and expecting this, we used cement for everything in the construction and tiled all the walls, there is no plaster or carpet or bricks. But I have to clean up and vent the humidity out and then heat with the floor heating to dry the room later on.

So basically when ever the pump float switch is ocasionally not activating we will get flooded by our own rain gutter water.

On light rain events, pump comes on once an hour for a bunch of seconds. On heavy rain events, its on 50% of time, and about 240 seconds each cycle pumping about a quarter m³ (about 60 bananas).

I know rain amount from rain sensor and forecast. So I can adjust my monitoring. But Im not jet clear how I will do it.

Ill be back here with my solution, also it may take a while to get it done. Probably until I have to clean up once or twice. :slight_smile:

1 Like

You certainly have a different use case than I. But I wonder if you need a stronger pump that can empty that faster? Good luck!

I’ve taken a lot from this thread and implemented nearly all of it, so thank you all. I’m having trouble getting the daily run time sensor to give me a proper value. I’m using the code pasted below, and the daily count sensor works as expected, but I just get a zero value for the daily run time. I’ve been through it a thousand times and I can’t figure out why that is.

#ejector pump history run count#
  - platform: history_stats
    name: ejector run count today
    entity_id: sensor.ejector_pump_running
    state: 'true'
    type: count
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: '{{ now() }}'
    
#ejector pump history run time#
  - platform: history_stats
    name: ejector run time today
    entity_id: sensor.ejector_pump_running
    state: 'true'
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: '{{ now() }}'`
1 Like

Does using a Utility Meter Helper also enable you to swap out devices over time but retain the stats by changing the ‘source’?
e.g. relocating a kitchen appliance on to a different energy monitoring smart plug/socket

Does the utility meter tracking a _sumation_delivered entity report power (kW) or energy (kWh) ?

I’m pretty sure it is by entity name so i wouldn’t think so. Maybe renaming it would work.

Looks to be unit independent. I have it count power consumption, internet use and run count.

1 Like

I just implemented this myself recently. Here’s what I’m using. Perhaps you are missing the ‘running’ sensor:

sensor:
  - name: "Sump running"
    state: "{% if states('sensor.bsmt_sump_smartenergy_metering')|float(0) > 2  %} true {% else %} false {% endif %}"


  - platform: history_stats
    name: Sump Runtime today
    entity_id: sensor.sump_running
    state: "true"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

  - platform: history_stats
    name: Sump Runtime Week
    entity_id: sensor.sump_running
    state: "true"
    type: time
    start: "{{ as_timestamp( now().replace(hour=0, minute=0, second=0, microsecond=0) ) - now().weekday() * 86400 }}"
    end: "{{ now() }}"

And a note of warning :warning:. I recently had a flood because I managed to hit a button that shut off all the switches in the house. Including the smart switch monitoring the sump. I added an automation to turn on the switch (with delay) if it gets turned off.

Sorry about the flood! This is why I’ve built my controls with an HA integrated relay (Shelly pro in my case) in parallel with dumb sensors and relays, both driving the same contactor. I can monitor everything and manually start a pump but I can’t stop the pump from running if there’s water (I can kill the circuit remotely if, for example, I have a locked rotor). I don’t want to depend on home automation or have it be able to shut things down. Especially given the rather limited security model in HA.

I don’t rely on HA to manage the sump action - it is fully self-contained - except for the monitor. Thanks

Would you mind sharing your power consumption recorded over an hour of heavy rain, since you log the current by the sound of your post? I’m trying to size a battery backup for my sump pump and by your mention of 9 amps running, it is likely a 1/2 hp pump like the one i installed. Your capture of the duty cycle along with both idle and running current would paint a very accurate picture of how much power to expect per hour of peak usage, and allow a more certain sizing of battery backup knowing how long it would run from your logs. Thanks in advance if you are able to share. I’m really just after your maximum wattage recorded in an hour. Thanks.