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