# OH4.2.0 oh-button actionVariable on multiple variables at once

**URL:** <https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262>\
**Category:** Beginners\
**Tags:** widget, oh-button, openhab4\
**Created:** [July 17, 2024, 12:00pm UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262 "2024-07-17T12:00:25Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_VG](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/2acd7d/32.png) [@Mark\_VG](https://community.openhab.org/u/Mark_VG)\
**Post date:** [July 17, 2024, 12:00pm UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/1 "2024-07-17T12:00:25Z")

</div>

Hi All

I am currently running on the latest OH4.2.0 SNAPSHOT

Is there anyway to easily apply the `actionVariableValue` to multiple variables at the same time?

I would like to do something like:

```auto
- component: oh-button
  config:
	action: variable
	actionVariable:
	  - testVariable
	  - DetailShow
	actionVariableValue: false
	clearVariable:
	  - ZZZ
	  - ZZZ
	large: true
	style:
	  background: rgb(220,220,220)
	  color: white
	  display: flex
	  height: 30px
	  left: 5px
	  position: absolute
	  top: 5px
	  width: 30px

```

I have also tried:

```auto
actionVariable: =['testVariable', 'DetailShow']

```

Both of these seem to ignore BOTH variables.

The following fo ra single variable does work:

```auto
actionVariable: testVariable

```

Hoping for a simple option that will not require a complete redo of the widget.

The array option does work for `clearVariable` however O need to set a default value and not clear the variable.

I will have to look and see what I can achieve with `oh-context` otherwise?

Thanks as always  
Mark

---

<div class="post-metadata">

**Author:** ![JustinG](https://community.openhab.org/user_avatar/community.openhab.org/justing/32/55948_2.png) [@JustinG](https://community.openhab.org/u/JustinG)\
**Post date:** [July 17, 2024, 3:33pm UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/2 "2024-07-17T15:33:38Z")

</div>

You have two options (that I can think of off the top of my head, there may be others). See this topic:

> [@Multiple Widget Actions](https://community.openhab.org/t/multiple-widget-actions/144327):
>
> Since the beginning of MainUI this question has cropped up with some regularity: Can I trigger more than one of the OH widget actions on a component with a single click? The answer has always, rightly, been: No, you can only define a single action for each component in a widget. This answer is not 100% true, there are ugly hacks that could allow a click on a link, for example, to trigger the actions of other components, but these are not truly supported nor even advised. The question (and def…

The main idea of that topic would certainly cover this use case; so, that’s one option. However, down at the end of the post, there’s a concluding paragraph on possible combinations of actions and it mentions that if you want multiple variables, you can just use a single object with multiple keys as the variable.

---

<div class="post-metadata">

**Author:** ![Mark\_VG](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/2acd7d/32.png) [@Mark\_VG](https://community.openhab.org/u/Mark_VG)\
**Post date:** [July 18, 2024, 6:14am UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/3 "2024-07-18T06:14:15Z")

</div>

Hi Justin

Thanks as usual, I do remember seeing that post, but didn’t thin of it.

> [@JustinG](#):
>
> However, down at the end of the post, there’s a concluding paragraph on possible combinations of actions and it mentions that if you want multiple variables, you can just use a single object with multiple keys as the variable.

> [@Multiple Widget Actions](https://community.openhab.org/t/multiple-widget-actions/144327/1):
>
> If you’re setting more than one variable then maybe it’s easier to make that variable an object with multiple keys.

Could you expand on that? I like that idea but have no idea how to do that? And how you would send the vale to all of the objects with keys?

I will play around with the first option in the meantime.

---

<div class="post-metadata">

**Author:** ![hmerk](https://community.openhab.org/user_avatar/community.openhab.org/hmerk/32/56432_2.png) [@hmerk](https://community.openhab.org/u/hmerk)\
**Post date:** [July 18, 2024, 6:55am UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/4 "2024-07-18T06:55:54Z")

</div>

> [@Mark\_VG](#):
>
> And how you would send the vale to all of the objects with keys?

The following is an example, how to set two keys with one button press:

```yaml
- component: oh-button
  config:
    action: variable
    actionVariable: objVar
    actionVariableValue:
    floor: =loop.floorArraySrc.name
    selectSection: SECTION2

```

And this one changes display style according to the keys:

```yaml
    display: '=vars.objVar ? (vars.objVar.selectSection=="SECTION2" &&
       vars.objVar.floor ) ? "" : "none !important" : "none

```

We make use of this heavily in the semanticHomeMenu widget series…

---

<div class="post-metadata">

**Author:** ![Mark\_VG](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/2acd7d/32.png) [@Mark\_VG](https://community.openhab.org/u/Mark_VG)\
**Post date:** [July 18, 2024, 7:25am UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/5 "2024-07-18T07:25:18Z")

</div>

> [@hmerk](#):
>
> The following is an example, how to set two keys with one button press:

Thank you @hmerk

Please could you explain how it works? I am still not clear how this would work if I need to set for example two variables `Variable1` and `Variable2` to `false`?

---

<div class="post-metadata">

**Author:** ![hmerk](https://community.openhab.org/user_avatar/community.openhab.org/hmerk/32/56432_2.png) [@hmerk](https://community.openhab.org/u/hmerk)\
**Post date:** [July 18, 2024, 7:28am UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/6 "2024-07-18T07:28:03Z")

</div>

> [@Mark\_VG](#):
>
> Please could you explain how it works? I am still not clear how this would work if I need to set for example two variables `Variable1` and `Variable2` to `false`?

```yaml
- component: oh-button
  config:
    action: variable
    actionVariable: objVar
    actionVariableValue:
    Variable1: false
    Variable2: false

```

```yaml
display: '=vars.objVar ? (vars.objVar.Variable1=="false" &&
       vars.objVar.Variable2) ? "" : "none !important" : "none

```

Should be what you are looking for…

---

<div class="post-metadata">

**Author:** ![Mark\_VG](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/2acd7d/32.png) [@Mark\_VG](https://community.openhab.org/u/Mark_VG)\
**Post date:** [July 18, 2024, 8:41am UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/7 "2024-07-18T08:41:56Z")

</div>

> [@hmerk](#):
>
> Should be what you are looking for…

Thank you.

When I save the widget, I end up with:

```auto
  - component: oh-button
    config:
      action: variable
      actionVariable: objVar
      actionVariableValue: null
      testVariable: false
      DetailShow: false

```

And the two variables are not set to false.

Does `objVar` need to be defined somewhere?

EDIT: Also tried:

```auto
                - component: oh-button
                  config:
                    action: variable
                    actionVariable: objVar
                    actionVariableValue:
                      testVariable: false
                      DetailShow: false

```

with no sucess.

---

<div class="post-metadata">

**Author:** ![Mark\_VG](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/2acd7d/32.png) [@Mark\_VG](https://community.openhab.org/u/Mark_VG)\
**Post date:** [July 18, 2024, 10:46am UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/8 "2024-07-18T10:46:58Z")

</div>

> [@JustinG](#):
>
> The main idea of that topic would certainly cover this use case; so, that’s one option.

I have got the following:

```auto
                - component: oh-button
                  config:
                    action: variable
                    actionVariable: testVariable
                    actionVariableValue: false
                    style:
                      pointer-events: none
                  slots:
                    default:
                      - component: oh-button
                        config:
                          action: variable
                          actionVariable: DetailShow
                          actionVariableValue: false
                          large: true
                          style:
                            background: rgb(220,220,220)
                            color: white
                            display: flex
                            height: 30px
                            left: 5px
                            position: absolute
                            top: 5px
                            width: 30px
                            pointer-events: auto
                          popupClose: .modal-in
                        slots:
                          default:
                            - component: f7-icon
                              config:
                                color: white
                                f7: clear_fill
                                style:
                                  color: black
                                  font-size: 20px
                                  margin: auto

```

Which works to set the `DetailShow` variable, but seems to take no action on the `testVariable`.

Not sure what I have wrong?

The full widget is as follows:

[ANT.txt](https://community.openhab.org/uploads/short-url/uTXDJdu7fgBpJ24hbnH8FdL09km.txt) (6.1 KB)

---

<div class="post-metadata">

**Author:** ![hmerk](https://community.openhab.org/user_avatar/community.openhab.org/hmerk/32/56432_2.png) [@hmerk](https://community.openhab.org/u/hmerk)\
**Post date:** [July 18, 2024, 11:34am UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/9 "2024-07-18T11:34:45Z")

</div>

Here is a working example :

```yaml
uid: widget_a21e11171f
tags: []
props:
  parameters:
    - description: A text prop
      label: Prop 1
      name: prop1
      required: false
      type: TEXT
    - context: item
      description: An item to control
      label: Item
      name: item
      required: false
      type: TEXT
  parameterGroups: []
timestamp: Jul 18, 2024, 1:33:46 PM
component: f7-card
config:
  title: '=(props.item) ? "State of " + props.item : "Set props to test!"'
  footer: '=vars.objVar ? vars.objVar.Variable1==="false" ? "Variable 1 = false" :
    "Variable1 not set" : "objVar not set"'
  content: =items[props.item].displayState || items[props.item].state
slots:
  default:
    - component: oh-button
      config:
        action: variable
        actionVariable: objVar
        actionVariableValue:
          Variable1: "false"

```

---

<div class="post-metadata">

**Author:** ![Mark\_VG](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/2acd7d/32.png) [@Mark\_VG](https://community.openhab.org/u/Mark_VG)\
**Post date:** [July 18, 2024, 12:18pm UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/10 "2024-07-18T12:18:53Z")

</div>

> [@hmerk](#):
>
> Here is a working example :

Thank you so much. I finally get it. Sorry about the lack of experience etc.

I will need to access my variables as `vars.objVar.Variable1` and `vars.objVar.Variable2`.

This is definitely a good solution. Thanks for clarifying.

---

<div class="post-metadata">

**Author:** ![JustinG](https://community.openhab.org/user_avatar/community.openhab.org/justing/32/55948_2.png) [@JustinG](https://community.openhab.org/u/JustinG)\
**Post date:** [July 18, 2024, 3:42pm UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/11 "2024-07-18T15:42:44Z")

</div>

> [@Mark\_VG](#):
>
> `actionVariableValue: null`

> [@Mark\_VG](#):
>
> And the two variables are not set to false.

> [@Mark\_VG](#):
>
> Not sure what I have wrong?

The issues you are having with both versions is because of the `false` value that you are trying to set. It is a quirk of the way the yaml system works, that false values are equivalent to no value when converted to json for processing. The example that @hmerk showed works because that false value is not a boolean `false`, but a string `'false'`. (The same problem actually arises with `0` sometimes in widgets because that is also a falsy value.)

In practice, setting a variable to false is no different than clearing the variable. So, it turns out, if the only time you are setting multiple variables is to set them all to false, then you don’t need any special widget constructions, just use the clear variable function which can, as you have noted, take a list of variable names.

The most reliable way to get around this issue if there’s some reason in your widget why an actual `false` value must be different than `undefined` is to work with strings such as `'true'` and `'false'` or something even more descriptive such as `'active'` and '`inactive'`. This complicates widget expressions a little because you have to actually test the variable value instead of just using the variable as a boolean directly (e.g., `(vars.dummy == 'active')` instead of just `vars.dummy`). The good news is with the now `oh-context` you can create a test function that is even easier to read (e.g., `fn.isActive(vars.dummy)`)

---

<div class="post-metadata">

**Author:** ![Mark\_VG](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/2acd7d/32.png) [@Mark\_VG](https://community.openhab.org/u/Mark_VG)\
**Post date:** [July 18, 2024, 5:16pm UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/12 "2024-07-18T17:16:23Z")

</div>

> [@JustinG](#):
>
> The issues you are having with both versions is because of the `false` value that you are trying to set. It is a quirk of the way the yaml system works, that false values are equivalent to no value when converted to json for processing.

Thanks Justin.

I am actually not using the results in an expression at this stage. I am displaying/logging them out to see what happens as I am trying to find the easiest way to visibility of some components to only be true when the component is active (you helped me with part of this some time ago).

Because I am logging them out I am pretty confident they are not actually being set to false (or undef). I have tested again without using `false` just to be 100% sure:

```auto
- component: oh-button
  config:
    action: variable
    actionVariable: objVar
    actionVariableValue:
      testVariable: notActive
      DetailShow: notActive

```

That being said I have a working option using @hmerk option after I realised that I had to use  
`vars.objVar.Variable1 ` syntax.

Just trying to work out whether that solution or your initial solution with the nested oh-button is better? I have not been able to get the nested button to work as I mentioned in Point 7 above?

Always appreciet your input and guidance.

---

<div class="post-metadata">

**Author:** ![JustinG](https://community.openhab.org/user_avatar/community.openhab.org/justing/32/55948_2.png) [@JustinG](https://community.openhab.org/u/JustinG)\
**Post date:** [July 19, 2024, 12:16am UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/13 "2024-07-19T00:16:41Z")

</div>

> [@Mark\_VG](#):
>
> Just trying to work out whether that solution or your initial solution with the nested oh-button is better? I have not been able to get the nested button to work as I mentioned in Point 7 above?

It seems that the problem is that you have both the components as `oh-buttons`. The second, nested, component must be an `oh-link`. The top one can be a button if you prefer.

I’m not 100% sure why it makes a difference whether the nested component is a link or a button, I can only guess that there’s something to do with the way the underlying f7 library handles the two.

---

<div class="post-metadata">

**Author:** ![Mark\_VG](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/2acd7d/32.png) [@Mark\_VG](https://community.openhab.org/u/Mark_VG)\
**Post date:** [July 19, 2024, 5:09am UTC](https://community.openhab.org/t/oh4-2-0-oh-button-actionvariable-on-multiple-variables-at-once/157262/14 "2024-07-19T05:09:44Z")

</div>

> [@JustinG](#):
>
> It seems that the problem is that you have both the components as `oh-buttons`. The second, nested, component must be an `oh-link`. The top one can be a button if you prefer.

Thanks Justin. That works great. I had tried bth as `oh-link` with no luck. Great to have it working 🙂
