ButtonON: button widget to send ON commands to an item

ButtonOn

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:

Changelog

Version 0.1

  • initial release

Resources

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

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.

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

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. :see_no_evil:

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™ Version 1.1
As you can see the same is true for all these:

 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")

3 Likes

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