I have been trying to writ my own smartapp to push data to emoncms.org. Below is the code I have. I get a âblacklistedâ error, but I donât know why. Any help?
I finally got it working, but I ended up posting as CSV instead of JSON. I really like having the android app. It makes seeing the data very easy.
Here is my new code:
/**
emconcmsv2 (31May2016)
*
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.
*
*/
definition(
name: "emconcms_v2",
namespace: "Jonathan Baker",
author: "Jonathan Baker",
description: "Log to emconcms",
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 "power", "capability.powerMeter", title: "Power", required: false, multiple: true
input "energymeters", "capability.EnergyMeter", title: "Energy Meter", required: false, multiple: true
}
section ("Emcon Feed PUT(write) API key...") {
input "channelKey", "text", title: "API key"
}
}
def installed() {
initialize()
}
def updated() {
unsubscribe()
unschedule()
log.debug "Attempted to Unschedule"
if (canSchedule()) {log.debug "all unscheduled."}
else {log.debug "still waiting for unschedule."}
initialize()
}
def initialize() {
subscribe(power, "power", handlePowerEvent)
subscribe(energies, "energy", handleEnergyEvent)
}
def handlePowerEvent(evt) {
logField(evt,"power") { it.toString() }
}
def handleEnergyEvent(evt) {
logField(evt,"energy") { it.toString() }
}
private logField(evt, field, Closure c) {
log.info "field: ${field}" //tells you if you are logging power (watts) or energy (kWh)
if (field == "power") { //no node assigned for power
log.debug "Power value is ${evt.value}"
def params = [
uri: "https://emoncms.org/input/post.json?csv=${evt.value}&apikey=${channelKey}"
]
try {
// log.debug "running commmand: httpGet(${params})"
httpGet(params)
} catch (e) {
log.info "httpGet response: ${e}"
}
}
else if (field == "energy") { //energy is node 1
log.debug "Energy value is ${evt.value}"
def params = [
uri: "https://emoncms.org/input/post.json?node=1&csv=${evt.value}&apikey=${channelKey}"
]
log.debug "params = ${params}"
try {
// log.debug "running commmand: httpGet(${params})"
httpGet(params)
} catch (e) {
log.info "httpGet response: ${e}"
}
}
}
I use Emoncms since over a year and it works perfectly.
However I do not code so I use WebCore to push the data to Emoncms. Really âeasyâ to set up different jobs for different types. For example every 5 minutes for the Watts, temperature, humidity etc and every hours for the kWh