The Laundry Has Finished

smartapp_alerts

(Andy - United Kingdom) #1

As a follow on from this thread…

I have been asked to share the code for my little app that I use to detect when an appliance (washer or dryer) has finished.

Essentially what this code does, is take readings from an energy monitor (smartplug or similar) to check if it is below a configurable level and stays that way for a configurable number of minutes (i.e. the wash cycle has finished)
If this is ‘true’ then it turns on a momentary switch. I then use this switch to get my system to ‘announce’ that the appliance has finished.

I have to say that this is probably the one app that has enhanced the WAF (Wife Approval Factor) in my house more than anything else :slight_smile:

I use this app to turn on a variable ‘momentary’ switch which fires a voice announcement from another basic app I wrote which it similar (but a bit more basic) to the excellent ‘Big Talker’


Laundry Notification?
A way to read the state of an LED
(Andy - United Kingdom) #2

The SmartApp code…

/**
 *  ****************  Appliance Finished - Switch  ****************
 *
 *  Design Usage:
 *  This was designed to let me know when the laundry was finished by detecting the power used by a smart socket
 *
 *
 *  Copyright 2017 Andrew Parker
 *  
 *  This SmartApp is free!
 *  Donations to support development efforts are accepted via: 
 *
 *  Paypal at: https://www.paypal.me/smartcobra
 *  
 *
 *  I'm very happy for you to use this app without a donation, but if you find it useful then it would be nice to get a 'shout out' on the forum! -  @Cobra
 *  Have an idea to make this app better?  - Please let me know :)
 *
 *  Website: http://securendpoint.com/smartthings
 *
 *-------------------------------------------------------------------------------------------------------------------
 *  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.
 *-------------------------------------------------------------------------------------------------------------------
 *
 *  If modifying this project, please keep the above header intact and add your comments/credits below - Thank you! -  @Cobra
 *
 *-------------------------------------------------------------------------------------------------------------------
 *
 *  Last Update: 07/09/2017
 *
 *  Changes:
 *
 * 
 *
 *
 *
 *  V1.0.0 - POC
 *
 */



definition(
    name: "Appliance Finished - Switch",
    namespace: "Cobra",
    author: "SmartThings",
    description: "Turn on a switch if energy goes below a defined level and stays that way for a set number of minutes (To get 'Big Talker' to announce when an appliance has finished)",
    category: "Green Living",
    iconUrl: "http://cdn.device-icons.smartthings.com/Appliances/appliances1-icn@2x.png",
    iconX2Url: "http://cdn.device-icons.smartthings.com/Appliances/appliances1-icn@2x.png",
    iconX3Url: "http://cdn.device-icons.smartthings.com/Appliances/appliances1-icn@2x.png"
)

preferences {
	section {
    paragraph "V1.0.0"
     paragraph image: "http://cdn.device-icons.smartthings.com/Appliances/appliances1-icn@2x.png", 
       	title: "Appliance Finished",
        required: false, 
    	"Turn on a switch if energy goes below a defined level and stays that way for a set number of minutes"
    
    
    
     	input(name: "enableswitch1", type: "capability.switch", title: "Enable/Disable app with this switch", required: false, multiple: false, description: null)
		input(name: "meter", type: "capability.powerMeter", title: "When This Power Meter...", required: true, multiple: false, description: null)
        input(name: "belowThreshold", type: "number", title: "Reports Below...", required: true, description: "in either watts or kw.")
        input(name: "delay1", type: "number", title: "And stays that way for...", required: true, description: "this number of minutes")
        input(name: "switch1", type: "capability.switch", title: "Turn this switch on", required: true, multiple: true, description: null)
       
}   
}

def installed() {
	initialize()
}

def updated() {
	unsubscribe()
	initialize()
}

def initialize() {
log.debug "Initialised with settings: ${settings}"
	subscribe(meter, "power", meterHandler)
   subscribe(switch1, "switch", switch1Handler)
   subscribe(enableswitch1, "switch", enableswitch1Handler)
   state.enablecurrS1 == 'on'
 }

def enableswitch1Handler(evt){
state.enablecurrS1 = evt.value
log.debug "$enableswitch1 is $state.enablecurrS1"
}

def switch1Handler(evt){
state.currS1 = evt.value
log.debug "$switch1 is $state.currS1"
}


def meterHandler(evt) {
    state.meterValue = evt.value as double
    def currTime = new Date()
    
		log.info "$meter shows $state.meterValue Watts - $currTime"
    if(state.enablecurrS1 == 'on'){
	checkNow()  
	}
    else if(state.enablecurrS1 == 'off'){
    log.info " App disabled by $enableswitch1 being off"
}
}

def checkNow(){

log.debug "checkNow -  Power is: $state.meterValue"
    state.belowValue = belowThreshold as int
    if (state.meterValue < state.belowValue) {
   def mydelay = 60 * delay1 as int
    log.debug "Checking again after delay: $delay1 minutes... Power is: $state.meterValue"
       runIn(mydelay, checkAgain)     
      }
  }

 

