Help with Logging Temperature from Motion

smartapp

(Tom Kane) #1

newbie here…
I am trying to write a SmartApp that will log events to an external system when triggered by certain devices… For the most part, its working nicely, but I want to grab the current temperature from motion detector at the time of motion… It this possible? I cannot seem to get the temp to show up anywhere…

Here is my modified code just to grab the temperature…

Thanks for you help!!


definition(
name: “Temperature Logging”,
namespace: “Smartthings”,
author: “Bobby Brady”,
description: "Logging Temps ",
category: “My Apps”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)

preferences {
section(“Log devices…”) {
input “temperature”, “capability.temperatureMeasurement”, title: “Temperatures”, required:false, multiple: true
}
}
def installed() {
initialize()
}

def updated() {
unsubscribe()
initialize()
}

def initialize() {
subscribe(temperatures, “temperature”, handleTemperatureEvent)
}

def handleTemperatureEvent(evt) {
sendValue(evt) { it.toString() }
}

private sendValue(evt, Closure convert) {
def compId = URLEncoder.encode(evt.displayName.trim())
def streamId = evt.name
def value = convert(evt.value)

log.debug "Logging temps ${compId}, ${streamId} = ${value}"

def url = “MODIFIED URL GOES HERE"
def json = “{“version”:“1.0.0”,“Devices”:[,{“compId”:”${compId}”,{“id”:"${streamId}",“current_value”:"${value}"}]}"

def params = [
uri: url,
headers: headers,
body: json
]
httpPutJson(params) { response ->
if (response.status != 200 ) {
log.debug “logging failed, status = ${response.status}”
}
}
}