SUCCESS!!
Yes, a google search quickly solved the bracket problem. Just added [0] as seen in the code I pasted below. I tried several strategies in the device handler to get it to refresh, but none of them worked. Creating a custom piston in WebCoRE solved it, though. I have it refreshing every 30 seconds. I did find that WU code and used it as a reference:)
I wrote a new Device Handler so that it works as a stand-alone Virtual ThingSpeak Sensor. If anyone else wants to use it, just replace my ThingSpeak uri with your own. I expect it will be easy enough to customize for humidity, lux levels, or whatever else you might be tracking on a ThingSpeak-like service rather than on a hub.
Also, I tested this as my sensor device with the SmartThings-VirtualThermostat-WithDTH thermostat, and it is working perfectly, updating the temperature in that app immediately after my Virtual ThingSpeak Sensor updates (I initially tried seeing the the thermostat would regularly refresh on it’s own before jumping into WebCoRE, but it didn’t)
Here’s the device handler code:
metadata {
definition (name: "Virtual ThingSpeak Sensor", namespace: "MN", author: "Michelle N.") {
capability "Refresh"
capability "Sensor"
capability "Temperature Measurement"
capability "Health Check"
command "refresh"
command "poll"
command "setVirtualTemperature", ["number"]
attribute "temperatureUnit", "string"
attribute "debugOn", "string"
}
simulator {
// TODO: define status and reply messages here
}
tiles(scale: 2) {
valueTile("temperature", "device.temperature", width: 2, height: 2, decoration: "flat") {
state("temperature", label:'${currentValue}°', unit: unitString(),
backgroundColors: getTempColors())
}
standardTile("refresh", "device.refresh", width:2, height:2, decoration: "flat") {
state "Refresh", action:"refresh.refresh", icon:"st.secondary.refresh"
}
}
/*preferences {
input "resetHistoryOnly", "bool", title: "Reset History Data", description: "", displayDuringSetup: false
input "resetAllData", "bool", title: "Reset All Stored Event Data", description: "", displayDuringSetup: false
}*/
}
def shouldReportInCentigrade() {
//there is no way to do this dynamically right now, a number of the functions that call this function are compile time evaluated :(
return false //Set this to true for Centigrade, false for Fahrenheit so that enums and colors are correct (due to ST issue of compile time evaluation)
/*try {
def ts = getTemperatureScale();
retVal = ts == "C"
} finally {
return retVal
}*/
}
def installed() {
initialize()
}
def configure() {
initialize()
}
def initialize() {
state.tempScale = "F"
}
def getTempColors() {
def colorMap
colorMap = [
// Set your own Color Range based on C/F and personal comfort ranges
[value: 40, color: "#153591"],
[value: 68, color: "#1e9cbb"],
[value: 70, color: "#90d2a7"],
[value: 73, color: "#44b621"],
[value: 76, color: "#f1d801"],
[value: 80, color: "#d04e00"],
[value: 90, color: "#bc2323"]
]
}
def unitString() { return shouldReportInCentigrade() ? "°C": "°F" }
def defaultTemp() { return shouldReportInCentigrade() ? 20 : 70 }
def getTemperature() {
try {
httpGet(uri: "https://api.thingspeak.com/channels/******/fields/1.json?results=1") {resp ->
// get the data from the response body
// log.debug "response data: ${resp.data}"
log.debug "temperature: ${resp.data.feeds.field1[0]}"
return "${resp.data.feeds.field1[0]}"
}
} catch (e) {
log.debug "something went wrong: $e"
}
}
def ping() {
log.trace "Executing ping"
refresh()
}
def parse(data) {
log.debug "parse data: $data"
}
def refresh() {
log.trace "Executing refresh"
sendEvent(name: "temperature", value: getTemperature(), unit: unitString())
}
def poll() {
refresh()
}
def setVirtualTemperature(temp) {
sendEvent(name:"temperature", value: temp, unit: unitString(), displayed: false)
}
def setTemperatureScale(val) {
log.debug "set temp scale to: $val"
sendEvent(name:"tempScale", value: val, displayed: false)
}
Here’s my code in WebCoRE:
/**************************************************************/
/* Refresh Temperature */
/**************************************************************/
/* Author : foxymichelle */
/* Created : 11/13/2019, 8:31:21 AM */
/* Modified : 11/13/2019, 8:32:15 AM */
/* Build : 1 */
/* UI version : v0.3.110.20191009 */
/**************************************************************/
execute
every 30 seconds
do
with
Virtual ThingSpeak Sensor
do
Refresh;
end with;
end every;
end execute;
Now it’s time for me to start building some more smart crap for my otherwise stupid home!