How to Schedule events in Device Type Code?


(Jjhamb) #1

Hi All,
Perhaps this has been answered before but please bear with me… My Groovy Experience is near zero but I have been able to modify existing codes to adapt to my devices. Mainly two types
A) Dual Relay Switch from TKBHome - I am able question arises from my need to be able to store to control individual relays in this device using Aeon Strip code.
B) AEON Smart Meter HEM G2

My question arises from my need to Store Energy Value of HEM at a particular time to enable me to calculate consumption and billing. Say from Noon to Noon and / Or from Month to Month.

Is there any way to generate a cron type event in Device Type code to creatEvent to store attribute value or SendEvent to the app at a specific time?

Thanx in advance

jjhamb


(Brian Steere) #2

Not really. The only way to do that (reliably) is to have a SmartApp that does the scheduled things and updates the devices accordingly.


(Barry) #3

You can read most any parameter shown on a Tile from within a Smart App. In the case of the Aeon HEMv2 Smart device driver that I created (here https://github.com/SANdood/Aeon-HEM-v2), you can read the kWh value directly as aeonDevice).latestValue(“energy”) on a schedule, and you can also call aeonDevice.reset() to reset ALL the counters to zero so that you can collect the daily values.


(Jjhamb) #4

@storageanarchy - Thanx for the link… I am using the device and it works . Well with some problems. What I am trying to do is store a reading (energy) as an attribute. Say reading at 00::00LT on 1st of the month and evaluate the billing on monthly cycle. Or Daily. Presently since I am developing the Billing App it gets loaded often and it looses state. If this reading can be stored on the device handler code (which) is static, then all instances of the app will get the sane reading irrespective of when they are initialized.


(Jjhamb) #5

Additionally Guys please help with this:
I am using an app to upload HEM data to Xively channel. I can retrieve this data as json as under
log.debug ${resp.data} is as under:
[id:1526578265, title:hem, product_id:maHiH0E-UrJncAUszD_9, device_serial:R94JJHC49KXP, created:2014-04-19T01:52:41.642027Z, updated:2014-08-13T05:25:25.739810Z, status:live, feed:https://api.xively.com/v2/feeds/1526578265.json, datastreams:[[id:Energy, datapoints:[[at:2014-08-01T06:30:00.000000Z, value:96130.559506]], unit:[symbol:kWh, label:Kilo Watt], current_value:96663, at:2014-08-13T05:22:25.842159Z, max_value:96663.0, min_value:2242.72152]], version:1.0.0, creator:https://xively.com/users/jjhamb, private:false]

The value I need to retrieve is 96130.559506
I can get to it with resp.data.datastreams.datapoints.value
However ${resp.data.datastreams.datapoints.value} returns:
[[96130.559506]]

Now how do I remove the brackets and use the value?
def toReplace = “${resp.data.datastreams.datapoints.value}“
def replaced = toReplace.replaceAll(”[[”, “”)
this results in an error:
ava.util.regex.PatternSyntaxException: Unclosed character class near index 0
[
^ @ line 286


(Geko) #6

Try this:

str = str.replaceAll('\\[|\\]','')

(Jjhamb) #7

@geko Worked like a charm… thanx, and I managed to find groovy docs for myself. But hey much appreciate the help.