def checkAgain() {
   
     if (state.meterValue < state.belowValue) {
      log.debug "Checking again... Power is: $state.meterValue"
      log.info " switching $switch1 on"
		switch1.on()
			}
     else  if (state.meterValue > state.belowValue) {
     log.debug "checkAgain -  Power is: $state.meterValue so cannot run yet..."
	}	
}

As with all the apps I create (related to voice/speaking) the first section has an ‘enable/disable’ switch - I just use a generic virtual switch “Voice Announcements” so I can disable the app at any time. and make the house quiet
I’m sure there is probably a better way to do this but it works for me! :slight_smile:


(Andy - United Kingdom) #3

Just in case it’s useful for anyone, I modified a standard ‘Simulated Switch’ to automatically turn off after a configurable number of minutes.
This is the virtual switch (or the other one I wrote which works for seconds rather than minutes) I use for quite a few of my apps which involve speech.
I use it as a work around when I don’t want a switch repeatedly triggered in a short space of time.

To use… after installing, go into the switch and set the off time under the switch configuration.

The Virtual Switch code…

/**
 *  Copyright 2015 SmartThings
 *
 *  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.
 *
 *
 *  Modified to show different colours/text and auto switch off
 *
 *
 */
metadata {

    definition (name: "Custom Variable Switch - Minutes", namespace: "Cobra", author: "smartthings") {
		capability "Switch"
        capability "Relay Switch"
		capability "Sensor"
		capability "Actuator"

		command "onPhysical"
		command "offPhysical"
	}


preferences {
		
		
	
	
		section {
			input "delayNum", type: "number", title: "Minutes delay before 'Off'", description: ""
		}


		

 }


	tiles {
		standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
			state "off", label: 'OffMin',  icon: "st.switches.switch.off", backgroundColor: "#0808F9"
			state "on", label: 'OnMin',  icon: "st.switches.switch.on", backgroundColor: "#FF0416"
		}
		standardTile("on", "device.switch", decoration: "flat") {
			state "default", label: 'OnMin', action: "onPhysical", backgroundColor: "#ffffff"
		}
		standardTile("off", "device.switch", decoration: "flat") {
			state "default", label: 'OffMin', action: "offPhysical", backgroundColor: "#ffffff"
		}
        main "switch"
		details(["switch","on","off"])
	}
}

def parse(description) {
}

def on() {
def delay1 = delayNum as int
def delay2 = delay1 * 60
	log.debug "$version on()"
	sendEvent(name: "switch", value: "on")
    runIn(delay2, off,[overwrite: false])
}

def off() {
	log.debug "$version off()"
	sendEvent(name: "switch", value: "off")
}

def onPhysical() {
def delay1 = delayNum as int
def delay2 = delay1 * 60
	log.debug "$version onPhysical()"
	sendEvent(name: "switch", value: "on", type: "physical")
    runIn(delay2, offPhysical,[overwrite: false])
}

def offPhysical() {
	log.debug "$version offPhysical()"
	sendEvent(name: "switch", value: "off", type: "physical")
}

private getVersion() {
	"PUBLISHED"
}

def myDelay() {


}

(llcanada) #4

@Cobra thanks for sharing. I will use it over the weekend and let you know how it goes. Thanks so much.


(Andy - United Kingdom) #5

@llcanada
You are welcome.
I was actually looking at this a few days ago as I’m using a virtual switch to control the speech but that seems a bit complicated and ‘long winded’ :slight_smile:
I’m thinking about just adding the ability to the app so I can just get this one app to do everything…
i.e. instead of using a switch just get the app to ‘talk’.

I’ll probably look at this over the next few days as I get time :slight_smile:


(Andy - United Kingdom) #6

@llcanada
It took a while for me to get to this but… As promised… :slight_smile:

I have updated the app to include the voice section so other apps are not required.
This makes it self-contained - Now added GitHub integration too :slight_smile:


(Nick Snyder) #7

This is exactly what I have been looking for! Is it possible to add a push notification instead of a switch?


(Andy - United Kingdom) #8

@audiorazor
Do mean just a push when the laundry is finished?


(Nick Snyder) #9

Correct. I don’t want to turn on a switch. Just want a push notification
from SmartThings


(Andy - United Kingdom) #10

@audiorazor
I can probably do that.
I’ll have a look for you


(Andy - United Kingdom) #11

@audiorazor

Try this…

Please let me know how you get on.


(Nick Snyder) #12

Thank you so much! I will test it today.

Do I have to do anything to activate the app or it works automatically? That was the only part I was confused by.


(Andy - United Kingdom) #13

@audiorazor
you just need to install & publish it in the IDE then install it in the smartthings app on your mobile device


(Nick Snyder) #14

Thanks. I have lots of apps installed but I didn’t know if it needed to be
triggered.

I will let you know how it goes!


(Nick Snyder) #15

Works perfect.

Thank you for making that change!


#16

@Cobra Just what I was looking for! Works perfect! Thank you, thank you!


(Andy - United Kingdom) #17

You are welcome guys.


(Jay) #18

Hi

What speakers are people using to get the voice commands?


(Andy - United Kingdom) #19

Any wifi or dnla speakers will work
I’m using ‘Jam Rhythm’ speakers


(Jay) #20

I have a few Alexa speakers around the house, any chance they could work?