I have a custom Zigbee sensor that sends a simple voltage value. I have been able to parse the incoming value to a float. However I've not been able to create the proper "sendevent" to set the value.
The smartthings documentation says the value in a sendEvent can be a value.
sendEvent(name: "Voltage", value: floatValue, unit:"V", isStateChange: true) shows "floatValue" in text
sendEvent(name: "Voltage", value: "floatValue", unit:"V", isStateChange: true) shows Null
Can anyone suggest where I'm going wrong?
Thanks
John
my code:
/**
* Analog Simple Test
* 2021-01-10 v02
* 2021-01-23 v07 - (open) adding the ability to convert the PVTO IEEE-754 input to decimal.
*
*/
metadata {
// Automatically generated. Make future change here.
definition (name: "AnalogTst", namespace: "johnrob", author: "johnrob") {
capability "Actuator"
capability "Switch"
capability "Configuration"
capability "Refresh"
capability "Sensor"
attribute "Voltage", "BigDecimal"
// attribute "Voltage", "long"
//fingerprint profileId: "0104", inClusters: "0000,0003,0004,0005,0006,0B04,0B05", outClusters: "0019"
}
} // --- metadata ---
// Parse incoming device messages to generate events
def parse(String description) {
//log.debug " 24 Parse description= $description"
def name = null
def value = null
Map map = [:]
if (description?.startsWith("read attr ")) {
def descMap = zigbee.parseDescriptionAsMap(description)
if (descMap.cluster == "000C" && descMap.attrId == "0055") {
//___Convert Hex Value to Float _____________________________________________
hexValue = descMap.value
valueHexStr = hexValue.toString()
int intBits = Long.valueOf(valueHexStr, 16).intValue();
float floatValue = Float.intBitsToFloat(intBits);
log.info " 38 Voltage=${floatValue}" // active log shows correct number
// __________________________________________________________________
}
// for this test floatValue = 3.295
sendEvent(name: "Voltage", value: floatValue, unit:"V", isStateChange: true)
//sendEvent(name: "Voltage", value: "floatValue", unit:"V", isStateChange: true)
}
} // --- parse ---
def parseDescriptionAsMap(description) {
(description - "read attr - ").split(",").inject([:]) { map, param ->
def nameAndValue = param.split(":")
map += [(nameAndValue[0].trim()):nameAndValue[1].trim()]
}
}
// --- eof ---