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 ![]()
NOTE: Iām on the latest version of the rule by updating from template library ![]()
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);
};
};
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.
On it now, report back ASAP ![]()
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.
Iāll do exactly that, refresh so that I have the latest version with all the logs ![]()
Thank you once again for the quick responses and guidance - very much appreciated! ![]()
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! ![]()
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?
