Simple counter


(Matthias Ertl) #1

Hello,

i want to simply create a thing which is able to count.

(my idea: im not able to monitor my daily energy consumption, but i know that for example every day i consume xx KWHs - therefore i want to create a thing showing my initial energy KWH meter and add with WebCoRe everyday my value x : initial value xx + daily y = @new value)

therefore i created a simple energy tile and now i need to create a variable which i can fill with Webcore

tiles {
    valueTile("energy", "device.energy", width: 3, height: 2,  canChangeIcon: true) {
        state "default", label: '@newvalue kWh'
    }

can someone help me to do that ?


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #2

A Device exposes Attributes not variables (variables are for internal use only).

So if you have created a DTH with Capability “Energy Meter”, you have can expose an ad hoc custom Command called like “def addToEnergy( amount )” and that Command can use the sendEvent(...) method to update the Attribute “energy”.

I know that’s just a sketch … but does it make sense?

Using a Command to update an Attribute is pretty common, but not ubiquitous. Most DTHs get their updates through the parse() method which silently calls sendEvent(...) at its end.


(Matthias Ertl) #3

Hi,
thank you for your response, … i managed now to add the Command addToEnergy in order to send an event:

	def addToEnergy (amount) {
        sendEvent(name: "energy", value: 39396 )
}

what is the syntax to set the value to my global variable @var1 (which is updated by webcore ?)

thanks matthias


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #4

While I think this is likely simple, I’m not familiar enough yet with webCoRE to say.

I think you just need to add an “action” (?) statement that calls your “addToEnergey(@var1)” command.

It should be similar to any other Command call, I presume; like a Piston that calls setLevel(dimlevel).


(Matthias Ertl) #5

ok … but when i call the command addToEnergy it simply sets the value of “energy” to 39396 (from sendEvent)

i have to so some math here … 39396 + 4
e.g.


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #6

Correct…


(Robin) #7

Hi,

Please come on over to the webCoRE forum where all the experts are hiding.

I’m currently hubless which sucks… so I can’t post any examples… the guys and gals on the new forum will definitely help you out though!

In a nutshell, you’ll need to use webCoRE to read the current value, add the extra value and then send that back to the DTH… fairly simple.

Alternatively, and probably easier, just have webCoRE keep count and update the DTH with that instead.