Debounce [4.0.0.0;5.0.9.9]

Not using a template. Templates can only be written as, installed through, and instantiated through MainUI.

Hi @rlkoshak

I’ve recently upgraded to OH5, prior to this my debounce rule was working perfectly.

I’ve noticed that my master proxy switch is not updating automatically on the specified interval (2 minutes). However, if I manually run the debounce rule it works. In addition, I’ve set the rule logs to debug and no errors are reported.

My setup is as per below:

Group:Switch:OR(ON,OFF) gPresence (Debounce) { debounce="Presence"[timeout="PT2M", states="OFF", command="True"] }

// Master Presence Switch
Switch Presence "Home/Away [MAP(presence.map):%s]"

// Phones

Switch Phone1 "Phone1" (gPresence) { channel="" }


Switch Phone2 "Phone2" (gPresence) { channel="" }

After gPresence is ā€œOFFā€œ but the master Presence switch remains ā€œONā€

12:25:02.933[DEBUG] [org.openhab.automation.rules_tools.Debounce] - End debounce for gPresence state OFF with proxy Presence and isCommand true

However, if I manually run the rule with gPresence ā€œOFFā€ :

12:28:42.663[DEBUG] [org.openhab.automation.rules_tools.Debounce] - There are 1 Items with debounce metadata
12:28:42.672[DEBUG] [org.openhab.automation.rules_tools.Debounce] - Item gPresence has debounce metadata
12:28:43.220[INFO] [org.openhab.automation.rules_tools.Debounce] - Updating Presence to OFF
12:28:43.233[INFO] [openhab.event.ItemStateChangedEvent] - Item 'Presence' changed from ON to OFF
12:28:43.238[INFO] [org.openhab.automation.rules_tools.Debounce] - All debounce Items are configured correctly

On the other hand once gPresence equals ā€œONā€ and manually run the rule:

12:41:44.758[DEBUG] [org.openhab.automation.rules_tools.Debounce] - There are 1 Items with debounce metadata
12:41:44.761[DEBUG] [org.openhab.automation.rules_tools.Debounce] - Item gPresence has debounce metadata
12:41:44.781[INFO] [org.openhab.automation.rules_tools.Debounce] - Updating Presence to ON
12:41:44.789[INFO] [openhab.event.ItemStateChangedEvent] - Item 'Presence' changed from OFF to ON
12:41:44.789[INFO] [org.openhab.automation.rules_tools.Debounce] - All debounce Items are configured correctly

Guess my end goal is as per original, if gPresence equals ā€œOFFā€ after 2 minutes should switch off master Presence switch.

Many thanks in advanced :slight_smile:

NOTE: I’m on the latest version of the rule by updating from template library :slight_smile:

When the rule is run manually, it only does an initialization. It checks the Item metadata for errors and synchronizes the states of the debounced Items with the Proxy Items. This occurs on every startup and when you run it manually.

So all running it manually tells us is that the Item’s debounce metadata is correct.

If you put the logger into TRACE level logging, immediately after that ā€œEnd debounceā€ log statement there should be either be a log statement saying ā€œCommandingā€ or ā€œDebounce is complete for gPresenceā€.

I need to know which of those two statements are being logged. Note, it should only log ā€œCommandingā€ when the gPresence state is different from Presence’s state. The code in question is:

var endDebounceGenerator = (name, state, proxy, isCommand) => {
  return function(){
    console.debug('End debounce for', name, "state", state, 'with proxy', proxy, 'and isCommand', isCommand);
    const isCurrState = (items.getItem(name).state == state);
    if(isCommand && !isCurrState) {
      console.trace('Commanding');
      items.getItem(proxy).sendCommand(state);
    }
    else if(!isCommand && !isCurrState) {
      console.trace('Updating');
      items.getItem(proxy).postUpdate(state);
    }
    console.trace('Debounce is complete for', name);
  };
};
1 Like

Thanks for the detailed response there @rlkoshak

It seems to be going to the final else which is very strange indeed:

15:00:58.280[DEBUG] [org.openhab.automation.rules_tools.Debounce] - End debounce for gPresence state OFF with proxy Presence and isCommand true
15:00:58.292[TRACE] [org.openhab.automation.rules_tools.Debounce] - Debounce is complete for gPresence at trace (@jsscripting-globals.js:146) at endDebounceGenerator (:82) at (timerMgr.js:70) at callbackFn (actions.js:275)

gPresence state is different to Presence’s state:

I’ve got a map to change the switch, it’s as follows:

OFF=Away
ON=Home
NULL=Unknown

As always thank you for your help!

The map doesn’t matter. that’s just for display.

The only way it can skip both the commanding clause and the updating is if isCurrState is true. That get set by the line:

const isCurrState = (items.getItem(name).state == state);

So that should only be true when the Proxy Item’s state matches the passed in state. Add a new console.debug statement or append to the existing ā€œEnd debounceā€ log statement to log out the Proxy Item’s current state in addition to the debounce state.

Thanks for the info, you’re right isCurrState is true:

15:53:44.812[DEBUG] [org.openhab.automation.rules_tools.Debounce] - End debounce for gPresence state OFF with proxy Presence and isCommand true
15:53:44.817[DEBUG] [org.openhab.automation.rules_tools.Debounce] - isCurrState: true
15:53:44.826[TRACE] [org.openhab.automation.rules_tools.Debounce] - Debounce is complete for gPresence at trace (@jsscripting-globals.js:146) at endDebounceGenerator (:83) at (timerMgr.js:70) at callbackFn (actions.js:275)

But I dont understand how that’s possible looking at them both they are different states completely. i.e. gPresence is OFF and Presence is ON……

That’s why I need you to log the state of the Item, not isCurrState. I already know isCurrState is true, I don’t know why.

console.debug(items.getItem(name).state

Sorry, logs as follows for the proxy item:

17:53:29.622[DEBUG] [org.openhab.automation.rules_tools.Debounce] - End debounce for gPresence state OFF with proxy Presence and isCommand true
17:53:29.627[DEBUG] [org.openhab.automation.rules_tools.Debounce] - ON
17:53:29.634[TRACE] [org.openhab.automation.rules_tools.Debounce] - Debounce is complete for gPresence at trace (@jsscripting-globals.js:146) at endDebounceGenerator (:84) at (timerMgr.js:70) at callbackFn (actions.js:275)

Well that doesn’t make a lot of sense.

Hmmmm.

Oh shoot! There’s a bug! How has this not been caught before now?

Please change the line where isCurrState is calculated to the following and let me know if that fixes it.

    const isCurrState = (items.getItem(proxy).state == state);

I.e. change ā€œnameā€ to ā€œproxyā€.

What we need to test is the state of the Proxy Item, not the debounce Item. Of course the debounce Item, matches the state. We wouldn’t be in this function if it didn’t.

1 Like

On it now, report back ASAP :slight_smile:

That’s done the trick @rlkoshak - thank you so much, great catch!

Logs now as follows:

18:08:40.439[DEBUG] [org.openhab.automation.rules_tools.Debounce] - End debounce for gPresence state OFF with proxy Presence and isCommand true
18:08:40.445[DEBUG] [org.openhab.automation.rules_tools.Debounce] - ON
18:08:40.451[TRACE] [org.openhab.automation.rules_tools.Debounce] - Commanding at trace (@jsscripting-globals.js:146) at endDebounceGenerator (:77) at (timerMgr.js:70) at callbackFn (actions.js:275)
18:08:40.459[INFO] [openhab.event.ItemCommandEvent] - Item 'Presence' received command OFF
18:08:40.461[INFO] [openhab.event.ItemStateChangedEvent] - Item 'Presence' changed from ON to OFF
18:08:40.462[TRACE] [org.openhab.automation.rules_tools.Debounce] - Debounce is complete for gPresence at trace (@jsscripting-globals.js:146) at endDebounceGenerator (:84) at (timerMgr.js:70) at callbackFn (actions.js:275)

Excellent, I’ve already staged the fix. In a little bit reinstall the template and refresh your rule(s) using the great new refresh feature in OH 5 to pick up the changes.

Or just continue running with your fixed version. All I’m changing is that one line and the log statement above it to also log out the proxy Item’s state.

1 Like

I’ll do exactly that, refresh so that I have the latest version with all the logs :slight_smile:

Thank you once again for the quick responses and guidance - very much appreciated! :slight_smile:

Hi @rlkoshak noticed that this automation addon no longer seems to work for 5.1+.

My use case hasn’t changed from the original debounce group / proxy item.

Are you looking to maintain this going forward or do I go down another route?

Many thanks! :slight_smile:

I’m still maintaining it, and it’s still working for me on 5.1.3.

Please verify you are running the latest version (you can find the version in the first line of the scriopt action). It should be 0.5.

What specifically is ā€œno longer seems to workā€? Errors in the logs? Silently fails? Does the wrong thing?