I’m new to OpenRemote platform but it seems very powerful and seems to fit my needs regarding some project. Currently I’m facing problem with Groovy rule which should modify asset X custom attribute “atr3” (Number) as caclulation (let’s say sum for a simplicity) based on values “atr1” and “atr2” of this asset and “atr4” of asset Y (atr3=atr1+atr2+atr4). I’ve managed to change value of attribute “atr3” to defined constant everytime “atr1” is being updated but having problem how to get and use values of “atr1”, “atr2” (from asset X) and “atr4” (from asset Y) for a full calculation formula. I have no experience in Groovy/Java language and little help would be very appreciated.
Have you tried this with the Flow Rules feature in the Manager UI?
We use this ourselves to make simple calculations, so it might be a good fit.
.
However, if this does not fit your needs, Groovy can provide flexibility
You can look at the examples we made here and here, or look at the official docs:
Unfortunately simple Flow Rules are not suitable for calculations I need to make. I must use Groovy.
To precise my question: how can I get current value of attribute “atr2” from asset “X” and “atr4” from asset “Y” (I would like to reference to assets by their id and to attributes by their name) in “then” section of Groovy rule? What objects and methods should I use?
I’ve checked examples you suggested but unfortunately can’t clearly undestand how to use them in my (much simplier - I think) case.
In another thread I found someting I’m thinking of:
def co = assets.matchFirstAssetState(new AssetQuery().ids(“2zhjdjqTWSONZYMcuLA71o”)).getAttributeValue(“co_pred”)
modified to my case (variable name,asset Id, asset attribute name):
Thank you, I’ve managed to get attributes yesterday, I was struggling because lack of “rule state” item on attribute (attribute was not found by AssetQuery()) - great that you pointed it!
Hi Igor,
I already knew about your proposal to get a value for an attribute, but now I would need to get a list of the latest values of an attribute. Let’s say, for example, that this attribute stores daily MAPE values, and I want to get the average of the last month to decide on further action, how could I do it?
I’m trying to learn a bit about Groovy but it seems that ‘universal’ Groovy is not applicable to Openremote, could it be?
Thanks in advance
Not sure what you mean by ‘universal’ Groovy, there is a limited sandbox for the groovy engine but it doesn’t do much and all groovy language functionality should be available.
There is the historicFacade exposed to rules which is an instance of the HistoricFacade class and this has a method called getValueDatapoints which takes an AssetDatapointQuery allowing retrieval of average value(s) using the AssetDatapointIntervalQuery, you’ll need to look at the code to know the data schema.