Idea / Feature request: Confirmation step during rule execution

Tags: #<Tag:0x00007f616ec80538> #<Tag:0x00007f616ec803d0> #<Tag:0x00007f616ec80240>

I’m using OpenHAB for a few years now, and I have quite a few items and rules running.
But when I make up new usecases, a lot of times I’m not able to implement them because they don’t ALWAYS apply.

Quite often I would like the system to ask me if I want it to do something, for instance:

  • I want to arm the alarm since I don’t detect any phones, is that ok?
  • Hey you’re home, you want me to set the thermostat and turn on the radio?
    I can see this as some popup window with yes and no buttons on my phone, or more exotic, the question playing on my Sonos and using voice control to answer the questions.

I quess this is something that needs to be in the runtime to use in a rule, the api and implemented in the apps.

But I would hope I’m not the only who would like to use this, and it would make a smarthome even smarter :slight_smile:

Not necessarily. This is really a UI question and we all know that the built in UIs are pretty basic in some areas. However, if you take advantage of the REST API (or MQTT or whatever) and some third party app to ask for the confirmation or at least kick off some code (scripts,or OH rules, etc.) to ask for the confirmation. For example, when my phone detects I’m driving and I cross into my home geofence Tasker pops up a dialog asking if I want to open the garage.

This works great for this use case because my phone is mounted in the car and in all the cases where I will want to confirm the action I will see it and can easily confirm and in all others it will simply time out.

In the case of the Sonos working pretty well now. Write a rule that triggers on the presence update, sends the voice to the Sonos, waits a certain amount of time for the voice to set a switch based on your response, if then proceed based on that response.

All that being said, I can see something built into the phone apps being useful in some contexts.

Good to know there is a workaround using Tasker (I will try this myself).

But it’s basicly stepping out of OpenHAB to achieve this effect and on the other big mobile platform (iOS) there is no Tasker.

I got the idea from this btw: https://www.athom.com/

I also would like an optional timeout on the confirmation, that if you don’t respond in x seconds / minutes the rule execution just continues.

I think there are similar, if much less capable apps on iPhone that can do the same. I experimented with a few and was able to do a lot. The biggest problem was I needed to be able to interact with OH when not at home and iPhone will not allow you to use a URL with the simple auth user/password as part of the URL. But it worked great on the local network.

Also, I don’t know that stepping outside of OH is in and of itself a bad thing. There are many many things that a dedicated team focused on solving that particular problem (e.g. voice control) will always be able to do far better than OH ever will. So stepping out of OH to utilize those services is a good thing.

I gave the Tasker example mainly because that is what I use. I can also envision an approach using an SMS/email/pushbullet/etc. confirm/response sequence. The approach would be similar to my Sonos description above.

Actually you would need to configure whether the rule just continues or exits. For example, in my use case I do not want the garage door to open unless it is confirmed.

This idea sounds simple but there are a lot of complications involved.

  • Is it really all that user friendly to have a pop-up on your phone, a device that is usually in your pocket, for confirmation? What I do with Tasker works for me because when the pop-up does show up I’m already looking at my phone but that would not be convenient or desirable in all situations.
  • Given that most people have their phone in their purse or pocket, there would also need to be some sort of alert sound/vibration to inform the user that a confirmation is requested.
  • For voice, does it make sense to provide the hooks to the rules to enable confirmations but rely on external devices/services (At Home, Echo, Tasker, etc) to provide the confirmation?
  • How do you handle multiple devices? I don’t really want my wife’s phone to buzz, make a noise, or talk to her every time I open the garage door. This almost requires most of the logic to be implemented in the OH phone apps which creates an even more complicated interaction between rules and the apps.

From a rules perspective, I can see it implemented as an action (or just implemented manually as I did below in a lambda). It would consist of an alert message sent to an Item, a busy wait loop that checks for a response on an Item, a timeout for when the response isn’t received on time, and a return value indicating whether the action was confirmed or not.

NOTES: Lambdas do not support return values (as far as I can tell) so I use a global. This can probably be made prettier in the new OH 2 rules. This was just typed in. I’m not sure the syntax or even the logic is completely right but the concept should work.

var boolean confirmed = false
val Functions$Function4 confirm = [ ItemType requestItem, String requestMsg, SwitchType confirmed, int timeoutMsec |
    confirmed.postUpdate(OFF)
    requestItem.sendCommand(requestMsg)
    var stopTime = now.millis + timeoutMsec
    while(confirmed.state != ON && now.millis < stopTime) {
        Thread::sleep(250)
    }
    if (confirmed.state == ON) confirmed = true
]

// Somewhere in a rule
    confirm.apply(MyRequestItem, "Do you want to open the garage?", MyConfirmRequestItem, 30000)
    if(confirmed) {
        // open the garage
    } else {
        // don't open the garage
    }

You can return values by just putting the return value on the last line in the lambda function. I have used this to return strings as well as boolean.

Odd. I’ve never actually been able to make that work. I always got a null pointer exception when I tried it. I must have been doing something else wrong. Thanks for the tip.