State not updating / refreshing?

Can someone help figure out why the attributes in this custom DTH aren’t refreshing every 15 minutes?

    metadata {
 	definition (name: "TWC Weather Device", namespace: "lnjustin", author: "Justin Leonard") {
 	capability "Configuration"
 	capability "Refresh"
    attribute "dayOfWeek","string"
    attribute "dayOrNight","string"
    attribute "precip1Hour","number"
    attribute "precip6Hour","number"
    attribute "precip24Hour","number"
    attribute "relativeHumidity","number"
    attribute "temperature","number"
    attribute "temperatureMax24Hour","number"
    attribute "temperatureMin24Hour","number"
    attribute "validTimeLocal","string"
    attribute "validTimeUtc","number"
    attribute "windSpeed","string"
    attribute "qpfToday","number"
    attribute "qpfTomorrow","number"
    attribute "temperatureMaxToday","number"
    attribute "temperatureMaxTomorrow","number"
    attribute "temperatureMinToday","number"
    attribute "temperatureMinTomorrow","number"
    attribute "precipChanceTodayDay","number"
    attribute "precipChanceTodayNight","number"
    attribute "precipChanceTomorrowDay","number"
    attribute "precipChanceTomorrowNight","number"
    attribute "relativeHumidityTodayDay","number"
    attribute "relativeHumidityTodayNight","number"
    attribute "relativeHumidityTomorrowDay","number"
    attribute "relativeHumidityTomorrowNight","number"
    attribute "windSpeedTodayDay","number"
    attribute "windSpeedTodayNight","number"
    attribute "windSpeedTomorrowDay","number"
    attribute "windSpeedTomorrowNight","number"
    
    command "sync"
     }

 }

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

def installed()
{
	LOG("TWC In installed")
    // clear existing state info
    state.clear()
    
    // update system info
    updated()
}

def refresh()
{
	LOG("TWC refresh")
   def twcConditions = [:]
    try {
    	twcConditions = getTwcConditions()
    } catch (e) {
    	LOG("Error getting TWC Conditions: ${e}",1,null,'error')
        return null
    }
    if (twcConditions) {

          sendEvent(name: "dayOfWeek", value: twcConditions.dayOfWeek)
    sendEvent(name: "dayOrNight", value: twcConditions.dayOrNight)
    sendEvent(name: "precip1Hour", value: twcConditions.precip1Hour)
    sendEvent(name: "precip6Hour", value: twcConditions.precip6Hour)
    sendEvent(name: "precip24Hour", value: twcConditions.precip24Hour)
    sendEvent(name: "relativeHumidity", value: twcConditions.relativeHumidity)
    sendEvent(name: "temperature", value: twcConditions.temperature)
    sendEvent(name: "temperatureMax24Hour", value: twcConditions.temperatureMax24Hour)
    sendEvent(name: "temperatureMin24Hour", value: twcConditions.temperatureMin24Hour)
  	sendEvent(name: "validTimeLocal", value: twcConditions.validTimeLocal)
    sendEvent(name: "validTimeUtc", value: twcConditions.validTimeUtc)
    sendEvent(name: "windSpeed", value: twcConditions.windSpeed)
    }
    
       def twcForecast = [:]
    try {
    	twcForecast = getTwcForecast()
    } catch (e) {
    	LOG("Error getting TWC Forecast: ${e}",1,null,'error')
        return null
    }
    if (twcForecast) {
    sendEvent(name: "qpfToday", value: twcForecast.qpf[0])
    sendEvent(name: "qpfTomorrow", value: twcForecast.qpf[1])
    sendEvent(name: "temperatureMaxToday", value: twcForecast.temperatureMax[0])
    sendEvent(name: "temperatureMaxTomorrow", value: twcForecast.temperatureMax[1])
    sendEvent(name: "temperatureMinToday", value: twcForecast.temperatureMin[0])
    sendEvent(name: "temperatureMinTomorrow", value: twcForecast.temperatureMin[1])
    sendEvent(name: "precipChanceTodayDay", value: twcForecast.daypart[0].precipChance[0])
    sendEvent(name: "precipChanceTodayNight", value: twcForecast.daypart[0].precipChance[1])
    sendEvent(name: "precipChanceTomorrowDay", value: twcForecast.daypart[0].precipChance[2])
    sendEvent(name: "precipChanceTomorrowNight", value: twcForecast.daypart[0].precipChance[3])
    sendEvent(name: "relativeHumidityTodayDay", value: twcForecast.daypart[0].relativeHumidity[0])
    sendEvent(name: "relativeHumidityTodayNight", value: twcForecast.daypart[0].relativeHumidity[1])
    sendEvent(name: "relativeHumidityTomorrowDay", value: twcForecast.daypart[0].relativeHumidity[2])
    sendEvent(name: "relativeHumidityTomorrowNight", value: twcForecast.daypart[0].relativeHumidity[3])
    sendEvent(name: "windSpeedTodayDay", value: twcForecast.daypart[0].windSpeed[0])
    sendEvent(name: "windSpeedTodayNight", value: twcForecast.daypart[0].windSpeed[1])
    sendEvent(name: "windSpeedTomorrowDay", value: twcForecast.daypart[0].windSpeed[2])
    sendEvent(name: "windSpeedTomorrowNight", value: twcForecast.daypart[0].windSpeed[3])
    }
    parent.sendDeviceEvent(device.deviceNetworkId, "refresh")
}

def updated()
{
	LOG("TWC updated")
    unschedule()
    runEvery15Minutes(refresh)
    runIn(2, refresh)
}

/*
	sync
*/
def sync()
{
	// The server will respond with updated status and details
	parent.syncDevice(device.deviceNetworkId, "omnipurpose")
	sendEvent([name: "version", value: "v${driverVersion.major}.${driverVersion.minor}.${driverVersion.build}"])
}
def getDriverVersion() {[platform: "Hubitat", major: 1, minor: 0, build: 0]}

What are your live logs showing for errors? I can see a few without running you code:

What does LOG do? There’s no method for it.

You don’t need the last line for Hubitat, This is SmartThings :wink:

Why are you doing a runEvery and then again a runIn()? You only need 1 for those.

I got your code to work with many changes. See below:

metadata {
 	definition (name: "My TWC Weather Device", namespace: "lnjustin", author: "Justin Leonard") {
 	capability "Configuration"
 	capability "Refresh"
    attribute "dayOfWeek","string"
    attribute "dayOrNight","string"
    attribute "precip1Hour","number"
    attribute "precip6Hour","number"
    attribute "precip24Hour","number"
    attribute "relativeHumidity","number"
    attribute "temperature","number"
    attribute "temperatureMax24Hour","number"
    attribute "temperatureMin24Hour","number"
    attribute "validTimeLocal","string"
    attribute "validTimeUtc","number"
    attribute "windSpeed","string"
    attribute "qpfToday","number"
    attribute "qpfTomorrow","number"
    attribute "temperatureMaxToday","number"
    attribute "temperatureMaxTomorrow","number"
    attribute "temperatureMinToday","number"
    attribute "temperatureMinTomorrow","number"
    attribute "precipChanceTodayDay","number"
    attribute "precipChanceTodayNight","number"
    attribute "precipChanceTomorrowDay","number"
    attribute "precipChanceTomorrowNight","number"
    attribute "relativeHumidityTodayDay","number"
    attribute "relativeHumidityTodayNight","number"
    attribute "relativeHumidityTomorrowDay","number"
    attribute "relativeHumidityTomorrowNight","number"
    attribute "windSpeedTodayDay","number"
    attribute "windSpeedTodayNight","number"
    attribute "windSpeedTomorrowDay","number"
    attribute "windSpeedTomorrowNight","number"
    
    command "sync"
     }

 }

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

def installed()
{
//	LOG("TWC In installed")
    // clear existing state info
    state.clear()
    
    // update system info
    updated()
}

def refresh()
{
//	LOG("TWC refresh")
   def twcConditions = [:]
    try {
    	twcConditions = getTwcConditions()
    } catch (e) {
    	LOG("Error getting TWC Conditions: ${e}",1,null,'error')
        return null
    }
    if (twcConditions) {
	log.debug "$twcConditions"
          sendEvent(name: "dayOfWeek", value: twcConditions.dayOfWeek)
    sendEvent(name: "dayOrNight", value: twcConditions.dayOrNight)
    sendEvent(name: "precip1Hour", value: twcConditions.precip1Hour)
    sendEvent(name: "precip6Hour", value: twcConditions.precip6Hour)
    sendEvent(name: "precip24Hour", value: twcConditions.precip24Hour)
    sendEvent(name: "relativeHumidity", value: twcConditions.relativeHumidity)
    sendEvent(name: "temperature", value: twcConditions.temperature)
    sendEvent(name: "temperatureMax24Hour", value: twcConditions.temperatureMax24Hour)
    sendEvent(name: "temperatureMin24Hour", value: twcConditions.temperatureMin24Hour)
  	sendEvent(name: "validTimeLocal", value: twcConditions.validTimeLocal)
    sendEvent(name: "validTimeUtc", value: twcConditions.validTimeUtc)
    sendEvent(name: "windSpeed", value: twcConditions.windSpeed)
    }
    
       def twcForecast = [:]
    try {
    	twcForecast = getTwcForecast()
    } catch (e) {
    	LOG("Error getting TWC Forecast: ${e}",1,null,'error')
        return null
    }
    if (twcForecast) {
    sendEvent(name: "qpfToday", value: twcForecast.qpf[0])
    sendEvent(name: "qpfTomorrow", value: twcForecast.qpf[1])
    sendEvent(name: "temperatureMaxToday", value: twcForecast.temperatureMax[0])
    sendEvent(name: "temperatureMaxTomorrow", value: twcForecast.temperatureMax[1])
    sendEvent(name: "temperatureMinToday", value: twcForecast.temperatureMin[0])
    sendEvent(name: "temperatureMinTomorrow", value: twcForecast.temperatureMin[1])
    sendEvent(name: "precipChanceTodayDay", value: twcForecast.daypart[0].precipChance[0])
    sendEvent(name: "precipChanceTodayNight", value: twcForecast.daypart[0].precipChance[1])
    sendEvent(name: "precipChanceTomorrowDay", value: twcForecast.daypart[0].precipChance[2])
    sendEvent(name: "precipChanceTomorrowNight", value: twcForecast.daypart[0].precipChance[3])
    sendEvent(name: "relativeHumidityTodayDay", value: twcForecast.daypart[0].relativeHumidity[0])
    sendEvent(name: "relativeHumidityTodayNight", value: twcForecast.daypart[0].relativeHumidity[1])
    sendEvent(name: "relativeHumidityTomorrowDay", value: twcForecast.daypart[0].relativeHumidity[2])
    sendEvent(name: "relativeHumidityTomorrowNight", value: twcForecast.daypart[0].relativeHumidity[3])
    sendEvent(name: "windSpeedTodayDay", value: twcForecast.daypart[0].windSpeed[0])
    sendEvent(name: "windSpeedTodayNight", value: twcForecast.daypart[0].windSpeed[1])
    sendEvent(name: "windSpeedTomorrowDay", value: twcForecast.daypart[0].windSpeed[2])
    sendEvent(name: "windSpeedTomorrowNight", value: twcForecast.daypart[0].windSpeed[3])
    }
//    parent.sendDeviceEvent(device.deviceNetworkId, "refresh")
}

def updated()
{
//	LOG("TWC updated")
    unschedule()
    runEvery15Minutes(refresh)
//    runIn(2, refresh)
}

/*
	sync
*/
//def sync()
//{
	// The server will respond with updated status and details
//	parent.syncDevice(device.deviceNetworkId, "omnipurpose")
//	sendEvent([name: "version", value: "v${driverVersion.major}.${driverVersion.minor}.${driverVersion.build}"])
//}
// def getDriverVersion() {[platform: "Hubitat", major: 1, minor: 0, build: 0]}

Results:

10:08:15 PM: debug [cloudCeiling:null, cloudCoverPhrase:Clear, dayOfWeek:Saturday, dayOrNight:N, expirationTimeUtc:1588472224, iconCode:31, iconCodeExtend:3100, obsQualifierCode:null, obsQualifierSeverity:null, precip1Hour:0.00, precip24Hour:0.00, precip6Hour:0.00, pressureAltimeter:30.09, pressureChange:0.01, pressureMeanSeaLevel:1018.9, pressureTendencyCode:1, pressureTendencyTrend:Rising, relativeHumidity:85, snow1Hour:0.0, snow24Hour:0.0, snow6Hour:0.0, sunriseTimeLocal:2020-05-02T06:19:39-0400, sunriseTimeUtc:1588414779, sunsetTimeLocal:2020-05-02T20:01:21-0400, sunsetTimeUtc:1588464081, temperature:58, temperatureChange24Hour:3, temperatureDewPoint:54, temperatureFeelsLike:58, temperatureHeatIndex:58, temperatureMax24Hour:75, temperatureMaxSince7Am:75, temperatureMin24Hour:47, temperatureWindChill:58, uvDescription:Low, uvIndex:0, validTimeLocal:2020-05-02T22:07:04-0400, validTimeUtc:1588471624, visibility:10.000, windDirection:10, windDirectionCardinal:N, windGust:null, windSpeed:1, wxPhraseLong:Clear, wxPhraseMedium:Clear, wxPhraseShort:Clear]

Did you get this to work in terms of updating every 15 minutes? I copied your code but it is still not updating?

Hi Justin,

I avoid using refresh and other ST standard commands within schedules as a best practice. I cleaned up your code and added a new method for getting TWC data. I tested it with getting it every 5 minutes, and it’s been working fine. I also ran it for every 15 minutes, and that worked too.

EDIT: over the last few days ST has had some odd scheduling issues. Myself and a few others have an active support ticket with ST to try and figure out what’s going on.

Here’s your code with running it every 15 minutes. Watch your live logs and the device’s event logs:

metadata {
 	definition (name: "My TWC Weather Device", namespace: "lnjustin", author: "Justin Leonard") {
 	capability "Configuration"
 	capability "Refresh"
    attribute "dayOfWeek","string"
    attribute "dayOrNight","string"
    attribute "precip1Hour","number"
    attribute "precip6Hour","number"
    attribute "precip24Hour","number"
    attribute "relativeHumidity","number"
    attribute "temperature","number"
    attribute "temperatureMax24Hour","number"
    attribute "temperatureMin24Hour","number"
    attribute "validTimeLocal","string"
    attribute "validTimeUtc","number"
    attribute "windSpeed","string"
    attribute "qpfToday","number"
    attribute "qpfTomorrow","number"
    attribute "temperatureMaxToday","number"
    attribute "temperatureMaxTomorrow","number"
    attribute "temperatureMinToday","number"
    attribute "temperatureMinTomorrow","number"
    attribute "precipChanceTodayDay","number"
    attribute "precipChanceTodayNight","number"
    attribute "precipChanceTomorrowDay","number"
    attribute "precipChanceTomorrowNight","number"
    attribute "relativeHumidityTodayDay","number"
    attribute "relativeHumidityTodayNight","number"
    attribute "relativeHumidityTomorrowDay","number"
    attribute "relativeHumidityTomorrowNight","number"
    attribute "windSpeedTodayDay","number"
    attribute "windSpeedTodayNight","number"
    attribute "windSpeedTomorrowDay","number"
    attribute "windSpeedTomorrowNight","number"
    
    command "getTWCData"
     }
 }

def installed() {
    updated()
}

def updated() {
    unschedule()
    getTWCData()
    runEvery15Minutes(getTWCData)
}

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

def getTWCData() {
	log.debug "Getting TWC data..."
	def twcConditions = [:]
    try {
    	twcConditions = getTwcConditions()
    } catch (e) {
		log.debug "Error getting TWC Conditions"
    }
    if (twcConditions) {
        log.debug "$twcConditions"
        sendEvent(name: "dayOfWeek", value: twcConditions.dayOfWeek)
        sendEvent(name: "dayOrNight", value: twcConditions.dayOrNight)
        sendEvent(name: "precip1Hour", value: twcConditions.precip1Hour)
        sendEvent(name: "precip6Hour", value: twcConditions.precip6Hour)
        sendEvent(name: "precip24Hour", value: twcConditions.precip24Hour)
        sendEvent(name: "relativeHumidity", value: twcConditions.relativeHumidity)
        sendEvent(name: "temperature", value: twcConditions.temperature)
        sendEvent(name: "temperatureMax24Hour", value: twcConditions.temperatureMax24Hour)
        sendEvent(name: "temperatureMin24Hour", value: twcConditions.temperatureMin24Hour)
        sendEvent(name: "validTimeLocal", value: twcConditions.validTimeLocal)
        sendEvent(name: "validTimeUtc", value: twcConditions.validTimeUtc)
        sendEvent(name: "windSpeed", value: twcConditions.windSpeed)
    }
    def twcForecast = [:]
    try {
    	twcForecast = getTwcForecast()
    } catch (e) {
    	log.debug "Error getting TWC Forecast"
    }
    if (twcForecast) {
        log.debug "$twcForecast"
        sendEvent(name: "qpfToday", value: twcForecast.qpf[0])
        sendEvent(name: "qpfTomorrow", value: twcForecast.qpf[1])
        sendEvent(name: "temperatureMaxToday", value: twcForecast.temperatureMax[0])
        sendEvent(name: "temperatureMaxTomorrow", value: twcForecast.temperatureMax[1])
        sendEvent(name: "temperatureMinToday", value: twcForecast.temperatureMin[0])
        sendEvent(name: "temperatureMinTomorrow", value: twcForecast.temperatureMin[1])
        sendEvent(name: "precipChanceTodayDay", value: twcForecast.daypart[0].precipChance[0])
        sendEvent(name: "precipChanceTodayNight", value: twcForecast.daypart[0].precipChance[1])
        sendEvent(name: "precipChanceTomorrowDay", value: twcForecast.daypart[0].precipChance[2])
        sendEvent(name: "precipChanceTomorrowNight", value: twcForecast.daypart[0].precipChance[3])
        sendEvent(name: "relativeHumidityTodayDay", value: twcForecast.daypart[0].relativeHumidity[0])
        sendEvent(name: "relativeHumidityTodayNight", value: twcForecast.daypart[0].relativeHumidity[1])
        sendEvent(name: "relativeHumidityTomorrowDay", value: twcForecast.daypart[0].relativeHumidity[2])
        sendEvent(name: "relativeHumidityTomorrowNight", value: twcForecast.daypart[0].relativeHumidity[3])
        sendEvent(name: "windSpeedTodayDay", value: twcForecast.daypart[0].windSpeed[0])
        sendEvent(name: "windSpeedTodayNight", value: twcForecast.daypart[0].windSpeed[1])
        sendEvent(name: "windSpeedTomorrowDay", value: twcForecast.daypart[0].windSpeed[2])
        sendEvent(name: "windSpeedTomorrowNight", value: twcForecast.daypart[0].windSpeed[3])
    }
}

def refresh() {
	log.debug "Running Refresh..."
	getTWCData()
}

def configure() {
	log.debug "Running Configure and scheduling updates..."
	unschedule()
    runEvery15Minutes(getTWCData)
}