Something wrong with my Device Type


(Adrian Lopez) #1

Hi community,

I’m creating a new device type and something goes wrong, my device is a ZigBee falls sensor. I don´t know if it is well implemented but for now in the part of “Tiles” something must be wrong because the icon which appear is unknown and doesn´t change color when i simulte from active to inactive . What else is good?

Thanks

/**
 *  Detector de caidas
 *
 *  Copyright 2015 Adrián López Delgado
 *
 *  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: "Detector de caidas", 
        namespace: "Adrián TFG", 
        author: "Adrián López Delgado") {
			capability "sensor"
			fingerprint inClusters: "0000, 0003, 00b2", 
        				endpointId: "08", 
                    	profileId: "0104"
		}
    
    command 'active'
    command 'inactive'


	simulator {
		// status messages
		status "active": "active/inactive: 1"
		status "inactive": "active/inactive: 0"

		// reply messages
		reply "zcl on-off active":"active/inactive: 1"
		reply "zcl on-off inactive":"active/inactive: 0"
	}
	tiles {
		standardTile("sensor", "device.sensor", width: 2, height: 2, canChangeIcon: true) {
			state "inactive", label: 'inactive', action: "sensor.on", icon: "st.categories.damageAndDanger", backgroundColor: "#e86d13"
			state "active", label: 'active', action: "sensor.off", icon: "st.categories.damageAndDanger", backgroundColor: "#53a7c0"
		}
		main "sensor"
		details(["sensor"])
	}
}

// Parse incoming device messages to generate events

def parse(String description) {
    log.info description
    if (description?.startsWith("catchall:")) {
	def value = name == "sensor" ? (description?.endsWith(" 1") ? "active" : "inactive") : null
		def result = createEvent(name:name, value:value)
		def msg = zigbee.parse(description)
		return result
	} else{
        def name = description?.startsWith("on/off: ") ? "sensor": null
		def value = name == "sensor" ? (description?.endsWith(" 1") ? "active" : "inactive") : null
        def result = createEvent(name:name, value:value)
		return result
    }

    def result = createEvent(name: name, value: value)
    return result
}


// handle commands
def active() {
	log.debug "Execution 'active()'"
	sendEvent(name: "sensor", value: "active")
	"st cmd 0x${device.deviceNetworkId} ${endpointId} 6 1 {}"
    'zcl active/inactive active'
}

def off() {
	log.debug "Execution 'inactive()'"
	sendEvent(name: "sensor", value: "inactive")
	"st cmd 0x${device.deviceNetworkId} ${endpointId} 6 0 {}"
    'zcl active/inactive inactive'
}