# ButtonON: button widget to send ON commands to an item

**URL:** <https://community.openhab.org/t/buttonon-button-widget-to-send-on-commands-to-an-item/138629>\
**Category:** UI Widgets\
**Tags:** stable, published\
**Created:** [September 4, 2022, 9:10am UTC](https://community.openhab.org/t/buttonon-button-widget-to-send-on-commands-to-an-item/138629 "2022-09-04T09:10:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bernd\_Ritter](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@Bernd\_Ritter](https://community.openhab.org/u/Bernd_Ritter)\
**Post date:** [September 4, 2022, 9:10am UTC](https://community.openhab.org/t/buttonon-button-widget-to-send-on-commands-to-an-item/138629/1 "2022-09-04T09:10:46Z")

</div>

![ButtonOn](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/1/c/1c11e663adad15125bf8fff3114f2ee0cfd9bdb5.jpeg)

A simple button widget that sends ON commands to an item.  
Typical use case is that a rule gets triggered when the item state changes to ON and at the end of the rule, the item state will be set back to OFF.  
The label on the button can be configured, as well as the TITLE.

## Screenshots

I use this to control the roller shutter automation in my house:

 ![AutomationPage](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/3/6/369512c49418c446042f177cf0c3e2f08587d259.jpeg)

## Changelog

### Version 0.1

- initial release

## Resources

```yaml
uid: ButtonOn
tags: []
props:
  parameters:
    - context: item
      description: Item to use with this button.
      label: Item
      name: item
      required: true
      type: TEXT
      groupName: general
    - description: Text to show on the button.
      label: Button
      name: Button
      required: false
      type: TEXT
    - description: Text to show as title.
      label: Title
      name: Title
      required: false
      type: TEXT
  parameterGroups:
    - name: general
      label: Display options
timestamp: May 13, 2021, 9:25:53 AM
component: f7-card
config:
  title: '=(props.Title) ? props.Title : "Title"'
slots:
  default:
    - component: f7-block
      config:
        class: bog
        style:
          display: flex
          flex-wrap: wrap
          justify-content: space-between
          align-content: space-between
          padding: 20px
      slots:
        default:
          - component: oh-button
            config:
              text: '=(props.Button) ? props.Button : "Start"'
              outline: true
              actionItem: =(props.item)
              actionCommand: "ON"
              action: command
              active: =(items[props.item].state === 'ON')
              style:
                width: 100px

```

---

<div class="post-metadata">

**Author:** ![the-ninth](https://community.openhab.org/user_avatar/community.openhab.org/the-ninth/32/95557_2.png) [@the-ninth](https://community.openhab.org/u/the-ninth)\
**Post date:** [January 20, 2023, 5:25pm UTC](https://community.openhab.org/t/buttonon-button-widget-to-send-on-commands-to-an-item/138629/2 "2023-01-20T17:25:40Z")

</div>

Seems the version on the market place has a bug - the actionCommand is not as shown above set to “ON” but set to “true” and thus the button does not work.

To fix this, I created a version that makes the command configurable, so it can be used to send both ON or OFF or any other command.

```auto
uid: CommandButton
tags:
  - button
props:
  parameters:
    - description: Text to show as title.
      label: Title
      name: title
      required: false
      type: TEXT
      groupName: display
    - description: Text to show on the button.
      label: Button
      name: button
      required: false
      type: TEXT
      groupName: display
    - context: item
      description: Item to use with this button.
      label: Item
      name: item
      required: true
      type: TEXT
      groupName: item
    - description: Command to send to the item.
      label: Command
      name: command
      required: true
      type: TEXT
      groupName: item
  parameterGroups:
    - name: display
      label: Display Options
    - name: item
      label: Item and Command
timestamp: Jan 20, 2023, 5:20:33 PM
component: f7-card
config:
  title: '=(props.title) ? props.title : "Title"'
slots:
  default:
    - component: f7-block
      config:
        class: bog
        style:
          display: flex
          flex-wrap: wrap
          justify-content: space-between
          align-content: space-between
          padding: 20px
      slots:
        default:
          - component: oh-button
            config:
              text: '=(props.button) ? props.button : "Start"'
              outline: true
              actionItem: =(props.item)
              actionCommand: =(props.command)
              action: command
              active: =(items[props.item].state === (props.command))
              style:
                width: 100px

```

---

<div class="post-metadata">

**Author:** ![Bernd\_Ritter](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@Bernd\_Ritter](https://community.openhab.org/u/Bernd_Ritter)\
**Post date:** [January 21, 2023, 6:18am UTC](https://community.openhab.org/t/buttonon-button-widget-to-send-on-commands-to-an-item/138629/3 "2023-01-21T06:18:27Z")

</div>

> [@the-ninth](#):
>
> Seems the version on the market place has a bug - the actionCommand is not as shown above set to “ON” but set to “true” and thus the button does not work.

Damn, you are right! How can I fix this?

---

<div class="post-metadata">

**Author:** ![the-ninth](https://community.openhab.org/user_avatar/community.openhab.org/the-ninth/32/95557_2.png) [@the-ninth](https://community.openhab.org/u/the-ninth)\
**Post date:** [January 21, 2023, 7:27am UTC](https://community.openhab.org/t/buttonon-button-widget-to-send-on-commands-to-an-item/138629/4 "2023-01-21T07:27:54Z")

</div>

> [@Bernd\_Ritter](#):
>
> Damn, you are right! How can I fix this?

No idea - I am new to this and just started to create my own widget. I just put online a version derived from yours where the command can be specified, since I needed the widget to be able to send different commands for different scenarios. But I do not know yet how to update a published widget once it is on the market place. 🙈

> [@CommandButton: button widget to send a command to an item](https://community.openhab.org/t/commandbutton-button-widget-to-send-a-command-to-an-item/143604):
>
> This widget is derived from the [ButtonON](https://community.openhab.org/t/buttonon-button-widget-to-send-on-commands-to-an-item/138629) widget from @Bernd_Ritter. It adds the option to specify the command that is sent to the item when the button is activated. The button will remain in a visual activation stage filled with color as long as the item remains in that state. Screenshots Example: Example when active: Configuration of the example: Changelog Version 0.1 initial release Resources The YAML code for the widget…

---

<div class="post-metadata">

**Author:** ![ysc](https://community.openhab.org/letter_avatar_proxy/v4/letter/y/e480ec/32.png) [@ysc](https://community.openhab.org/u/ysc)\
**Post date:** [January 22, 2023, 2:34pm UTC](https://community.openhab.org/t/buttonon-button-widget-to-send-on-commands-to-an-item/138629/5 "2023-01-22T14:34:41Z")

</div>

Regarding the previous issue. There’s a stupid reason why this happens…  
The YAML 1.1 spec thought a good idea to say that `ON` is a valid representation of the `true` boolean.  
See [Boolean Language-Independent Type for YAML™&nbsp;Version&nbsp;1.1](https://yaml.org/type/bool.html)  
As you can see the same is true for all these:

```auto
 y|Y|yes|Yes|YES|n|N|no|No|NO
|true|True|TRUE|false|False|FALSE
|on|On|ON|off|Off|OFF

```

When you install the widget from the marketplace the library that does the parsing complies with this so your `actionCommand: ON` will be transformed to `"actionCommand": true` in JSON.  
This doesn’t happen in the UI because the client-side library doesn’t honor this part of the spec.

So when using the above in marketplace entries make sure you use quotes i.e. `commandAction: "ON"` (which the UI will happily remove… so you can use for instance `commandAction: ="ON"`)

---

<div class="post-metadata">

**Author:** ![Bernd\_Ritter](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@Bernd\_Ritter](https://community.openhab.org/u/Bernd_Ritter)\
**Post date:** [February 5, 2023, 11:57am UTC](https://community.openhab.org/t/buttonon-button-widget-to-send-on-commands-to-an-item/138629/6 "2023-02-05T11:57:16Z")

</div>

Can someone confirm that the version online is really fixed?  
I just deleted the widget from my OpenHAB and readded it from the marketplace.  
It still has  
actionCommand: true
