How to pass a parameter to DSL-script/rule

  • Platform information:
    Openhab version 4.1.3 on ubuntu 20.04 LTS, x86_64.

I would like to send an email when some item reaches a treshold-value.
I installed the mail-binding and set it up. Then I made a script to send test-mails with just text. That works fine.
I made a test-script using Blockly. Since Blockly can’t send emails, I used “run rule or script with context” with my script to send the mail. That works fine for plain text.
Now I would like to send also the value of that item.
So I used the “context” of that “run rule or script”.
My problem is that I don’t know how to get that value in the mailer-script.

My mailer-script (plain text, DSL) :

val mailActions = getActions("mail","mail:smtp:b56b6b064a");
val success = mailActions.sendMail("someone@example.com", "subject  test", "body test");

Blockly :
openhab-blockly

Thanks.

Actually it can if you install the Block library: Mail Actions

You can install that from Add-on Store → Automation → Block Libraries.

In Rules DSL you don’t. Rules DSL doesn’t support receiving values passed into the script like that.

Your options are (in order of preference):

  • install and use the Block library and do away with the whole rule calling in the first place
  • implement the called rule using JS Scripting instead of Rules DSL
  • use the sharedCache to store the value in the calling rule and retrieve the value in the called rule

Thanks,
That was what I was looking for. Works like I wanted now, using the Block-library.