Simple counter

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 ?

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.

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

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

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.

Correct…