Greetings,
I am new to this platform working on my first personal project. I am trying to create a “device” that exposes the current price of electricity from ComEd’s Real-Time Pricing program (see https://hourlypricing.comed.com/live-prices/). Once I have this, I want to create automations that turn on/off high energy consumption devices based on the price (for example, my dehumidifier in the basement which has a smart plug should only run when electricity is cheap).
I have it working so that it shows up correctly in the Classic app but in the new app it simply shows “Checking Status” and no data. I’m 95% sure that I’m missing something simple. I think I need to add something so that it works with the new app, but I’m not sure how that works.
Here is my DTH so far:
metadata {
definition (name: "Price Handler", namespace: "myappspace", author: "ABC123", cstHandler: true, vid: "generic-sensor") {
capability "Sensor"
capability "Health Check"
attribute "price", "number"
}
simulator {
// TODO: define status and messages here (if needed)
status "getPrice": ""
}
tiles(scale: 2) {
valueTile("priceTile", "device.price", decoration: "flat", width: 1, height: 1, canChangeIcon: true) {
state "price", label:'${currentValue} Cents'
}
main('priceTile')
}
}
def getPrice() {
log.debug "Fetching Current Hour Price"
Calendar calendar = Calendar.getInstance()
def minute = calendar.get(Calendar.MINUTE)
if ( minute <= 10 ) {
return;
}
def params = [
uri: "https://hourlypricing.comed.com?type=currenthouraverage",
path: "/api",
query: [type: "currenthouraverage"]
]
try {
httpGet(params) { resp ->
def price = new groovy.json.JsonSlurper().parseText(resp.getData().toString()).price.get(0)
log.debug "Current hour price: $price"
sendEvent(name: "price", value: price)
}
} catch (e) {
log.error "Error getting current hour price: $e"
}
}
// parse events into attributes
def parse(String description) {
log.debug("Parse got message: '${description}'");
}
def initialize() {
runEvery5Minutes(getPrice)
log.debug "Schedule Set"
}
def installed() {
initialize()
getPrice()
}
def updated() {
initialize()
}
//For Health Check
def ping() {
log.debug "ping()"
}
I thought I found some information that I need to add the vid to the metadata and the HealthCheck (and the associated ‘ping’ method) to make it work with the new app but that didn’t seem to change anything.
Does anyone see what I’m missing? Any help or pointers to the documentation that I need to read to understand are deeply appreciated!