Keeping Water Cooler Off When Empty?

I am looking for some help with some SmartApps. I have a water cooler that i use Smart Lights to turn it on when everyone arrives. I also use It to turn it off during the day when everyone leaves. I also have a third instance that turns it off during the night.

The problem i have is when it is empty, it sometimes takes me a couple days to refile it. I am wondering if someone could help me with some SmartApps that would allow me to disable these apps from running.

I was thinking of having a virtual switch that when on would allow these apps to send the commands and when off the commands would not be sent. I discussed this with Tech support and they suggested i turn to the community for help with this.

I would probably use a virtual presence sensor named “Water” that had both switch capability and presence capability so you could toggle it on and off. Toggle when there’s no water which makes it “away.” Then only run the routines when “water” is present.

That way you don’t have to change any of your other modes or anything.

But there may be a more elegant way to do it, hopefully some of the master coders will have suggestions.

Thanks for the reply @JDRoberts. I don’t think that will work for my case because I use presence sensor to turn on the water cooler when someone arrives home. That is why I was thinking a virtual switch would work better.

Eg.
If switch “water cooler full” is on then turn on this switch. Not sure if the Smart Lights SmartApp can be edited to add an if command.

The point is that you can have your routine/Smartapp Check to see that multiple “people” are home. And you can use a virtual presence sensor which isn’t an actual device at all, it’s just a device type that the system will treat like a real device. So you can toggle the “water presence” on or off whenever you want. It’s not dependent on anyone actually being home. You could make it dependent on a moisture sensor. So it becomes an and condition to all your other condition. All of this is true ( including however you set your other real present sensors and your modes) and “Water presence sensor” is turned on.

Just one possibility using the existing rule structures. :sunglasses: I’m sure there are many other ways to do it.

As you note, smart lights itself doesn’t have that nested if. But it does have an and for presence.

Ok I have created a virtual presence sensor and a virtual Switch for trying this out. Unfortunately I am not following how I can use this in the Smart Lights SmartApp. This is a screen shot of what I have now for water cooler.

I am also using th goodbye routine to turn it off when everyone leaves.

Sorry just having a hard time figuring this out. @bravenel maybe you can weigh in on this (thanks in advance).

Your simulated presence sensor for " water" would need to show up in the list of presence sensors to make this work. So that would be the first thing to look at.

I think you have to start with the device type of virtual presence sensor and then add the capability.switch to it.

@tgauchat or one of the other coding grandmasters would know. I think @luna might have done something similar for a different use case. I know @joshua_lyon has written about using them before.

Virtual Presence Device - Control from SmartPhone

Sorry I can’t help more, I’m not able to actually read the groovy code because I depend on text to speech.

1 Like

And just to be sure, this is my thought of the logic flow:

A) you do A one time set up where you create a virtual presence sensor which also has the capability switch. For now I will call this “water” as in water is “present” or not.

Normal run logic:

One) something, either a physical monitoring device like a SmartThings-compatible moisture sensor, or a text notification to IFTTT from the cooler if it has that capability, or even a person manually checking the cooler, toggles the switch on the “water” present sensor to say no water is present in the cooler.

Two) the routines that would normally run the water cooler when you got home check for the presence of “water” and if water is not also “home” the routine doesn’t run.

This might require setting up a separate routine for each of your family members that includes that family member plus water being present. So that if there was water it would run for any person who came home, not wait for the entire family. But that just depends on how you want it to actually work.

  1. once the cooler is refilled with the water, the same indicator process from step one is done in reverse. Something flips the switch to say water is now “home”. That could be a moisture sensor, it could be an indicator from the cooler itself if it can send a text, or it could be just a person toggling The “water” presence through the SmartThings mobile app. (This is why also needs to switch capability. So it can be toggled on and off.)

So it looks to me like the screenshot that you’re showing would be a first take for step two. You’ll still need something to do step one and three. But like I said, that could just be a manual toggle.

Anyway, that was just my first thought, other people might have a much better ideas.

What you are saying makes sense now. I will toggle the presence of water manually.

The problem lies when i set up the separate routines. In everything i have seen it is when “someone arrives” not when “everyone arrives”. I have tried the Smart Lights SmartApp and i have also tried setting up a new routine.

Edit: Just chatted with Tech support and they are not aware of a SmartApp that will do Everyone present.

