Moisture Sensor to trigger outlet? -Help needed

New to this, so I have not delved into programming yet. I’m also leaving for vacation in a few days, there is supposed to be lots of rain while we are gone and I’m in a bit of a rush to try and get it done. I’ll search through the apps to see if I can find something…but the organization of them stinks at the moment.

So how does the pump know to turn off? Do you need the moisture sensor to control that as well?

A few things on this little project - this is a back stairwell to the basement. The drain is clogged and we basically need someone to jackhammer out the bottom and redo it. I would prefer a different drain method altogether, so it is going to be expensive and we don’t have it in the budget yet to do it. I have a few small sandbags in front of the double-door, so I can stop some of the water from coming in unless it reaches a certain height.

The pump will be placed right next to the drain (lowest part of the bottom) and has it’s own sensor that activates when it hits 1/4 in of water.

I plan on putting the moisture sensor probes about that high above the ground near the door. When the pump brings the water back down below the sensor, it can then turn off the pump (maybe after a delay). This is a failsafe in case the pump sensor is not working correctly. I have already tested the sensor in the sink and as soon as I pull it from a cup of water, it says no detection.

It sounds like a lot for not a long time in use (maybe a few months). It is actually an experiment for me to really learn ST much better. Since I need to do it for a little while, it made sense to try this.

Have you thought about this carefully? If the pump’s float switch is not working, turning on the power to the outlet it’s plugged into won’t help. (c;

Or am I missing something?

Excellent point. I also have a pump that does not have a switch in it that will server as a backup. It is actually primary right now as I just got the sensor pump.

I guess this was more a test than anything else to understand the system. The problem I have here is that ST controls what you can and can’t do, even if it isn’t completely thought out. Case in point - a moisture sensor is a trigger device, just like a door sensor. All trigger devices should not only alert, but should also be allowed to have associated actions.

For example, a few years ago I happened to go down into the basement and noticed the water line coming from the street was leaking. If I had a zwave water valve, it could have been triggered and shutoff the water. In the case of ST, a moisture sensor would not have been able to do that natively out of the box.

So, you can see my point is that ALL trigger devices should have the ability to initiate actions without the need for a smartapp or new device type. I compare it to IFTTT or Zapier. Once the trigger occurs, I should basically be able to associate almost any notification or action with it as long as the action doesn’t need parameters to be passed from the trigger itself.

I kind of disagree that every aspect of every device should be auto discovered. That would be hugely inefficient. But I admit that currently, discovery of almost all things SmartThings has been a much bigger pain than should be. They need to fix this if they ever want to be in the Best Buys and Home Depots of the world.

For the record, if your new pump is one similar to those built by Rule for boat bilges, they are incredibly reliable. The switch is nothing more than a sealed cavity with two contacts at one end, and a drop of mercury in it. When water floats the cavity (it is mounted on a small hinged lever), it tilts up and the mercury moves to cover the two contacts, completing the circuit.

Back in my boating days, I have only seen these pumps fail for two reasons:

1.) the motor itself burned out (not likely to happen with a new pump)

2.) there was so much rust and silt in the water that it collected around the lever’s hinge, providing enough friction to keep it from moving

Number 2 above is easily solved by a fixing a finer filter around the water entry of the pump. Some fine screen, or wrap tight with chessecloth and put a rubber band around it.

If you have a neighbor that would be willing to check on things if they go awry, check out the floodAlert SmartApp in the samples section to get notified if your sensor detects water. If you really want to use the other pump as a back up with the sensor… here you go!

