Confirmation Button

Hi Guys,

i wonder if there is any way to show a confirmtion before execute a command after press a button?
at the habpanel i found a widget which do the job, but is there something for sitemaps?

just a simple Yes/No after pressing the garagedoor opener or the restart would be super nice to have.

thanks

You could do something like. Maybe use proxy Items and some rules.
You’d have to place a proxy on your sitemap instead of the real garage opener Item, so that clicking does not command it directly.
(You can update the state of the proxy to keep in line with the real thing)
A rule can trigger from command to proxy, and set another dummy Item to “Maybe” or something.
Meantime, you’ve got your sitemap proxy entry visibility= option set to disappear when the dummy is “maybe”.
And a substitute confirmation entry with yes/no buttons.
When a “yes” command arrives at dummy, have a rule send a command to your real garage opener.
And also set dummy to not-“maybe” to restore sitemap view.

as @rossko57 already noted i do this very often in sitemap to prevent accidentally clicks.

see a rough overview (i work with jython):

the (proxy)-item in items-file

Number iViReset_OpenHAB

the sitemap:

	Switch item=iViReset_OpenHAB label="OpenHAB & 1Wire" icon="error" labelcolor=["black"] mappings=[1="! Reset !"] visibility=[iViReset_OpenHAB==0]
	Switch item=iViReset_OpenHAB label="Reset OpenHAB & 1Wire?" icon="confirm" labelcolor=["red"] mappings=[2="bestätigen", 3="abbrechen"] visibility=[iViReset_OpenHAB==1]
	Text item=iViReset_OpenHAB label="Reset OpenHAB & 1Wire[! ausgefĂĽhrt !]" icon="alarm" labelcolor=["red"] visibility=[iViReset_OpenHAB==2]

the py-file:

def confirm_function(item, befehl):
    retval = False

    if befehl == 1:
        postUpdateCheckFirst(item, "1")                                         # postUpdate manuell ausfĂĽhren falls autoupdate="false"
    elif befehl == 2:
        LogAction.logInfo(u"confirm_function", u"Bestätigt Funktion Item %s" % item)
        retval = True
    elif befehl == 3:
        LogAction.logInfo(u"confirm_function", u"Abbruch Funktion Item %s" % item)
        sleep(0.1)
        postUpdate(item, "0")
    elif befehl == 5:
        postUpdateCheckFirst(item, "5")                                         # postUpdate manuell ausfĂĽhren falls autoupdate="false"
    elif befehl == 6:
        LogAction.logInfo(u"confirm_function", u"Bestätigt Funktion Item %s" % item)
        retval = True
    elif befehl == 7:
        LogAction.logInfo(u"confirm_function", u"Abbruch Funktion Item %s" % item)
        sleep(0.1)
        postUpdate(item, "4")
    elif befehl == 9:
        postUpdateCheckFirst(item, "9")                                         # postUpdate manuell ausfĂĽhren falls autoupdate="false"
    elif befehl == 10:
        LogAction.logInfo(u"confirm_function", u"Bestätigt Funktion Item %s" % item)
        retval = True
    elif befehl == 11:
        LogAction.logInfo(u"confirm_function", u"Abbruch Funktion Item %s" % item)
        sleep(0.1)
        postUpdate(item, "0")
    elif befehl == 13:
        postUpdateCheckFirst(item, "13")                                        # postUpdate manuell ausfĂĽhren falls autoupdate="false"
    elif befehl == 14:
        LogAction.logInfo(u"confirm_function", u"Bestätigt Funktion Item %s" % item)
        retval = True
    elif befehl == 15:
        LogAction.logInfo(u"confirm_function", u"Abbruch Funktion Item %s" % item)
        sleep(0.1)
        postUpdate(item, "12")

    return retval

@rule("Init Technik",\
    description="Initialisierungen beim Systemstart verzögert ausführen",\
    tags=["Systemstart"])
@when("System started")
def init_technik(event):
    postUpdate("iViReset_OpenHAB", "0")

# **********************************************************
# *** Reset Raspberry Pi (Openhab)
# **********************************************************
def reset_openhab_body():
    postUpdate("iViReset_OpenHAB", "0")
    LogAction.logInfo(u"iJython_Busbefehl", u"Aktor 1/10 fĂĽr 10 Sekunden aktiviert - Reset Raspberry & 1wire")
    sendCommand("iJython_Busbefehl", "*#1*0110#4#01*#2*0*0*10##")                 # Aktor 1/10 fĂĽr 10 Sekunden aktiviert - Reset Raspberry & 1wire

@rule("Reset Openhab",\
    description=u"Reset Raspberry Pi (Openhab), incl. SicherheitsrĂĽckfrage")
@when("Item iViReset_OpenHAB received command")
def reset_openhab(event):
    item = event.itemName
    befehl = event.itemCommand.intValue()

    if confirm_function(item, befehl):
        ScriptExecution.createTimer(DateTime.now().plusSeconds(5), reset_openhab_body)

i want to add that i use the confirm_function quite often, because of that it uses more commands as needed for this example.

i think this is surely not the best solution, but for me it works quite good, maybe at least it points you a direction

I just use a Selection element. You have to click it to get the popup and then click the command you want to send, so it serves the same purpose as a confirmation button.

image

image

This example is with a string, but you can do it with a switch or contact.

1 Like

same here, using a popup in my widget:

popup

part of the YAML:

                - component: oh-link
                  config:
                    action: options
                    item: =[props.itemLock]
                    actionItem: =[props.itemLock]
                    actionOptions: ON=TĂśR Ă–FFNEN
                    style:
                      position: absolute
                      width: 100%
                      height: 100%
                      top: 0
                      left: 0