@florianz, I tried but not working, I am posting my code here, basically I am trying to get Temperature and Humidity from my Spark Core. Could you please check and advice?
/**
* Spark Core Temperature & Humidity Sensor
*
* Copyright 2014 Krishnaraj Varma
*
* INSTALLATION
* ------------
*
* 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.
*
*/
preferences {
input("deviceId", "text", title: "Device ID")
input("token", "text", title: "Access Token")
}
metadata {
definition (name: "Spark Core Temperature Sensor", namespace: "krvarma/sparktemperature", author: "Krishnaraj Varma") {
capability "Polling"
capability "Temperature Measurement"
capability "Relative Humidity Measurement"
capability "Sensor"
}
simulator {
}
tiles {
valueTile("temperature", "device.temperature", width: 2, height: 2){
state "temperature", label: '${currentValue}°C', unit:"",
backgroundColors: [
[value: 25, color: "#202040"],
[value: 30, color: "#202080"]
]
}
valueTile("humidity", "device.humidity", width: 2, height: 2){
state "humidity", label: '${currentValue}%', unit:"",
backgroundColors: [
[value: 50, color: "#202040"],
[value: 80, color: "#202080"]
]
}
standardTile("refresh", "device.temperature", inactiveLabel: false, decoration: "flat") {
state "pollsensors", action:"polling.poll", icon:"st.secondary.refresh"
}
standardTile("timestamp", "device.timestamp", inactiveLabel: false, decoration: "flat") {
state "default", action:"polling.poll", icon:""
}
main "temperature"
details(["temperature", "humidity", "refresh"])
}
}
// handle commands
def poll() {
log.debug "Executing 'poll'"
getTemperature()
}
// Get the temperature & humidity
private getTemperature() {
//Spark Core API Call
def temperatureClosure = { response ->
log.debug "Temeprature Request was successful, $response.data"
sendEvent(name: "temperature", value: response.data.return_value)
}
def temperatureParams = [
uri: "https://api.spark.io/v1/devices/${deviceId}/getTemp",
body: [access_token: token],
success: temperatureClosure
]
httpPost(temperatureParams)
def humidityClosure = { response ->
log.debug "Humidity Request was successful, $response.data"
sendEvent(name: "humidity", value: response.data.return_value)
sendEvent(name: "timestamp", value: response.data.published_at)
}
def humidityParams = [
uri: "https://api.spark.io/v1/devices/${deviceId}/getHum",
body: [access_token: token],
success: humidityClosure
]
httpPost(humidityParams)
}