/**
 *  Dry the Wetspot
 *
 *  Copyright 2014 Scottin Pollock
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
definition(
    name: "Dry the Wetspot",
    namespace: "smartthings",
    author: "Scottin Pollock",
    description: "Turns switch on and off based on moisture sensor input.",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
)


preferences {
	section("When water is sensed...") {
		input "sensor", "capability.waterSensor", title: "Where?", required: true
	}
	section("Turn on a pump...") {
		input "pump", "capability.switch", title: "Which?", required: true
	}
}

def installed() {
	subscribe(sensor, "water.dry", waterHandler)
	subscribe(sensor, "water.wet", waterHandler)
}

def updated() {
	unsubscribe()
	subscribe(sensor, "water.dry", waterHandler)
	subscribe(sensor, "water.wet", waterHandler)
}

def waterHandler(evt) {
	log.debug "Pump says ${evt.value}"
	if (evt.value == "wet") {
		pump.on()
	} else if (evt.value == "dry") {
		pump.off()
	}
}

It might be inefficient, but it might be better for “the masses”. I’m not necessarily hung up on every aspect of a device. In this particular case, I’m looking at the type of device. It is a sensor. Sensors trigger other things to happen. ST has arbitrarily limited this sensor to only notify when it is triggered. I can see no reason to not also allow an associated action to be in the software by default. For example - trigger lights to flash, trigger a valve to close, trigger a garage door to open. (who knows, maybe it is a sink in the garage…I’m making crap up now, but you get the point)

Until the ST approved community smartapps are easy to browse, discover, compare, and load directly from the app, the “simplest user” should be used most of the time (though, not all) as a guidepost. I know that they have it now in the app, but the ecosystem needs to expand a bit more.

I got your point initially; mine was that providing every possible mapping parameter in the built in behavior would be very unwieldy. Some limitations need and should be made to best suit the average user.

I won’t argue the specific omissions as that is pretty subjective. But I’ll admit there are some that I feel should be expanded on (like having available offsets to sunrise/sunset values in actions), but then again that might just be me. And I’m with you that the moisture sensor defaults should include at least optional switches on addition to an alert.

In any event, I welcome the granularity to build it when the defaults don’t fit; something I’m used to doing having been involved in HA for some 30 years (nothing has ever been a perfect fit). Of course you can pay a VAR tens of thousands to get everything right for you, but back in the day when I was doing this thing professionally, it was rare to come across a client who could even define their needs initially.

1 Like

I have been using this app to trigger a sump pump in my back yard (which is in the process of being graded, etc, but until then…). It’s great!! I am wondering if you can show me how to revise the code to prevent the switch from turning on if it has been on in the last [five] minutes? I have tried but have not been successful; I guess I’m not a very good coder :smile: I would like to prevent the pump from turning on and off repeatedly in a short time frame.

Hmmm… I don’t have a moisture sensor so I am not sure how they behave. If we ignore a “wet” event because it is within the 5 minute delay, will another wet event be sent? Or will the sensor not send another event until the state is changed to “dry”?

Very good point. My moisture sensor would only provide one event per “wet”, so you’re right, that won’t work. Maybe a five minute delay AFTER each wet trigger? Of course then we’d have the same probem – an intervening “dry” would cause the switch never to turn off. I thought I’d seen something in the developer documentation about polling devices. The example was to see if everyone was gone from home, and then a ten minute delay to make sure everyone was gone, but perhaps that works because a motion sensor provides an event at every motion whereas the moisture sensor is only wet or dry. Is there a way to poll a device for status?

I don’t know that you would want to poll it, but you can check its status. How about something like:

Store last time pump turned off
If wet comes in in next 5 minutes, ignore it
after the 5 minutes check last state of sensor to see if wet, if so start pump

I think that would work!

Ok, I’ll try and take a shot at this next week.

Actually this was much simpler than I thought, and seems to work as intended:

/**
 *  Dry the Wetspot 2
 *
 *  Copyright 2014 Scottin Pollock
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
definition(
    name: "Dry the Wetspot",
    namespace: "soletc.com",
    author: "Scottin Pollock",
    description: "Turns switch on and off based on moisture sensor input.",
    category: "Safety & Security",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Developers/dry-the-wet-spot.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Developers/dry-the-wet-spot@2x.png"
)


preferences {
	section("When water is sensed...") {
		input "sensor", "capability.waterSensor", title: "Where?", required: true
	}
	section("Turn on a pump...") {
		input "pump", "capability.switch", title: "Which?", required: true
	}
    // new stuff
    section("Don't restart pump for at least...") {
		input "timeout", "number", title: "how many minutes. (optional)", required: false
	}
}
def installed() {
	subscribe(sensor, "water.dry", waterHandler)
	subscribe(sensor, "water.wet", waterHandler)
}

def updated() {
	unsubscribe()
	subscribe(sensor, "water.dry", waterHandler)
	subscribe(sensor, "water.wet", waterHandler)
}

def waterHandler(evt) {
	log.debug "Sensor says ${evt.value}"
	if (evt.value == "wet") {
		 if (state.delay != true) {
			pump.on()
          }
	} else if (evt.value == "dry") {
		pump.off()
        if (timeout) {
        	state.delay = true
            runIn(timeout*60, resetTimeout)
        }
    }
}

def resetTimeout() {
	state.delay = false
	log.debug "resetting timeout"
    def wetOrDry = checkWet()
    if (wetOrDry == "wet") {
       	pump.on()
        }
}

def checkWet(evt) {
	def latestValue = sensor.latestValue("water")
}
1 Like

I’ve been trying to accomplish a similar thing with timeouts, but for notifications. How can you make it so that notifications are only sent if something happens twice in a period of time.

Example
Store last time event happened
If event happens again in the next XX minutes, notify me
If XX minutes pass, don’t notify me if it happens at all. But for each event start the notification timer.

Appreciate any help over here ----- > App for Multi Acceleration
so as not to highjack.

Thank you so much! Perfect.

I am new to Smartthings and I wasn’t aware thati need to creat apps to run certain things. Obviously I should have informed myself better. However this forum seems to be a great support. I found this app and installed it. What I need though, is to turn the outlet off in case moisture is detected. In my case the dehumidifier would keep running even though the pump doesn’t work anymore. How can this be accomplished with the smart app above??

Scott,

Anyway to integrate this with a fortrezz wv-01? The hub picks it up however is there a way to program the moisture sensors to turn of the fortrezz main valve? I would assume its just coding to replace the pump relay with the fortrezz main valve relay.

Scott, I was referred to your post by smartthings support. I plan to install an electric solenoid valve to my main water supply. I would like to use a normally off valve so in case of a power failure the water would be shut-off (just to be safe). It looks like I can use your app, but need to reverse the pump.on and pump.off statements? When conditions are dry there will be power to the valve to keep water flowing, then when wet the power will be switched off allowing the valve to close. I am new to this so your help is very much appreciated.
Also is this the final version of the app?
Thanks

Good question:

  1. Ideally the Valve shows up as “capability.valve” instead of “capability.switch”.

  2. The actions to be taken are then wet → “close() or shut()”, dry → “open()”; with perhaps some extra logic to determine if it is safe to "open()" the valve arbitrarily.

  3. If the Valve is still reading as “capability.switch”, then I presume "off()" means Shut, and “on()” means Open.


For more detail than you care to read: