Acces items on a widget from w rule

I have an understanding question to custom widgets.

I have a widget with 2 oh-input and one oh-button.

The 2 oh input were mapped to items. The oh Button sents a command to an Switch Item,which triggers a rule.

Now my question: is it possible to access the values of the oh-input Fields?
Every oh-input has a sent Button. If I activate it I can see in the logs that the linked Item is updated.
But I do not want to press the sent Button for every input field. I want to update all items with one Button click.

Yes. The oh-input has a variable which I believe is updated when the input changes, not just when the send button is clicked.

This, however, is not possible, to my knowledge. The command action of a single widget only accepts a single item and its command. There’s no way to command multiple different item with different commands from the widget.

Since you already have a rule that is associated with this widget, you could change things up just a little so that you have a proxy String item which collects the variables from the inputs and triggers the rule when its state changes. Then in the rule you can handle actually sending the input values to the relevant items.

But then, if I have multiple oh-input I have this variable multiple times. But how is this variables transfered to an item.

So were is the relationship between the input items on the widget, the proxy string and the rule.
Were is the string, also on the widget?

The variable property just lets you set the name of the variable that gets used by the component, so you just set two different variable names, such as itemCommand1 and itemCommand2, or whatever you want.

Create a button on the widget. Configure this button to send a command to the string item that contains the two variable values in a way that is easy to extract in the rule. For example, using the variable names up above, the command property might be:

command: =vars.itemCommand1 + "," + vars.itemCommand2

If the first variable is "ON" and the second variable is "OFF" then the string item will get the command "ON,OFF" and change its state accordingly.

Now you just need to configure the rule to run whenever the string item changes. Then, in the rule you can get the commands that you want to send to the two items from the state of the string item. In this case you would want to do something like use the split() method on the state string to separate it at the comma and have the two commands as elements in an array.

The way how to split the string into separate parts was not the.problem.
It was the understanding how to sent with a button a value to the variable.
But thanks a lot for the explanation.
I hop I understood it now. Will try it after work.

Ok, I’m not able to make it working
@JustinG maybe you can helb me.

Here is my wídget

                - component: oh-input-card
                  config:
                    #  item: =props.prefix+"_1"
                    name: myName
                    sendButton: false
                    type: Text
                    variable: _tst_StrInp_1

                - component: oh-button
                  config:
                    action: command
                    actionCommand: =vars._tst_StrInp_1
                    # actionItem: =vars._tst_StrInp_1
                    outline: true
                    style:
                      width: 100px
                    text: Sent

The both components were in diffrent rows. I do not copy the code.
When I enter code and press sent
i received the log message
2022-10-22 18:48:30.428 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn’t exist: undefined_1

_tst_StrInp_1 is a real openhab string item

So where is my Problem?
When I use the sent function from one input iot works

          - component: f7-col
            slots:
              default:
                - component: oh-input-card
                  config:
                    item: =props.prefix+"_2"
                    name: myName
                    sendButton: true
                    type: Text

in this case props.prefix = _tst_StrInp

You still need both the actionCommand and the actionItem properties. The command is the information you want to store in the string item but without actionItem the widget has no idea which item you want to send that information to.

Here’s a small demo. I have a string item with the name testString The state of testString starts as "Old title here". If you watch the card you can see that the lower text changes as I type in the input, but that’s the cardTitle variable getting changed with each change of the input. The title of the card,however, doesn’t change until I press the button which updates testString with the new input value.

uid: demo:input
tags: []
props:
  parameters: []
  parameterGroups: []
timestamp: Oct 22, 2022, 10:37:33 AM
component: f7-card
config:
  title: =items.testString.state
  footer: =(vars.cardTitle)?(vars.cardTitle):('Please enter a title in the input box')
slots:
  default:
    - component: oh-input
      config:
        type: text
        variable: cardTitle
        outline: true
    - component: oh-button
      config:
        text: Send String State
        action: command
        actionItem: testString
        actionCommand: =vars.cardTitle

input-demo

Ok, thank you very much. That is working.
Is there somewhere a doc about that-
I’ve read the oh-button - Button | openHAB
but from that the behaviour you showed to me was not clear.

But anyway. Thank you

The action documentation is the same in each of the component reference pages for components that have the action property so for the command action this is all you get:

action: command allows you to send a command actionCommand to an item, specified in the actionItem.

There’s a little more information in the Building Pages page of the docs, but it’s not specific to the command action.

1 Like