Why don't my tiles update?

Ok guys… Why don’t my tiles update? The debug messages all look proper but nothing updates???

/**
 *  WaterTempSensor
 *  Copyright 2018 John Intorcio
 **/

metadata {
  definition (name: "DualWaterTempSensor", namespace: "JIntorcio", author: "John Intorcio") {
    capability "Sensor"
    attribute "laketemp", "string"
    attribute "tubtemp", "string"
    attribute "lakebat", "string"
    attribute "tubbat", "string"
  }

  tiles(scale: 2) {
    valueTile("laketemp", "device.laketemp", width: 2, height: 2) {
      state("laketemp", label: '${currentValue}°') }
    valueTile("tubtemp", "device.tubtemp", width: 2, height: 2) {
      state("tubtemp", label: '${currentValue}°') }
    valueTile("lakebat", "device.lakebat", width: 2, height: 2) {
      state("lakebat", label: '${currentValue}%') }
    valueTile("tubbat", "device.tubbat", width: 2, height: 2) {
      state("tubbat", label: '${currentValue}%') }
  }
}

def parse(String desc) {
    def msg = zigbee.parse(desc)?.text
    log.debug "Parsed message: $msg"
    def name = ""
    def name2 = ""
    def value = "Null"
    def value2 = "Null"
        
    if (msg != "ping") {
       	//msg format is [index] hyphen [temp in F * 10] hyphen [battery level]
        //Example 0-760-98 means it's a Lake temperature of 76° and battery is at 98%
        //Split on hyphens
        String[] Msgparts = msg.split("-")
        log.debug "Msgparts: $Msgparts"
        //Msgaprts is an array like [0, 760, 98]
        
        //First value is the index: 0 --> Lake, 1 --> Hot Tub
        int Index = Msgparts[0].toInteger()
        
	    //Pick the attribute for the temperature Update
        if (Index == 0)
	      name = "laketemp"
	    else
          if (Index == 1)
	        name = "tubtemp"
	      else
	        name = null
          
        int IntVal = Msgparts[1].toInteger() // Convert to integer
        value = (String)(IntVal/10)          // Divide by 10 and turn back to string
                
        // Create the temperature event
    	def evt1 = createEvent(name: name, value: value)
   		log.debug "Temp event: ${evt1?.descriptionText}"
        
        //Pick the attribute for the battery Update
        if (Index == 0)
	      name2 = "lakebat"
	    else
          if (Index == 1)
	        name2 = "tubbat"
	      else
	        name2 = null
          
        value2 = Msgparts[2]
        
        // Create the battery event
    	def evt2 = createEvent(name: name2, value: value2)
   		log.debug "Battery event: ${evt2?.descriptionText}"
        }
    
    //Return two events
	return [evt1, evt2]
    }

I think it is a scope issue. You defined evt1 and evt2 inside the if statement, but return them outside of the scope of the if.

2 Likes

Definitely.

This is what happens when folks use sloppy languages like Groovy - though scope issues occur in other languages, strong typing and such puts the coder in a more meticulous mood.

3 Likes

Bingo. Dang - where are the compiler warnings when you need them? Thanks.

3 Likes