Emonscms push app

i just got my smarthub and some sensors and so far i like it, i thing it is very easy to setup and use.

before i used to have a raspberry pi with a bunch of rf sensor nodes pushing information to emoncms.org website with a POST statement.

i wonder if there is an application already to post to emoncsms service.?

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?

The blacklist error is " 12:07:22 AM: error java.lang.SecurityException: Endpoint http://emoncms.org/input/post?json={power:556}&apikey=xxxxxxxxxxxxxxxxxxxxxxxx is blacklisted. @ line 68"

Line 68 = log.debug “postApi= ${postApi}” (see below)

I’m very new to all of this but would love to get this working.

definition(
name: “emconcms”,
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
}

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)
}

def handlePowerEvent(evt) {
logField(evt.value)
}

def logField(watts) {
log.info “watts value= ${watts}”
def apiURL = ‘Emoncms - input post}&apikey=${channelKey}’

    def postApi = [
	    uri: apiURL,
        headers: ['Content-Type': 'application/xml'],
		body:'testing'
        ]
    log.debug "postApi= ${postApi}"
    httpPost(postApi) { response ->
    log.info "httpPost responce:${response.status}"
  }   

}

Anyone gotten emoncms to work with smartthings?

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}"
        }
	}
}
1 Like

This is really cool…

i haven read smarthings api code…

but could you comment more the code to see what is it doing? how can i grab the temperature of a smarthings sensor and log it to a emonscms feed…

Reviving the dead here - but I’d really like to figure out how to modify this to pull other data, like thermostat temperature and humidity,

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

I’ve made a WebCoRE piston for this, its published here - https://community.webcore.co/t/post-device-statistics-to-emoncms-org-open-energy-monitor-or-emonpi/17158