Ok, my bad.

It think it could be done with a separate step, but it’s getting kludgy, I hope one of the coder gurus will chime in soon.

I’m sure there’s a better way to do this. @MichaelS does some creative stuff. Also @baldeagle072. Maybe they can think of something.

Meanwhile, take a look at @joec 's simple rule builder. Third party rules engine for SmartThings, very popular. I think it could do this because it has more of a “while” construct. Runs in any browser.

https://www.simplerulebuilder.com/about/

I just glanced at this thread so I am not sure I have all of the history, but it sounds like some custom app might need to be developed to do what you are looking for, specifically, the “Everyone Present” tag
that requires a creative bit of programming that is a few more lines then just checking when one person in a group arrives.

I have a Smart Water Heater app that does something similar to what you want, but it also uses the ‘anyone present’ tag. Tell you what
try it out (below) and see what might need to be changed in wording and coding and I will see if I can create a specific version for your use case.

2 Likes

@MichaelS

We were just kicking around the idea of using a virtual presence sensor to represent the water cooler being full or empty.

The use case is pretty simple. There’s a “somebody arrived” routine that starts the water cooler. But OP doesn’t want it to start if he cooler is empty. That’s going to be a manual check and toggle of some indicator in the smart things app, not a sensor check.

So the question is what can be done to keep the usual “somebody arrived” routine from turning on the water cooler when the water is empty.

The use case details are in post 1. Everything else is just my attempt to MacGyver a solution without code until some actual coders showed up . :sunglasses:

So I thought maybe we could use a virtual presence sensor for “water” to indicate that the tank has water or doesn’t. But then that would need to be anded with the person being there.

We can throw out the whole idea of the “everybody’s present” use of present sensors if there’s a better way to do it with custom code and just a switch to indicate that the water cooler has water.

The use case need is to be able to toggle off running the water cooler part of the somebody’s home routine if it’s known that the water cooler is empty.

I think this will work for you. Try it out and tell me what you think.

