Sump Pump Monitor

I’ve got a Sonoff POW R2 hooked up to my sump pump to monitor cycles.
I’ve been tinkering a bit to get some monitoring set up, and am having a little trouble with the logic.
Ideally want to monitor three functions.

1 - If it stops cycling. It would be perfect if I could take the average cycle time over the last hour and use that as a value. For example, I’d like a message if it doesn’t cycle for twice the average cycle time.

2 - If the pumping time is longer than say 60 seconds, indicating an issue with the output line or float.

3 - If the Sonoff is offline due to network or loss of power, such as a breaker tripped.

For #2, I used a “Poll State” with an update interval of 60 seconds to send a message if the power consumption is greater than .1A. While this seems to work, I don’t think it is quite right. Ideally I’d need to start that 60 second timer when the sensor current goes over .1A.

I’m sure it can be done, I just need to get pushed in the right direction. Thanks for any input you may have.

1 Like

Replying to my own post…

I believe this is a working solution for #2, but won’t be able to test till later.

“state_changed” monitors whether there is current draw over .1A.
“If True” starts the 60 second timer.
“If False” passes a stop message to the timer before the message is sent.

I don’t have an answer; I just want to give your post a bump and add that I think it’s a great idea.

Right now I just use a History Graph card for my sump pumps. The regularity of the spikes (or lack thereof) gives me a quick visual indicator of the status. Obviously the next step would be to automate notifying me if things are out of the ordinary.

To me the real benefit of a system like HA is in monitoring all the possible trouble spots in my house. Avoiding one pump failure or burst pipe can justify a whole lot of money and effort spent on building out a HA system.

Sadly, I often see development on this sort of thing sidelined in favor of the more “fun” automations which, frankly, have far less tangible value to the homeowner.

1 Like

I got a chance to tackle #2 and #3, and only bench tested so far. #1 could work with something similar, but of course wouldn’t have any of the functionality to change the cycle time as things dry up.
The third on just checks that the Sonoff is switched on, as it should never be shut off.

@bwthor, I have two sump pumps, master and backup and I test the backup pump each week. The backup pump is about 3 inches higher than the master so it will only run if the master has an issue.

I monitor how long the pumps runs and compare to how long they ran two hours ago. If at the end of the hour it ran either twice as much or less than half as much, I send an alert.

If the pumps run for over 10 minutes straight, or the backup pump runs outside the test period, I also send an alert.

Most of the alarming and control is built in a PLC controller, but this is what it looks like in my HA GUI. I also installed two floats so I can tell if the pumps can’t keep up with the incoming water.

Hope this gives you some ideas.

So, about those “Last Hour” and “Two Hours Ago” values, how are you getting those?

I did run across a couple Node Red Nodes that solve part of my plan.
First is interval-length which simply outputs a time between state changes
Second is the Smooth function, which can output a mean value over the last number of values.
These two nodes will give me the average cycle time over the last X cycles. Now I just need to figure out how to take that value and use it to trigger a message. Back to Google I go…

I compute those values in my PLC. I would look at node red docs, there should be a similar method.

I looked at the HA history stats sensor but didn’t see how to have more than one stat sensor and didn’t see an easy way to specify a time period that was two hours ago. We would probably have to write an automation to push the data from this hour at the top of the hour. As I recall, that is how I did it in the PLC.

OK, I wasn’t sure if those were something I was missing. I think that interval length node will work perfectly.

I am about 98% new to Node Red, and I am not a programmer, so the deck is stacked against me. I do however feel that I’ll be able to figure this out when I get a good solid block of time to sit down and work out the logic and get a better understanding of using variables in NR.

Thanks!

So, I’ve made some more progress.
I seem to have the flow working monitoring an on/off state change for testing. When I install it, I will be monitoring the sensors amp draw, and triggering when it goes over a set threshold.

The big thing I’m hung up on is I need to start the timer after the “Off” state change, and compare it to the average cycle time.

I’m happy to take suggestions, but keep in mind I am NOT a programmer, so my logic is most likely overly complicated or just plain wrong!

[{"id":"c4aae7e8.6cbbe8","type":"tab","label":"NP Stopped Pumping","disabled":false,"info":""},{"id":"97767677.8e3788","type":"server-state-changed","z":"c4aae7e8.6cbbe8","d":true,"name":"< .1 Amp","server":"303f7d80.f295e2","version":1,"entityidfilter":"sensor.north_pump","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":".1","halt_if_type":"num","halt_if_compare":"lt","outputs":2,"output_only_on_state_change":true,"x":80,"y":20,"wires":[["8ea11c5c.0029b"],[]]},{"id":"8ea11c5c.0029b","type":"interval-length","z":"c4aae7e8.6cbbe8","format":"mills","bytopic":false,"minimum":"","maximum":"","window":"","timeout":false,"msgTimeout":"","minimumunit":"msecs","maximumunit":"msecs","windowunit":"msecs","msgTimeoutUnit":"msecs","reset":false,"startup":false,"msgField":"payload","timestampField":"timestamp","repeatTimeout":false,"name":"","x":300,"y":40,"wires":[["9be034a5.d5a2a8","cd51e7cf.dbf958"],[]]},{"id":"cd51e7cf.dbf958","type":"smooth","z":"c4aae7e8.6cbbe8","name":"Average Cycles","property":"payload","action":"mean","count":"5","round":"1","mult":"single","reduce":false,"x":300,"y":160,"wires":[["f5703d34.af148"]]},{"id":"f5703d34.af148","type":"calculator","z":"c4aae7e8.6cbbe8","name":"Multiply x2","inputMsgField":"payload","outputMsgField":"payload","operation":"mult","constant":"2","x":110,"y":220,"wires":[["1e4edcfe.cbe083"]]},{"id":"1e4edcfe.cbe083","type":"function","z":"c4aae7e8.6cbbe8","name":"Set avgcyclex2","func":"flow.set(\"avgcyclex2\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":220,"wires":[[]]},{"id":"f436b271.8966f","type":"inject","z":"c4aae7e8.6cbbe8","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":320,"wires":[["14acf0f7.a6853f","246a3118.b5f7be"]]},{"id":"e5606790.ac6718","type":"switch","z":"c4aae7e8.6cbbe8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"avgcyclex2","vt":"flow"}],"checkall":"true","repair":false,"outputs":1,"x":450,"y":300,"wires":[["8ca60f6a.f2c58"]]},{"id":"14acf0f7.a6853f","type":"function","z":"c4aae7e8.6cbbe8","name":"Avg Cycle","func":"var avg = flow.get(\"avgcyclex2\");\nmsg.payload = avg;\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":340,"wires":[[]]},{"id":"9be034a5.d5a2a8","type":"function","z":"c4aae7e8.6cbbe8","name":"Set lastcycle","func":"flow.set(\"lastcycle\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":40,"wires":[[]]},{"id":"246a3118.b5f7be","type":"function","z":"c4aae7e8.6cbbe8","name":"Last Cycle","func":"var last = flow.get(\"lastcycle\");\nmsg.payload = last;\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":300,"wires":[["e5606790.ac6718"]]},{"id":"8ca60f6a.f2c58","type":"change","z":"c4aae7e8.6cbbe8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Pump Stopped Cycling","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":340,"wires":[["ef189d22.b8ba7"]]},{"id":"ef189d22.b8ba7","type":"debug","z":"c4aae7e8.6cbbe8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":720,"y":360,"wires":[]},{"id":"efea01d8.debb5","type":"server-state-changed","z":"c4aae7e8.6cbbe8","name":"NP Switch","server":"303f7d80.f295e2","version":1,"entityidfilter":"switch.north_pump_switch","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":80,"y":60,"wires":[["8ea11c5c.0029b"],[]]},{"id":"303f7d80.f295e2","type":"server","z":"","name":"Home Assistant"}]

I think I have it all working just like I’d hoped. Obviously still some testing to do, but so far, all good!

Have a look and let me know what you think. I’m open to any suggestions!

1 - Pump Stopped Cycling

[{"id":"8ea11c5c.0029b","type":"interval-length","z":"c4aae7e8.6cbbe8","format":"mills","bytopic":false,"minimum":"","maximum":"","window":"","timeout":false,"msgTimeout":"","minimumunit":"msecs","maximumunit":"msecs","windowunit":"msecs","msgTimeoutUnit":"msecs","reset":false,"startup":false,"msgField":"payload","timestampField":"timestamp","repeatTimeout":false,"name":"Off to Off interval","x":310,"y":160,"wires":[["e1100796.718d78"],[]]},{"id":"cd51e7cf.dbf958","type":"smooth","z":"c4aae7e8.6cbbe8","name":"Average Cycles","property":"payload","action":"mean","count":"5","round":"1","mult":"single","reduce":false,"x":360,"y":220,"wires":[["f5703d34.af148"]]},{"id":"f5703d34.af148","type":"calculator","z":"c4aae7e8.6cbbe8","name":"Multiply x2","inputMsgField":"payload","outputMsgField":"payload","operation":"mult","constant":"2","x":550,"y":220,"wires":[["1e4edcfe.cbe083"]]},{"id":"1e4edcfe.cbe083","type":"function","z":"c4aae7e8.6cbbe8","name":"Set avgcyclex2","func":"flow.set(\"avgcyclex2\", msg.payload);\nreturn msg;","outputs":0,"noerr":0,"x":740,"y":220,"wires":[]},{"id":"efea01d8.debb5","type":"server-state-changed","z":"c4aae7e8.6cbbe8","name":"NP Amp Draw","server":"303f7d80.f295e2","version":1,"entityidfilter":"sensor.north_pump","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"0","halt_if_type":"num","halt_if_compare":"is_not","outputs":2,"output_only_on_state_change":true,"x":90,"y":120,"wires":[["227a44a8.2d818c"],["60c3fc76.cdf884","8ea11c5c.0029b"]]},{"id":"7fe6879b.1d5a68","type":"function","z":"c4aae7e8.6cbbe8","name":"Avg Cycle Timer X2","func":"{var timeouttime = flow.get('avgcyclex2');\nmsg.timeout = timeouttime;\nreturn msg;}","outputs":1,"noerr":0,"x":470,"y":100,"wires":[["e5760d6.5799ff"]]},{"id":"e5760d6.5799ff","type":"mytimeout","z":"c4aae7e8.6cbbe8","name":"","outtopic":"","outsafe":"","outwarning":"Warning","outunsafe":"off","warning":"1","timer":"1","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":490,"y":40,"wires":[["1c9ecf92.b849b"],[]]},{"id":"e1100796.718d78","type":"calculator","z":"c4aae7e8.6cbbe8","name":"ms to sec","inputMsgField":"payload","outputMsgField":"payload","operation":"div","constant":"1000","x":540,"y":160,"wires":[["cd51e7cf.dbf958"]]},{"id":"60c3fc76.cdf884","type":"trigger","z":"c4aae7e8.6cbbe8","op1":"","op2":"avgcyclex2","op1type":"nul","op2type":"flow","duration":"250","extend":false,"units":"ms","reset":"","bytopic":"all","name":"Delay","x":290,"y":100,"wires":[["7fe6879b.1d5a68"]]},{"id":"227a44a8.2d818c","type":"change","z":"c4aae7e8.6cbbe8","name":"Pass \"stop\"","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":40,"wires":[["e5760d6.5799ff"]]},{"id":"1c9ecf92.b849b","type":"switch","z":"c4aae7e8.6cbbe8","name":"Only Pass \"off\"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":700,"y":40,"wires":[["b9ba0022.69271"]]},{"id":"b9ba0022.69271","type":"debug","z":"c4aae7e8.6cbbe8","name":"Send Telegram Message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":780,"y":100,"wires":[]},{"id":"303f7d80.f295e2","type":"server","z":"","name":"Home Assistant"}]

2 - Pumping longer than 60 seconds (I could use above code to create a sliding timer for this, but prefer a simpler solution).

[{"id":"be7114bd.76c338","type":"tab","label":"NP_Running Too Long","disabled":false,"info":""},{"id":"7e575bd0.f0c304","type":"api-call-service","z":"be7114bd.76c338","name":"Pump Running Too Long","server":"303f7d80.f295e2","version":1,"debugenabled":false,"service_domain":"telegram_bot","service":"send_message","entityId":"disable_notification=false","data":"{\"message\":\"North Pump running longer than 60 seconds\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":490,"y":120,"wires":[[]]},{"id":"1942c7cd.dfc758","type":"stoptimer","z":"be7114bd.76c338","duration":"60","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":290,"y":60,"wires":[["7e575bd0.f0c304"],[]]},{"id":"ff892da7.516d5","type":"server-state-changed","z":"be7114bd.76c338","name":"NP State","server":"303f7d80.f295e2","version":1,"entityidfilter":"sensor.north_pump","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":".1","halt_if_type":"num","halt_if_compare":"gt","outputs":2,"output_only_on_state_change":true,"x":60,"y":80,"wires":[["1942c7cd.dfc758"],["aa28f211.f7e7d"]]},{"id":"aa28f211.f7e7d","type":"change","z":"be7114bd.76c338","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":140,"wires":[["1942c7cd.dfc758"]]},{"id":"303f7d80.f295e2","type":"server","z":"","name":"Home Assistant"}]

3 - Sonoff Switched Off:

[{"id":"13907665.3c8e5a","type":"tab","label":"NP_Sonoff State","disabled":false,"info":""},{"id":"cb26cd45.7476a","type":"stoptimer","z":"13907665.3c8e5a","duration":"60","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":330,"y":60,"wires":[["c4a6662e.74e088"],[]]},{"id":"7fd66ad6.c111b4","type":"change","z":"13907665.3c8e5a","name":"Switch On, Stop Timer","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":160,"y":120,"wires":[["cb26cd45.7476a"]]},{"id":"c4a6662e.74e088","type":"api-call-service","z":"13907665.3c8e5a","name":"Telegram NP Off","server":"303f7d80.f295e2","version":1,"debugenabled":false,"service_domain":"telegram_bot","service":"send_message","entityId":"disable_notification=false","data":"{\"message\":\"North Pump Switch Off\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":520,"y":60,"wires":[[]]},{"id":"e4ba18f3.ba7028","type":"server-state-changed","z":"13907665.3c8e5a","name":"NP Switch State","server":"303f7d80.f295e2","version":1,"entityidfilter":"switch.north_pump_switch","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":80,"y":40,"wires":[["cb26cd45.7476a"],["7fd66ad6.c111b4"]]},{"id":"303f7d80.f295e2","type":"server","z":"","name":"Home Assistant"}]

3b - Sonoff network Down:

[{"id":"4016cd65.074404","type":"tab","label":"NP_Sonoff Network","disabled":false,"info":""},{"id":"55d1e40a.e7d7ec","type":"ping","z":"4016cd65.074404","name":"Ping North Pump Sonoff","host":"` [ `192.168.0.96` ](https://192.168.0.96/) `","timer":"5","x":110,"y":40,"wires":[["88bb251.b7777d8"]],"outputLabels":["false"]},{"id":"88bb251.b7777d8","type":"switch","z":"4016cd65.074404","name":"Ping State","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":190,"y":100,"wires":[["693f5c69.f26ec4"],["9dd60157.af88e"]]},{"id":"9dd60157.af88e","type":"change","z":"4016cd65.074404","name":"Ping UP --> STOP","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":160,"wires":[["693f5c69.f26ec4"]]},{"id":"9c845ff5.f80e8","type":"api-call-service","z":"4016cd65.074404","name":"","server":"303f7d80.f295e2","version":1,"debugenabled":false,"service_domain":"telegram_bot","service":"send_message","entityId":"disable_notification=false","data":"{\"message\":\"North Pump Sonoff Down\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":600,"y":140,"wires":[[]]},{"id":"693f5c69.f26ec4","type":"stoptimer","z":"4016cd65.074404","duration":"60","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":450,"y":80,"wires":[["9c845ff5.f80e8"],[]]},{"id":"303f7d80.f295e2","type":"server","z":"","name":"Home Assistant"}]
1 Like

Did you ever manage to get this working? I would love you latest yaml or automation if you did.