Not able to read input in device type


(Lord Saibat) #1

Any idea why this does not work on reading input?
green_status, yellow_status, and red_status is always null.

/**
 *  Input Monitor
 *
 *  Copyright 2014 
 *
 *  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.
 *
 */
metadata {
	definition (name: "Input Monitor (36 inputs)", author: "Tobias Mccurry", oauth: true) {
		capability "Contact Sensor"
		capability "Sensor"

		fingerprint profileId: "0104", deviceId: "0402", inClusters: "0000,0001,0003,0009,0500", outClusters: "0000"
	}

	// simulator metadata
	simulator {
		// status messages
        status "Red" : "Status reported within the last $red_status seconds"
		status "Yellow": "Status reported within the last $yellow_status seconds"
        status "Green": "Status reported within the last $green_status seconds"
        
        
	}

	preferences {
    	input name: "green_status", type: "number", title: "How long to wait for a ping?", description: "Set this to a low value in seconds", defaultValue: 60, required: true, displayDuringSetup: true
        input name: "yellow_status", type: "number", title: "How long to wait for a ping?", description: "Set this to a medium value in seconds", defaultValue: 120, required: true, displayDuringSetup: true
        input name: "red_status", type: "number", title: "How long to wait for a ping?", description: "Set this to a high value in seconds", defaultValue: 300, required: true, displayDuringSetup: true
	}
    
	// UI tile definitions
	tiles {
		standardTile("Alarm_Status", "device.AlarmState", canChangeIcon: true, canChangeBackground: true, width: 2, height: 2) {
            state "Red", label: '${name}', icon: "st.Home.home2", backgroundColor: "#ff0000"
			state "Yellow", label: '${name}', icon: "st.Home.home2", backgroundColor: "#cccc00"
            state "Green", label: '${name}', icon: "st.Home.home2",  backgroundColor: "#00ff00"
		}

		main ("Alarm_Status")
		details ("Alarm_Status")
	}
     
}

def init() {
  state.startping = now()
  log.debug("Start time: $state.startping")
  log.debug("Green timeout: " + $green_status) 
  log.debug("Yellow timeout: " + $yellow_status)
  log.debug("Red timeout: " + $red_status)
  }

def installed() {
	init()
}


def updated() {
  //unsubscribe()
  init()
}

def checktimeout(oldtime, newtime){
log.debug("Old time was: $oldtime")
log.debug("Current time: $newtime")
log.debug("Green timeout: " + $green_status) 
log.debug("Yellow timeout: " + $yellow_status)
log.debug("Red timeout: " + $red_status)



green_time_check = oldtime + $green_status
log.debug("Check green time: $green_time_check")
if (green_time_check > oldtime){
sendEvent(name:"AlarmState", value:"Green")
}
yellow_time_check = oldtime + $yellow_status
log.debug("Check yellow time: $yellow_time_check")
if (yellow_time_check > oldtime){
sendEvent(name:"AlarmState", value:"Yellow")
}
red_time_check = oldtime + $red_status
log.debug("Check red time: $red_time_check")
if (red_time_check > oldtime){
sendEvent(name:"AlarmState", value:"Red")
}



}

// Parse incoming device messages to generate events
def parse(String description) {
    log.debug("Description is: $description")
	def value = zigbee.parse(description)?.text
	def name = value && value != "ping" ? "response" : null
	def result = createEvent(name: name, value: value)
	log.debug "Parse returned ${result?.descriptionText}"
	zigbee.smartShield(text: "updated").format()
    
    def delay = green_status ?: 5
    log.debug("delay assign: $delay")
    log.debug("Green timeout: " + $green_status) 
	log.debug("Yellow timeout: " + $yellow_status)
	log.debug("Red timeout: " + $red_status)
    
    
    
    if (value == "ping"){
    log.debug "Ping Received!"
    //sendEvent(name:"AlarmState", value:"Green")
    state.pingtime = now()
  	log.debug("Ping time: $state.pingtime")
    checktimeout(state.startping, state.pingtime)
    //zigbee.smartShield(text: "Green").format()
	}
    
    if (description == "ping"){
    log.debug "Ping Received!"
    //sendEvent(name:"AlarmState", value:"Green")
    checktimeout(state.startping, state.pingtime)
    //zigbee.smartShield(text: "Green").format()
	}
    
    if (value.contains(":")){
      
    }
    
    return result
}

defaultValue in preferences inputs?
(MinKyu Park) #2

Hi,
you can access to inputs on preference page “settings.green_status”.