Water Heater Mode Control

I have a smart connected water heater that is compatible with IFTTT but not ST. I have modified a garage door DTH that functions basically to change modes utilizing a couple webCore pistons, but I am having an issue with the toggle function in the DTH. It switches once but them hangs up until toggled twice.

This idea was borrowed from one of the ST gurus in here but I can’t remember who so I apologize and will give proper credit if the person claims it.

Here’s what I have so far:

metadata {
	definition (name: "Water Heater Mode Selector", namespace: "smartthings", author: "Reid Keith") {
		capability "Actuator"
		capability "Door Control"
    capability "Garage Door Control"
		capability "Refresh"
		capability "Sensor"
        
        command "eco"
        command "highdemand"
        command "vacation"
        command "hybrid"
	}

	simulator {
		
	}

	tiles {
		standardTile("toggle", "device.door", inactiveLabel: true, width: 3, height: 3) {
			state("closed", label:"ECO", action:"eco", icon:"st.Outdoor.outdoor2", backgroundColor:"#33FF57", nextState:"open")
			state("open", label:"High Demand", action:"highdemand", icon:"st.thermostat.heat", backgroundColor:"#FF0000", nextState:"closed")
			state("opening", label:"Vacation", action:"vacation", icon:"st.Weather.weather3", backgroundColor:"#00A8FF")
			state("closing", label:"Hybrid", action:"hybrid", icon:"st.tesla.tesla-hvac", backgroundColor:"#EDFF00")
			
		}
		standardTile("vacation", "device.door", inactiveLabel: false, decoration: "flat") {
			state "default", label:"Vacation", action:"vacation", icon:"st.Weather.weather3"
		}
		standardTile("hybrid", "device.door", inactiveLabel: false, decoration: "flat") {
			state "default", label:"Hybrid", action:"hybrid", icon:"st.tesla.tesla-hvac"
		}
        standardTile("highdemand", "device.door", inactiveLabel: false, decoration: "flat") {
			state "default", label:"High Demand", action:"highdemand", icon:"st.thermostat.heat"
		}
        standardTile("eco", "device.door", inactiveLabel: false, decoration: "flat") {
			state "default", label:"ECO", action:"eco", icon:"st.Outdoor.outdoor2"
		}

		main "toggle"
		details(["toggle", "eco", "highdemand", "hybrid", "vacation"])
	}
}

def parse(String description) {
	log.trace "parse($description)"
}


def eco() {
    sendEvent(name: "door", value: "closed")
}

def highdemand() {
    sendEvent(name: "door", value: "open")
}

def vacation() {
    sendEvent(name: "door", value: "opening")
}

def hybrid() {
    sendEvent(name: "door", value: "closing")
}

I want to be able to toggle from Eco to High Demand and back with the other 2 modes only selectable by directly pressing their buttons. Any help is greatly appreciated.

What do you want to happen when hybrid or vacation are on and then you tap them again to turn it off?

Hi @Sparks244, I took a stab at your code. Made some changes to use switch capabilities vs door (will save you headaches with IFTTT and Alexa and other apps), added comments, and cleaned up tiles a little.

Basically it toggles between ECO and High Demand, with Vacation and Hybrid just being on/off capabilities. Each has their own method so you can then easily execute code, or call from SmartApps if needed, as well as a couple new attributes/states that will show up in the IDE and are exposed to SmartApps. Does that help you any?

Here’s the code:.

metadata {
	definition (name: "Water Heater Mode Selector", namespace: "smartthings", author: "Reid Keith") {
		capability "Actuator"
		capability "Switch"
		capability "Refresh"
		capability "Sensor"
        
        attribute "vacationState", "string"
        attribute "hybridState", "string"
        
        command "eco"
        command "highdemand"
        command "vacation"
        command "hybrid"
	}

	tiles {
		standardTile("toggle", "device.switch", inactiveLabel: true, width: 3, height: 3) {
			state("off", label:"ECO", action:"highdemand", icon:"st.Outdoor.outdoor2", backgroundColor:"#33FF57")
			state("on", label:"High Demand", action:"eco", icon:"st.thermostat.heat", backgroundColor:"#FF0000")			
		}
		standardTile("vacation", "device.vacationState", inactiveLabel: false, decoration: "flat") {
			state("on", label:"Vacation On", action:"vacation", icon:"st.Weather.weather3")
            state("off", label:"Vacation Off", action:"vacation", icon:"st.Weather.weather3")
		}
		standardTile("hybrid", "device.hybridState", inactiveLabel: false, decoration: "flat") {
			state("on", label:"Hybrid On", action:"hybrid", icon:"st.tesla.tesla-hvac")
            state("off", label:"Hybrid Off", action:"hybrid", icon:"st.tesla.tesla-hvac")
		}

		main "toggle"
		details(["toggle", "hybrid", "vacation"])
	}
}

