Power Consumption (First App)


#1

Forgive my noobness, but I have been scouring the net trying to find documentation on how to read the activity feed of a device? This is what I’m trying to accomplish and maybe I’m going about it the wrong way:

I have set up an espresso machine at work and would like to monitor the number of times per day that an espresso is made. I have it plugged into an appliance module that can turn the machine on/off through SmartThings. It also shows the watts being used by the machine constantly. At idle, the machine pulls 3W. When the machine is making an espresso, its using ~1400W. I can see the Activity Feed in the Smart Things app showing the change in current but I don’t see anywhere how to read that? Like I said, I may be looking at accomplishing this task from the wrong angle.

Any help/ideas?


(Jody) #2

Are you wanting an app that does this or are you asking how to do it? Keep in mind that via the smartthings app you will only see seven days of usage.

My dashboard has a power consumption graph that is very easy to get up an running

https://thinglayer.net

There is also the grovestreams app


#3

Thank you for your reply Jody. I was wanting to build an app to do this so I can extend it later to Google Docs or on a webpage etc. Mainly, what I’m looking for is a way to record the measurement when it exceeds ~1400W. That would be 1 espresso and keep going so I can get a count on how many espressos are made in 1 day. I would need a way, from SmartApps, to tap into the power consumption of the machine and to record it to a log somewhere.


(Jody) #4

Should be fairly straight forward.

I am not a groovy expert, but you simply need to grab the events for the espresso machine for the current 24 hour period. Loop through the events and increment a variable by 1 every time the watts are greater than 1350. With this variable stored in your device type, you could have an “Espressos Brewed” value tile.

http://docs.smartthings.com/en/latest/smartapp-developers-guide/querying-events-in-smartapps.html?highlight=events


(Jody) #5

As for logging out to an external service, take a look at the grovestreams link from my previous post.


#6

Awesome! Thank you so much for the direction on this. Ill start going through the setup of GrooveStream and reading up on the events from that link.


(Mark Ghosh) #7

This is so cool! Thank you so much for the direction. I am using an Aeon Labs HEM V1 with your code and it tracks the power usage just fine. I am also trending temperature inside and outside with this and matching it up with the power usage to better understand my cost and control energy footprint in the future.

Here is my modified app, if it will help someone. I take no credit. I just moved things around is all.

/**
 *  GroveStreams
 *
 *  Copyright 2014 Jason Steele
 *
 *  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: "GroveStreams",
    namespace: "JasonBSteele",
    author: "Jason Steele",
    description: "Log to GroveStreams",
    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 "temperatures", "capability.temperatureMeasurement", title: "Temperatures", required:false, multiple: true
        input "contacts", "capability.contactSensor", title: "Doors open/close", required: false, multiple: true
        input "accelerations", "capability.accelerationSensor", title: "Accelerations", required: false, multiple: true
        input "motions", "capability.motionSensor", title: "Motions", required: false, multiple: true
        input "presence", "capability.presenceSensor", title: "Presence", required: false, multiple: true
        input "switches", "capability.switch", title: "Switches", required: false, multiple: true
        input "powers", "capability.powerMeter", title: "Power Meters", required:false, multiple: true
        input "energys", "capability.energyMeter", title: "Energy Meters", required:false, multiple: true 

    }

    section ("GroveStreams Feed PUT API key...") {
        input "channelKey", "text", title: "API key"
    }
}

def installed() {
    initialize()
}

def updated() {
    unsubscribe()
    initialize()
}

def initialize() {
    subscribe(temperatures, "temperature", handleTemperatureEvent)
    subscribe(contacts, "contact", handleContactEvent)
    subscribe(accelerations, "acceleration", handleAccelerationEvent)
    subscribe(motions, "motion", handleMotionEvent)
    subscribe(presence, "presence", handlePresenceEvent)
    subscribe(switches, "switch", handleSwitchEvent)
    subscribe(powers, "power", handlePowerEvent)
    subscribe(energys, "energy", handleEnergyEvent)
}

def handlePowerEvent(evt) {
    sendValue(evt) { it.toString() }
}

def handleEnergyEvent(evt) {
    sendValue(evt) { it.toString() }
}

def handleTemperatureEvent(evt) {
    sendValue(evt) { it.toString() }
}

def handleContactEvent(evt) {
    sendValue(evt) { it == "open" ? "true" : "false" }
}

def handleAccelerationEvent(evt) {
    sendValue(evt) { it == "active" ? "true" : "false" }
}

def handleMotionEvent(evt) {
    sendValue(evt) { it == "active" ? "true" : "false" }
}

def handlePresenceEvent(evt) {
    sendValue(evt) { it == "present" ? "true" : "false" }
}

def handleSwitchEvent(evt) {
    sendValue(evt) { it == "on" ? "true" : "false" }
}


private sendValue(evt, Closure convert) {
    def compId = URLEncoder.encode(evt.displayName.trim())
    def streamId = evt.name
    def value = convert(evt.value)

    log.debug "Logging to GroveStreams ${compId}, ${streamId} = ${value}"

    def url = "https://grovestreams.com/api/feed?api_key=${channelKey}&compId=${compId}&${streamId}=${value}"

    def putParams = [
        uri: url,
        body: []
    ]

    httpPut(putParams) { 
        response -> 
        if (response.status != 200 ) {
            log.debug "GroveStreams logging failed, status = ${response.status}"
        }
    }

}