Update PhotonDS18B20.groovy

This commit is contained in:
timberjoegithub
2017-02-21 16:38:43 -05:00
committed by GitHub
parent a27967193e
commit b353f3d562
@@ -14,38 +14,33 @@
preferences { preferences {
input("token", "text", title: "Access Token") input("token", "text", title: "Access Token")
input("deviceId", "text", title: "Device ID") input("deviceId", "text", title: "Device ID")
// input("relaynum", "text", title: "Relay Number 1-6")
input("deviceName", "text", title: "Name of device in the Photon cloud") input("deviceName", "text", title: "Name of device in the Photon cloud")
// device name in api like: https://api.spark.io/v1/devices/${deviceId}/${deviceName} // device name in api like: https://api.spark.io/v1/devices/${deviceId}/${deviceName}
} }
metadata { metadata {
definition (name: "DS18B20 Temperature Sensor", namespace: "smartthings", author: "github@josephsteele.com") { definition (name: "DS18B20 Photon Temperature Sensor", namespace: "SmartThingsPublic", author: "github@josephsteele.com") {
capability "Temperature Measurement" capability "Temperature Measurement"
capability "Sensor" capability "Sensor"
// fingerprint profileId: "0104", deviceId: "0302", inClusters: "0000,0001,0003,0009,0402,0405"
} }
command "callTemp"
// simulator metadata // simulator metadata
simulator { simulator {
for (int i = -30; i <= 180; i += 10) { for (int i = -30; i <= 180; i += 10) {
status "${i}F": "temperature: $i F" status "${i}F": "temperature: $i F"
status "on": "command: 2003, payload: FF"
status "off": "command: 2003, payload: 00"}
} }
}
// UI tile definitions // UI tile definitions
tiles { tiles {
valueTile("temperature", "device.temperature", width: 3, height: 3) { valueTile("temperature", "device.temperature", width: 3, height: 3) {
state("temperature", label:'${currentValue}°', state("temperature", label:'${currentValue}°',
backgroundColors:[ backgroundColors:[
[value: 31, color: "#153591"], [value: 20, color: "#153591"],
[value: 44, color: "#1e9cbb"], [value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"], [value: 60, color: "#90d2a7"],
[value: 74, color: "#44b621"], [value: 85, color: "#44b621"],
[value: 84, color: "#f1d801"], [value: 98, color: "#f1d801"],
[value: 95, color: "#d04e00"], [value: 103, color: "#d04e00"],
[value: 96, color: "#bc2323"] [value: 110, color: "#bc2323"]
] ]
) )
} }
@@ -55,60 +50,50 @@ metadata {
} }
def installed() { def installed() {
initialize() initialize()
log.debug "Installed with settings: ${settings}"
} }
def updated() { def updated() {
initialize() initialize()
log.debug "Updated with settings: ${settings}"
} }
def initialize() { def initialize() {
// runEvery5Minutes(parse(temperature))
log.debug "handlerMethod called at ${new Date()}" log.debug "handlerMethod called at ${new Date()}"
runEvery5Minutes(callTemp()) runEvery5Minutes(callTemp)
//runEvery5Minutes(parse) log.debug "line after runevery5 executed at at ${new Date()}"
// log.trace
} }
// Parse incoming device messages to generate events // Parse incoming device messages to generate events
def parse(String description) { def parse(String description) {
// def getdata = callTemp(numtemp) log.info "Entered parse at ${new Date()}"
def getdata = callTemp
def name = parseName(description) def name = parseName(description)
def value = parseValue(description) def value = parseValue(description)
def unit = name == "temperature" ? getTemperatureScale() : (name == "humidity" ? "%" : null) def unit = name == "temperature" ? getTemperatureScale() : (name == "humidity" ? "%" : null)
def result = createEvent(name: name, value: value, unit: unit) def result = createEvent(name: name, value: value, unit: unit)
log.debug "Parse returned ${result?.descriptionText}" log.info "Parse returned ${result?.descriptionText}"
return result return result
} }
private String parseName(String description) { private String parseName(String description) {
if (description?.startsWith("temperature: ")) { if (description?.startsWith("temperature: ")) {
return "temperature" return "temperature"
} }
null
} }
private String parseValue(String description) { private String parseValue(String description) {
if (description?.startsWith("temperature: ")) { if (description?.startsWith("temperature: ")) {
def txtresult = "" def txtresult = ""
return (description - "temperature: " - "°F" - "F").trim() return (description - "temperature: " - "°F" - "F").trim()
// return zigbee.parseHATemperatureValue(description, "temperature: ", txtresult)
} }
} }
def callTemp(resp2) {
def callTemp() {
log.debug "callTemp called at ${new Date()}" log.debug "callTemp called at ${new Date()}"
try { try {
log.debug "https://api.particle.io/v1/devices/${deviceId}/${deviceName}?access_token=${token}" // log.debug "https://api.particle.io/v1/devices/${deviceId}/${deviceName}?access_token=${token}"
httpGet(uri: "https://api.particle.io/v1/devices/${deviceId}/${deviceName}?access_token=${token}", httpGet(uri: "https://api.particle.io/v1/devices/${deviceId}/${deviceName}?access_token=${token}",
contentType: 'application/json',) contentType: 'application/json',)
{resp -> {resp ->
log.debug "resp data: ${resp.data}" log.debug "resp data: ${resp.data}"
log.debug "result: ${resp.data.result}" log.info "result: ${resp.data.result}"
sendEvent(name: "temperature", value: "${resp.data.result}", unit: "F" ) //sendEvent(name: "temperature", value: 72, unit: "F") sendEvent(name: "temperature", value: "${resp.data.result}", unit: "F" ) //sendEvent(name: "temperature", value: 72, unit: "F")
//return (${resp.data.result}); log.debug (name: "temperature", value: "${resp.data.result}", unit: "F" )
} }
} catch (e) {log.error "something went wrong: $e"} } catch (e) {log.error "something went wrong: $e"}
} }