[Question] Passing multiple arguments to Javascript transformation?

I know the OH docs example shows:

transform("JS", "getValue.js", "foo bar baz")

// Wrap everything in a function
(function(i) {
    var
        array = i.split(" ");
    return array[array.length - 1].length;
})(input)
// input variable contains data passed by openhab

I was wondering if it is possible to pass multiple arguments to Javascript ? the reason i need this because when energy meter accumulated value turnover back to 0, a previous monthly reading should be passed to the script in order to get the accurate reading, for example if the MAX reading is 9999kWh and most recent reading passed that, the correct value should be (9999-previous_reading+current_reading).

Are rules the only way to do this ? in the docs it says its based on xtext but then xtend is mentioned, what the best way to check rules syntax in OH2 environment ? ESH designer rules and actions doesn’t work AFAIK

Hi,

I have followed provided example to pass multiple arguments to a Javascript transform, and it is working fine:
(function(i) {

             var inputArray = i.split(" ");
             var rel_hum = inputArray[0];
             var temp = inputArray[1];

And I call it this way in my rules file:
hygro_abs_salledeau_str = transform("JS", "absolute_humidity.js", String::valueOf(hygro_salledeau_value).concat(" ").concat(String::valueOf(temp_salledeau_value)))

Hope it helps you.

Lionel

Thanks, do you think this would work directly in item definition?

I figured out i could do my calculations in Rules using “Xtend” took me a lot to figure it out specially type conversion, JS is much simpler which brings me to another Question:

Having for loop in a calculation (fixed to 7 iterations) would it be best to implement it using Xtend in Rules , JS in Rules, or JS in items ? (To optimize performance)