/**
 *  Water Cooler
 *
 *  Copyright 2015 Eric Roberts
 *
 *  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: "Water Cooler",
    namespace: "baldeagle072",
    author: "Eric Roberts",
    description: "The cooler will turn on if everybody arrives home and the water cooler virtual switch is on. If the water cooler virtual switch turns off or everyone leaves, it will turn off the cooler.",
    category: "Convenience",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")


preferences {
	section("Water Cooler") {
		input "cooler", "capability.switch", title: "Water Cooler", multiple: false, required: true
        input "vCooler", "capability.switch", title: "Virtual Switch for cooler", multiple: false, required: true
	}
    
    section("People") {
    	input "presenceSensors", "capability.presenceSensor", title: "Presence Sensor(s)", multiple: true, required: true
    }
}

def installed() {
	log.debug "Installed with settings: ${settings}"

	initialize()
}

def updated() {
	log.debug "Updated with settings: ${settings}"

	unsubscribe()
	initialize()
}

def initialize() {
	subscribe(presenceSensors, "presence", "presenceHandler")
    subscribe(vCooler, "switch.on", "onHandler")
    subscribe(vCooler, "switch.off", "offHandler")
}

def presenceHandler(evt) {
	if (vCooler.currentSwitch == "on") {
    	if (getPresence()) {
        	cooler.on()
        } else {
        	cooler.off()
        }
    } else {
    	cooler.off()
    }
}

def onHandler(evt) {
	if (getPresence()) {
    	cooler.on()
    } else {
    	cooler.off()
    }
}

def offHandler(evt) {
	cooler.off()
}

def getPresence(){
	def presentCounter = 0
    
    presenceSensors.each {
    	if (it.currentValue("presence") == "present") {
        	presentCounter++
        }
    }
    
    if (presentCounter > 0) {
    	return true
    } else {
    	return false
    }
}
1 Like

Hey @MichaelS tried this code but not what i had in mind. Thanks for responding!!

Simplerulebuilder.com has potential!! The on problem is that it won’t give me times so it does’t execute at 2:30 am when i get home from work. The other issue I am having is it won’t list all my devices by name. Not sure why that is.

I think this is it!! i have set it up and will test it in a few hours when wife leaves and comes home again!! @baldeagle072 is there a lot of cone involved to adding “With Options” at the bottom like you see in the Smart Lights SmartApp so I can set time for it to only triggers from 6am to 1am when someone arrives. If you give me directions i might be able to try it (break it)!!

I’m not so great with using set times. If it would work to use modes, I could make that work


is there a way to see the code they use in the Smart Lights SmartApp? I have not been able to figure that out.

Ok I have been searching through some code and was able to copy and past some stuff into @baldeagle072 to get a bit closer. But still not working correctly. I have renamed it “Water Cooler Test”. Not sure if this is how we are supposed to do it in he community if not someone let me know and i will remove the following code.


/**

  • Water Cooler
  • Copyright 2015 Eric Roberts
  • 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: “Water Cooler Test”,
namespace: “baldeagle072”,
author: “Eric Roberts”,
description: “The cooler will turn on if everybody arrives home and the water cooler virtual switch is on. If the water cooler virtual switch turns off or everyone leaves, it will turn off the cooler.”,
category: “Convenience”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)

preferences {
section(“Water Cooler”) {
input “cooler”, “capability.switch”, title: “Water Cooler”, multiple: false, required: true
input “vCooler”, “capability.switch”, title: “Virtual Switch for cooler”, multiple: false, required: true
}

section("People") {
	input "presenceSensors", "capability.presenceSensor", title: "Presence Sensor(s)", multiple: true, required: true
}
section(title: "More options", hidden: hideOptionsSection(), hideable: true) {

		def timeLabel = timeIntervalLabel()

		href "timeIntervalInput", title: "Only during a certain time", description: timeLabel ?: "Tap to set", state: timeLabel ? "complete" : null

		input "days", "enum", title: "Only on certain days of the week", multiple: true, required: false,
			options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

		input "modes", "mode", title: "Only when mode is", multiple: true, required: false
	}

}

def installed() {
log.debug “Installed with settings: ${settings}”

initialize()

}

def updated() {
log.debug “Updated with settings: ${settings}”

unsubscribe()
initialize()

}

def initialize() {
subscribe(presenceSensors, “presence”, “presenceHandler”)
subscribe(vCooler, “switch.on”, “onHandler”)
subscribe(vCooler, “switch.off”, “offHandler”)
}

def presenceHandler(evt) {
if (vCooler.currentSwitch == “on”) {
if (getPresence()) {
cooler.on()
} else {
cooler.off()
}
} else {
cooler.off()
}
}

def onHandler(evt) {
if (getPresence()) {
cooler.on()
} else {
cooler.off()
}
}

def offHandler(evt) {
cooler.off()
}

def getPresence(){
def presentCounter = 0

presenceSensors.each {
	if (it.currentValue("presence") == "present") {
    	presentCounter++
    }
}

if (presentCounter > 0) {
	return true
} else {
	return false
}

}
private getAllOk() {
modeOk && daysOk && timeOk
}

private getModeOk() {
def result = !modes || modes.contains(location.mode)
log.trace "modeOk = $result"
result
}

private getDaysOk() {
def result = true
if (days) {
def df = new java.text.SimpleDateFormat(“EEEE”)
if (location.timeZone) {
df.setTimeZone(location.timeZone)
}
else {
df.setTimeZone(TimeZone.getTimeZone(“America/New_York”))
}
def day = df.format(new Date())
result = days.contains(day)
}
log.trace "daysOk = $result"
result
}

private getTimeOk() {
def result = true
if (starting && ending) {
def currTime = now()
def start = timeToday(starting).time
def stop = timeToday(ending).time
result = start < stop ? currTime >= start && currTime <= stop : currTime <= stop || currTime >= start
}
log.trace "timeOk = $result"
result
}

private hhmm(time, fmt = “h:mm a”)
{
def t = timeToday(time, location.timeZone)
def f = new java.text.SimpleDateFormat(fmt)
f.setTimeZone(location.timeZone ?: timeZone(time))
f.format(t)
}

private hideOptionsSection() {
(starting || ending || days || modes) ? false : true
}

private timeIntervalLabel() {
(starting && ending) ? hhmm(starting) + “-” + hhmm(ending, “h:mm a z”) : “”
}


If there are any coders out there that could have a look at this and fix it i would really appreciate it!! @MichaelS @slagle Or anyone else please feel free to join in.

Edit: Oh boy i really have this screwed up!! :frowning: