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?
Thanks for the response!
I am also running on 5.1.3.
I was running on 0.4 but I think I made the previous breaking change manually.
Now, when I attempted to regenerate the rule it remained on 0.4 (tried 3 times). I then thought to delete the rule, remove the debounce rule template to force the download of 0.5. Sadly, I can no longer see it as rule template to download at all so cannot get it back
Any advice?
The behaviour I’ve been experiencing is the group itself would go OFF when debounced. However, the main Presence switch would remain ON.
I do have the below logs prior to all this testing:
16:27:42.559[WARN] [org.openhab.automation.rules_tools.Debounce] - event.type is deprecated, use event.eventName instead. If you use Blockly, simply resave the script.
16:27:42.560[WARN] [org.openhab.automation.rules_tools.Debounce] - event.type is deprecated, use event.eventName instead. If you use Blockly, simply resave the script.
16:27:42.563[DEBUG] [org.openhab.automation.rules_tools.Debounce] - Debounce: GroupItemStateChangedEvent item: gPresence
16:27:42.588[WARN] [org.openhab.automation.rules_tools.Debounce] - event.itemState is deprecated, use event.receivedState for update triggers or event.newState for change triggers instead.
16:27:42.589[WARN] [org.openhab.automation.rules_tools.Debounce] - event.itemState is deprecated, use event.receivedState for update triggers or event.newState for change triggers instead.
16:27:42.591[WARN] [org.openhab.automation.rules_tools.Debounce] - event.itemState is deprecated, use event.receivedState for update triggers or event.newState for change triggers instead.
16:27:42.594[DEBUG] [org.openhab.automation.rules_tools.Debounce] - Debouncing gPresence 's state OFF using proxy Presence timeout PT2M command true and states OFF
16:29:42.625[DEBUG] [org.openhab.automation.rules_tools.Debounce] - End debounce for gPresence state OFF with proxy Presence and isCommand true
16:29:42.633[TRACE] [org.openhab.automation.rules_tools.Debounce] - Debounce is complete for gPresence at trace (@jsscripting-globals.js:159) at endDebounceGenerator (:84) at (timerMgr.js:70) at callbackFn (actions.js:275)
As always any help would be greatly appreciated ![]()
There was a problem with the versioning in the title. I fixed that so it should show up now. If it doesn’t go to Settings → Com,munity Marketplace → Show Unpublished.
It is not clear what you did. The upgrade process depends on when you installed the rule template. If you installed it prior to OH 5.0 the process is as follows:
- Disable the old rule.
- Remove the rule template using the add-on store
- Reinstall the rule template (you may want to refresh the page first to ensure you are getting the latest)
- Create a new rule based on the template. You can use the “configuration” section of the disabled rule (click the code tab) to remember what you filled in for the properties.
If you installed after OH 5.0 the process is:
- Remove the rule template using the add-on store
- Reinstall the rule template
- Navigate to the rule(s) created from the template and click the “regenerate” button to rebuild the rule based on the new template. You’ll have the opportunity to change the parameters if you want. If you have more than one rule based on the template, you can select them all and regenerate them in one go.
That’s brilliant - got it back, thank you ![]()
This did it - thank you!
Back up and running. Though, those warnings still persist
i.e
event.itemState is deprecated, use event.receivedState for update triggers or event.newState for change triggers instead
Thank you so much for the quick response ![]()
There will be a 0.6 version eventually that will remove the deprecation warnings. It will continue to work in the mean time though.