def parse(String description) {
	log.trace "parse($description)"
}


def eco() {
	log.debug "Tapped on High Demand to toggle back to ECO"
    sendEvent(name: "switch", value: "off")
}

def highdemand() {
	log.debug "Tapped on ECO to toggle back to High Demand"
    sendEvent(name: "switch", value: "on")
}

def vacation() {
    if (device.currentState("vacationState")?.value == "on") {
    	log.debug "Tapped on Vacation, so toggling from on to off"
		sendEvent(name: "vacationState", value: "off")
    } else {
    	log.debug "Tapped on Vacation, so toggling from off to on"
        sendEvent(name: "vacationState", value: "on")
    }
}

def hybrid() {
    if (device.currentState("hybridState")?.value == "on") {
    	log.debug "Tapped on Hybrid, so toggling from on to off"
		sendEvent(name: "hybridState", value: "off")
    } else {
    	log.debug "Tapped on Hybrid, so toggling from off to on"
        sendEvent(name: "hybridState", value: "on")
    }
}

Some screenshots:

IDE device states:

Live logging:
image

Mobile app (button values changing the way they should):


Thanks @johnconstantelo. I haven’t installed this yet (busy evening) but will it turn off eco or high demand when hybrid is selected? How about if vacation is selected, will it turn off the other modes? I do appreciate the assistance, still learning…

No problem. I was wondering how you wanted to handle that scenario.

I can easily update the code for hybrid to turn off vacation, and the other way around. Right now since eco and high demand are a toggle (one or the other is on), both both can’t be off (that can easily be changed too)

If vacation or hybrid come on, what do you want the toggle for eco and high demand to do? Have one or the other on, or should the toggle include a 3rd option of all off?

I enjoy playing around with code the best I can, but I’m certainly not a coder like others in this community are. This is how I learned, so I like returning the favor so others can learn too.

Also, instead of copying the code back here, I added this to my repo for you so it’s easier for you to make a copy for yourself:

https://raw.githubusercontent.com/jsconstantelos/SmartThings/master/devicetypes/smartthings/water-heater-mode-selector.src/water-heater-mode-selector.groovy

EDIT: Oops, just reread your first post and saw “webCore pistons”. Since I changed this from door control to a switch with more attributes, you’ll need to tweak those pistons. Sorry about that!

Hi @Sparks244, last update for the night. Made a lot of changes to the DTH to see what you like or not. Mainly these:

  • Softened colors a little
  • When selecting Eco or High Demand, turn off Hybrid or Vacation
  • When turning on Vacation or Hybrid, turn off Eco/High Demand mode
  • When toggle in is Eco/High Off mode, or All Off, taping on the tile starts back up in Eco mode
  • Added an All Off tile, just in case you need it
  • Added a new standard tile called “toggleSmallView” used only for the Room View to properly show device state
  • Added a new attribute called “deviceSummary” to support the above feature, which is also very useful in SmartApps
  • Added additional logging

Also, just in case you didn’t know, this will look different in the new app. You’ll only see 1 tile for “switch”, and it won’t look the way you want until the new app support customization like this. The good news is that all the attribute data is still there for automations, etc.

https://raw.githubusercontent.com/jsconstantelos/SmartThings/master/devicetypes/smartthings/water-heater-mode-selector.src/water-heater-mode-selector.groovy

1 Like

Hi @johnconstantelo, I installed the latest version you have shared. It works good! Didn’t need the all off since the unit always needs to be in one mode or another. But other than that, it’s great!

I really appreciate the help. Hopefully I’ll learn enough to pay it forward someday.

1 Like

You bet! If you need any other help, just ask.

I went ahead and removed that for you and updated my github repo with the changes so you can see the before/after changes.

2 Likes