Blockly: Calling a script with inputs

Dear all,
i am trying to calculate absolute humidity from several relative humidity.
I want to use the absolute values in a blockly rule.
Therefor i created a blockly script to calculate the values, but i dont know how to call this script from a rule and give the scripts inputs (rel. humidity and temperature). Is this even possible with a blockly script?

Different approach was to use an inline script in blockly. But this is giving me very strange outputs:

As you can see the blockly calculation is correct, but how can i give inputs (temperature, rel. humidity) to the script from a rule?
Inline script calculates 10^2 = 8 (why??)

Thank you!

Simple create a rule that triggers when those items change and then call your script

Hello, yes this is possible. But i want to work with the resulting absolute humidity values in my rule. For example compare 4 different absolute values with each other. In order to do this i need to give my script 8 different inputs (rel. humidity 1…4 and temperature 1…4) and get back 4 different abs. humidities (1…4). Is this possible?

Yes, if I understand you correctly.

You can call another rule via “run rule or script with context” Rules Blockly - Run & Process and Transformations | openHAB

Call 1_hello_rule with 2 params:

It takes a “dictionary” which is basically a set of key / value that are forward to the rule and this can then be read on the receiver rule (“1_hello_rule”) with “Retrieve context attributes passed by a calling rule/script” Rules Blockly - Run & Process and Transformations | openHAB

Is this what you are looking for?

The other replies have shown you that yes, you can call another rule from a Blockly script with inputs. However…

You don’t get anything back. It’s not a function call with a return value. In fact, I don’t think it even waits for the called rule to finish before the “run rule or script” block returns.

If you want to get a value back in a reusable function, you’ll probably need to create a Blockly Library (under Developer Tools). See Tutorial: How To Write Block Libraries.

In JavaScript, which is what Blockly “compiles” into, the ^ operator is a bitwise XOR. 10 XOR 2 = 8.

Do you mean 10*10 (i.e. 10 to the power of 2)? You’ll need to use Math.pow.

1 Like

I’m using a transformation, so that I can have a drewpoint channel on my mqtt thing.

Maybe, depending on your binding, that’s also an alternative

Thank you, also interessting to know. However not solving my problem because i get no return from the second script/rule.

Thank you. Math.pow(x, y) is what i was searching for. I ended up using this and inline script!