Pass parameters from a custom widget to a script

Context: I have a custom widget in which certain data is entered to later make a query (the script would come into play here)

Need: I need guidance or a simple example that I need to implement or install (add-ons) to be able to pass the data entered in my custom widget when I press a button to a script that is the one that performs the logic.

I don’t know if I need rules, install addons, what languages are supported … etc. My intention is for that script to generate a file and place it on the machine that runs oh.

Any type of recommendation orientation is welcome since I have not been able to locate anything that has made it clear to me how to do it. I have read some lambdas etc but am a bit disoriented right now.

Thank you.

Everything in OH comes down to Items. So pass what ever value is entered into the widget to an Item. When that Item changes or receives an update trigger a rule to do what needs to be done.

Note that the rule will be running on the same machine OH is running on.

Without more details this smells a whole lot like an XY Problem though. This use case is not one that comes up in a home automation context

1 Like

Pretty much you’r restricted to using an item. That’s the basic unit of information transfer in OH and the easiest to achieve. Take a look at the widget and code I posted for scene control and modification and you’ll see an example. The widget sets an item to a string containing an array of data and the rule parses that data from the array and then performs all the necessary work.

1 Like

Hi Rich, thank you for your response and guidance.

Indeed, it may seem like an XY problem, it usually occurs when trying to simplify a problem and it was not my intention, on the contrary, I wanted to facilitate the context and situation.

For more details, I want to use a widget to consult the information of an item by REST API in a time interval and generate a download file.

Hello again Justin, good to read to you.

Thank you very much for your answer and example.

You both have indicated the answer to me, so thank you very much to both @rlkoshak. I mark this comment as a solution because with the examples I think it will help other people and the forum more.

One more question @JustinG , in your answer it seems that there is some other possibility to do the step without using items? Or perhaps it is misinterpreted.

Again, thank you both for your help.

Sorry for the ambiguity in the answer. As Rich said, items are the basic unit of information control with OH. From a widget you can call a rule directly, but not also pass information to it.

There’s not even any reason to want to find a different way to solve this problem. An item to hold the data and trigger the rule is in line with the way OH is built to work so it’s the most efficient method anyway.

1 Like

Okay Justin.

Is it possible that the status of an item cannot be changed by pressing a button?
I am trying this to no avail.


          - component: oh-button
              text: Consultar
              outline: true
              action: command
              actionItem: =(items[props.item_queryValue])
              actionCommand: test2
              tooltip: =(items[props.item_queryValue].state)

The actionItem property does not take an object, just a string of the item name. So, in this case you only need:

actionItem: =props.item_queryValue
1 Like

You were right. Thanks again.