Attribute change in Tile

Hello there, I’m new here to Smartthings. I just read the documentation and now I want to make a Device Type Handler. Now I made a Device Handler with a GUI ( Tiles ) and on this GUI are two Buttons. One to increase the temperature and one to decrease. Now I made the functions ( tempup and tempdown ).

Now I got 2 Problems.

  1. I included the Thermostat capability. I can change the Values of own created attributes by sendEvent on the installed method and then this value is shown in the smartthings app. But I can’t change the value of attributes that are already defined by the capability. For Example: thermostatSetpoint. Do I have to initialize these attributes I need of a capability first or how can I use them?

  2. I can change the values of my own attributes on the installed method. But when I try to change the Value in another function like “tempup” or “tempdown”, the Value don’t change in the Smartthings app.

I hope you understand what I mean, otherwise just ask.

Hopefully someone can help me.

Code:


metadata {
	definition (name: "SmartThermostatDeviceHandler", namespace: "Dany Van der Meij", author: "Dany Van der Meij") {
		capability "thermostat"
        
        attribute "ThermostatSetpoint", "Number"
        attribute "ThermostatHumidity", "Number"
        attribute "ThermostatAirquality", "Number"
        
        command "tempUp"
        command "tempDown"
	}
	simulator {
		// TODO: define status and reply messages here
	}

	tiles (scale: 2) {
		multiAttributeTile(name:"thermostatFull", type:"thermostat", width:6, height:4) 
        {
    		tileAttribute("device.ThermostatSetpoint", key: "PRIMARY_CONTROL") {
        		attributeState("temp", label:'${currentValue}', unit:"dF", defaultState: true)
    		}
    		tileAttribute("device.ThermostatSetpoint", key: "VALUE_CONTROL") {
            	attributeState("VALUE_UP", action: "device.tempUp")
        		attributeState("VALUE_DOWN", action: "device.tempDown")
    		}
    		tileAttribute("device.ThermostatHumidity", key: "SECONDARY_CONTROL") {
       		 attributeState("humidity", label:'${currentValue}', unit:"%", defaultState: true)
    		}
    		tileAttribute("device.thermostatOperatingState", key: "OPERATING_STATE") {
        		attributeState("idle", backgroundColor:"#00A0DC")
        		attributeState("heating", backgroundColor:"#e86d13")
        		attributeState("cooling", backgroundColor:"#00A0DC")
    		}
    		tileAttribute("device.thermostatMode", key: "THERMOSTAT_MODE") {
        		attributeState("off", label:'${name}')
        		attributeState("heat", label:'${name}')
       	 		attributeState("cool", label:'${name}')
        		attributeState("auto", label:'${name}')
    		}

		}
        
        standardTile('temperatureTile', 'device.ThermostatSetpoint', defaultState: true, width: 2, height: 2, backgroundColor: "#e86d13")
        {
        	state "ThermostatSetpoint", label: '${currentValue}'
        }
		standardTile('humidityTile', 'device.ThermostatHumidity', defaultState: true, width: 2, height: 2)
        {
        	state "ThermostatHumidity", label: '${currentValue}'
        }
        standardTile('airqualityTile', 'device.ThermostatAirquality', defaultState: true, width: 2, height: 2)
        {
        	state "ThermostatAirquality", label: '${currentValue}'
        }
        standardTile('thermostatmodeTile', 'device.thermostatSetpoint', defaultState: true, width: 2, height: 2)
        {
        	state "thermostatSetpoint", label: '${currentValue}'
        }
        standardTile("refresh", "command.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) 
        {
            state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
        }    
        
        main('thermostatFull')
        
        details('thermostatFull','temperatureTile', 'humidityTile', 'airqualityTile', 'thermostatmodeTile', 'refresh')
        
	}
}


def installed()
{
	log.debug "Installed"
    sendEvent(name: "ThermostatSetpoint", value: 20)
    sendEvent(name:"ThermostatHumidity", value: 41)
    sendEvent(name: "ThermostatAirquality", value: 400)
    sendEvent(name: "thermostatSetpoint", value: 42)
	initialize()
}

def tempUp()
{
	log.debug "Tempup()"
    sendEvent(name: "ThermostatSetpoint", value: 30)
}

def tempDown()
{
	log.debug "Tempdown()"
    sendEvent(name: "ThermostatSetpoint", value: 40)
}

def initialize()
{
	log.debug "Initialize"
}

def poll()
{
	log.debug "Executing poll"
}

def updated()
{
	log.debug "updated()"
}


// parse events into attributes
def parse(Map description) {
	
}



/************** Betriebsfunktionen **************/
def auto()
{
	log.debug "auto()"
    
}

def cool()
{
	log.debug "cool()"
}

def emergencyHeat()
{
	log.debug "emergencyHeat()"
}

def fanAuto()
{
	log.debug "fanAuto()"
}

def fanCirculate()
{
	log.debug "fanCirculate()"
}

def fanOn()
{
	log.debug "fanOn()"
}

def heat()
{
	log.debug "heat()"
    def temp = device.currentState("ThermostatSetpoint").value;
    log.debug "Temp: ${temp}"
    setThermostatSetpoint(temp)
}

def off()
{
	log.debug "off()"
}


/************** Setter Methods **************/



def setCoolingSetpoint(Number setpoint)
{
	log.debug "setCoolingSetpoint()"
    setThermostatSetpoint(setpoint)
}

def setHeatingSetpoint(Number setpoint)
{
	log.debug "setHeatingSetpoint()"
    setThermostatSetpoint(setpoint)
}

def setThermostatFanMode(Enum fanmode)
{
	log.debug "setThermostatFanMode()"
}

def setThermostatMode(Enum mode)
{
	log.debug "setThermostatMode()"
}


def setThermostatSetpoint (Number setpoint)
{
	log.debug "setThermostatSetpoint()"
    sendEvent(name: "ThermostatSetpoint", value: setpoint)
    log.debug "Heating Sepoint: ${setpoint} new Setpoint: ${device.currentState("ThermostatSetpoint").value}"
}

First of all… Please learn to properly share code in the Forum using Markdown.

  • Either link to a GitHub Repo or a Gist.

  • Or surround your code with three back quotes:

def method() {
   do stuff
}

That was done like this:
image

Thanks!
…Terry.

2 Likes

Hello, thanks, I did it. Now, can you help me with my other problems?

I would be very grateful

angry_101_dalmations

Next: Throughout your code… Capitalization MATTERS.

Attribute names do not have initial caps.
Use exactly the capitalization shown here: http://docs.smartthings.com/en/latest/capabilities-reference.html#thermostat


My general advice?

Please start with a much simpler DTH to experiment with … like a Virtual Switch. Modify it’s code a bit at a time until you break it, then go back and fix it, repeat.

Do not start with a brand new complex DTH like a Thermostat.

But find a template example Thermostat and modify it.

This is not the attribute thermostatSetpoint from the capability. When you look into the code you see that I created this attribute by myself.

Ah! In that case, I would really recommend that you go even further and give the Attribute a much more unique name. SmartThings has a pre-processor and that could ignore case in some places! Even if not, the code is confusing.

Call it danThermoSetpoint or something really obvious!

I’m using my own attributes because when I try to use the attributes from the capability, the value shown in the Tiles is always 0. Even when I do:

sendEvent(name: "thermostatSetpoint", value: 42)

With my own Attributes it works, but not for the Capability Attributes.