BasicUI momentary pushbutton to trigger something

I wanted a single, momentary pushbutton to appear in BasicUI. When pressed it would trigger a spoken report of today’s events; its appearance should be stateless (i.e. does not indicate on or off). BasicUI does not appear to offer a momentary pushbutton. A Switch (indicating on/off) is not the appropriate UI control for my purpose.

I cobbled together something that produces the effect I want. I doubt it’s an original idea and there may be a more elegant way to do it; I’m open to suggestions.

To create a solitary, momentary pushbutton, I used the following:

  1. Switch

  2. Mappings

  3. Expire Binding

The Item is defined like so (this is an abbreviated version of it) using “expire”:

Switch Scenes_ReportEvents "Report Events"  {mqtt=">[broker:scenes/reportevents/play:command:*:MAP(ON1OFF0.map)]", expire="2s,command=OFF"}

In Sitemap it uses a Switch with “mappings” but with only one selection:

Switch item=Scenes_ReportEvents label="Report Events" icon="soundvolume" mappings=[ON="Speak"]

The result looks and behaves like I wish. Press “Speak” and it reports today’s events (without indicating on/off).

OpenHAB%20-%20Report%20Events%20-%20Pushbutton

Is this the usual way of accomplishing it or is there a better way?

EDIT

Appended the word “momentary” to pushbutton.

2 Likes

The best way to accomplish something is the first way that works, IMO - don’t fix it until it doesn’t :smiley:

I like it! Perfect use for the expire binding to implement a momentary pushbutton.

The only other way I can think of (and the way I implement my scene logic, is to use the rule that’s fired to set the state back to “OFF” on a toggle switch, after it’s done. But, this is actually cleaner and better-looking :slight_smile:

This is the usual way I’ve seen it done.

To take it to the next level you can use the visibility tag when you want a momentary button that says something different based on the state of some other Item. I use this for my garage door openers.

Switch item=aGarageOpener1 icon="garagedoorclosed" mappings=[ON=Open]  visibility=[vGarageOpener1 == CLOSED]
Switch item=aGarageOpener1 icon="garagedooropen"   mappings=[ON=Close] visibility=[vGarageOpener1 == OPEN]
Switch item=aGarageOpener2 icon="garagedoorclosed" mappings=[ON=Open]  visibility=[vGarageOpener2 == CLOSED]
Switch item=aGarageOpener2 icon="garagedooropen"   mappings=[ON=Close] visibility=[vGarageOpener2 == OPEN]

I won’t scar my wife by opening them right now but the button name changes to Close when the door sensor says the door is open and the icon changes to an opened garage door.

image

3 Likes

Hehe…

OK, I’ll run with what I’ve got; it seems to do the trick. Thanks for the example using “visibility”. I’ve been mining ThomDietrich’s repo for examples and this will also help me get my garage door into BasicUI.

Red Green: And men, remember, if the women don’t find you handsome, they should at least find you handy! :slight_smile:

2 Likes