Cassidy
Published © Beerware

SmartCoffee - Powered by SmartThings

SmartThings integrated coffee maker

BeginnerFull instructions provided4,990
SmartCoffee - Powered by SmartThings

Things used in this project

Hardware components

Mr. Coffee CG12 12-Cup Switch Coffeemaker
×1
PEQ Water Sensor
×1
Aeon Labs DSC06106-ZWUS - Z-Wave Smart Energy Switch
×1
Dap 00688 Household Waterproof Adhesive Sealant, 100% Silicone, 2.8-Ounce Tube
×1
Samsung SmartThings Hub
Samsung SmartThings Hub
×1

Story

Read more

Code

SmartCoffee SmartApp

Groovy
/**
 *  SmartCoffee
 *
 *  Copyright 2015 Cassidy Nelemans
 *
 *  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.
 *
 *
 *	For this SmartApp to work, a virtual On/Off switch has to first be created in the IDE. This virtual On/Off switch will be 
 *	used as a middle man to check on whether there is water in the coffee water reservoir before powering it on.
 *
 */



definition(
    name: "SmartCoffee",
    namespace: "smartthings",
    author: "Cassidy Nelemans",
    description: "Turns a coffee maker on based on whether there is water in the water reservoir. Notifies when coffee starts brewing and when it completes.",
    category: "My Apps",
    iconUrl: "http://i62.tinypic.com/2d7g09u.jpg",
    iconX2Url: "http://i62.tinypic.com/2d7g09u.jpg"
)


preferences {
	section("When this virtual switch is turned on..."){

		input "theSwitch", "capability.switch", title: "What virtual switch?", required: true, multiple: false
	}
	section("Check that this water sensor detects water...") {

		input "alarm", "capability.waterSensor", title: "Is there water in here?", required: true, multiple: false
	}
	section("Before turning on this coffee maker...") {

		input "coffee", "capability.switch", title: "What coffee maker?", required: true, multiple: false
	}
    section("(Optional) HAM Bridge integration", hideable: true, hidden: true) {
		input "HAMBcommand", "text", title: "Send this command to HAM Bridge when the coffee is done", required: false
		input "server", "text", title: "Server IP", description: "Your HAM Bridger Server IP", required: false
		input "port", "number", title: "Port", description: "Port Number", required: false
    }
}


def installed() {
	subscribe(theSwitch, "switch.On", onHandler)
    subscribe(alarm, "water.dry", waterDryHandler)
}


def updated() {

	unsubscribe()
	subscribe(theSwitch, "switch.On", onHandler)
    subscribe(alarm, "water.dry", waterDryHandler)
}

def onHandler(evt) {
	//Do these things when the virtual switch is turned on
    checkWater()
    }
    
	// Check the water sensor status
	def checkWater(evt) {
    	def latestValue = alarm.latestValue("water")
        def wetOrDry = latestValue
        
        
        if (wetOrDry == "wet") {
        	//Do these things if the virtual switch is turned on and the water tank is wet
        	log.debug "The tank is ${latestValue}. Turning on the coffee maker."
            	//Sending push notification
            log.debug "Sending push notification"
            sendPush("Your coffee is brewing...")
            	//Turning on the coffee maker
            log.debug "Turning on the coffee maker"
       		coffee.on()
        		}
        if (wetOrDry == "dry") {
        	//Do these things if the virtual switch is turned on and the water tank is dry
        	log.debug "The tank is ${latestValue}. Not turning on the coffee maker."
            	//Sending push notification...
            sendPush("There is no water in the SmartCoffee tank. Cancelling brew...")
            	//Turning off the virtual switch
            log.debug "Turning off the virtual switch"
        	theSwitch.off()
        	}
        }
        
        
    def waterDryHandler(evt) {
    	def switchValue = theSwitch.latestValue("switch")
        if (switchValue == "on") {
        //Do these things if the virtual switch is on and the water sensor switches from wet to dry
    		log.debug "The tank is now empty. Notifying that the coffee is done."
            	//Turning off the virtual switch
            theSwitch.off()
            	// Delay push notification
            log.debug "Pushing notification in ${secondsAfterClosed} seconds."
            sendPush()

    	}
    	if (switchValue == "off") {
        //Do these things if the virtual switch is off and the water sensor switches from wet to dry
        log.debug "The virtual switch is off. Doing nothing."
        	}
        }
        
 	def sendHttp() {
		def ip = "${settings.server}:${settings.port}"
		def deviceNetworkId = "1234"
sendHubCommand(new physicalgraph.device.HubAction("""GET /?${settings.HAMBcommand} HTTP/1.1\r\nHOST: $ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}"))
}
		
	def sendPush()	{
    		//Sending push notification
        log.debug "Sending push notification to for coffee being done"
    	sendPush("Your coffee is done!")
        	//Send command to HAM Bridge. Used for a voice notification
        log.debug "Sending HAM Bridge command - ${settings.HAMBcommand}"
        sendHttp()
        }

Credits

Cassidy
1 project • 2 followers
Contact

Comments

Please log in or sign up to comment.