I implemented the code exactly as on your Github page (java code), got the timer_mgr and time_utils installed and created items exactly as with your Github example (did change the names though).
However, my mainPresence item, witch is the proxy, does never switch to the OFF state (I set 5 mins as a start). Nothing shows up in the logs. Any ideas?
I have installed the Items 3 times now, just in case I messed up the metadata part of things but to no avail.
I figured, if the rule is broken or incorrect copied or an item is missing metadata, it will through an error. However, there is nothing in the log so I wandered where else the problem might lie.
The Java-version I got from @rlkoshak s Github page is, I think, the newest. I just got it a few days ago. The TimeOfDay rule works fine, also from his Github page.
You mean JavaScript? JavaScript is most decidedly not Java.
Show what youâve done. If you did things exactly right things would be working. Without seeing what youâve actually doneâŠ
Itâs confusing and I really need time to rework all of these tutorials. The Python versions and Rules DSL versions in all my tutorials and DPs are OH 2.5 only. The JavaScript versions are all OH 3 only.
Thatâs useful information. It shows you have timeUtils.js and timerMgr.js installed correctly. So there is either something wrong with how you set up the debounce rule or the Items. Did you create the Debounce Group Item? Are all the ârawâ Items members of the Debounce Group? What is the metadata used on each Item?
But did you create a Group called Debounce and add gPresence to that? From the readme for Debounce:
JavaScript
This code does not depend on the openHAB Helper Libraries. All Items that need to be debounce need to be added a to a Group named Debounce. When any member of that Groupâs state changes the rule will trigger to debounce the Item based on the metadata.
Thatâs how the rule knows to run. The debounce rule is triggered by changes to members of Debounce. All Items with the debounce metadata need to be a member of the Debounce Group.
Just one small thing: Script execution of rule with UID âPRESENCE-1â failed: The name âlogNameâ cannot be resolved to an item or type; line xx, column yy, length 7 in PRESENCE
I had a bit different setup: My presence is signaled through contacts, so I had to rewrite group and rules to fit it as OFF and CLOSED are not compatibleâŠ
rule "Set presence"
when
Item GP_Presence_Contacts changed
then
if((GP_Presence_Contacts.state == CLOSED && Presence.state == OFF) || (GP_Presence_Contacts.state == OPEN && Presence.state == ON))
{
logInfo("presence", "presence and contacts are in sync")
if(Presence_Timer.state == ON)
{
logInfo("presence", "cancel timer as we currently don't need it as items are yet in sync")
Presence_Timer.postUpdate(OFF)
}
else
{
logInfo("presence", "no timer running and items in sync, nothing to do anymore")
return;
}
}
if(GP_Presence_Contacts.state == OPEN)
{
logInfo("presence", "Somebody present!")
Presence.sendCommand(ON)
}
else
{
logInfo("presence", "Nobody present, setting timer")
Presence_Timer.sendCommand(ON)
}
end
rule "Expire presence"
when
Item Presence_Timer received command OFF
then
logInfo("presence", "Timer expired, still nobody present")
Presence.sendCommand(OFF)
end
I was dealing with presence detection on my OH 2.5 installation in the past and Iâm just setting up OH3 from scratch (3.2.0 - Release Build).
@rlkoshak Thank you for this great tutorial and the updated best practice for OH3. While creating the Debounce rule based on your rule template I think I missed something because when I trigger the rule in Main UI I get this error:
2022-01-07 18:13:52.646 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID âfccb09a5c1â failed: ReferenceError: âeventâ is not defined in at line number 198
The items I created in my .item file according to your very good description.
May you have an idea what I did wrong?
How are you triggering it? Just clicking the âplayâ button? There is nothing to debounce when you do that. There is no Item that has changed state. You need to have the rule triggered by an Item event.
Thank you for your quick response â yes, I triggered via âplayâ button. I thought with that I could test my configuration â my mistake. Now I tested via setting all presence sensors to OFF. Unfortunately now I get the following error:
2022-01-08 13:02:52.593 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID âfccb09a5c1â failed: PresenceAndi does not have a timeout parameter defined! Debounce metadata should follow debounce=ProxyItem[command=true, timeout=â2sâ, state=âON,OFFâ]. in at line number 155 at column number 4
But timeout parameter is defined - just copied from your example:
Evans debug logging for the rule out manually edit the code to change the debug logs to info. I think that will log out the metadata pulled from the item. If not, add a line to log out exactly what metadata was pulled from the item.
To get the debug logging, in Karaf console I set the logger for org.openhab.model.script.Rules.rules_tools. Triggering the rule once more I only got this output:
2022-01-08 19:44:50.539 [DEBUG] [el.script.Rules.rules_tools.TimerMgr] - Building timerMgr instance.
2022-01-08 19:44:50.555 [DEBUG] [el.script.Rules.rules_tools.TimerMgr] - Timer Mgr is ready to operate
Therefore I added the last line in this code snippet to log metadata:
var checkMetadata = function(itemName, timers) {
var USAGE = "Debounce metadata should follow debounce=ProxyItem[command=true, timeout='2s', state='ON,OFF']."
var cfg = MetadataRegistry.get(new MetadataKey("debounce", itemName));
logger.debug("Debounce " + cfg);
...
It seems to be treating the config part of the metadata as part of value.
Frankly, I stopped using. items files a year ago now and I couldnât say why is not seeing the config part (i.e. the stuff in []) as separate like its supposed to. But thatâs the problem. The value is AndiPresence[timeout=â5mâ, states=OFF, command=true] and there config is empty. The value should be AndiPresence and the config should be [timeout=â5mâ, states=OFF, command=true].
Unfortunately Iâm out of the business of solving syntax errors in text config files so Iâm not going to be much further help. All I can say is it looks right but something is wrong with the metadata.
@JimT Thank you for the right syntax, that did the trick! Now the debounce rule is running properly on my installation. @rlkoshak Nevertheless thanks for your support. Interesting to read that you seem to move completely away from text config files, if I am not mistaken. Perhaps an option also for me, after I got a better understanding of all the concepts in OH 3. But this is another discussion and off topic.
The tl;Dr is that even though itâs slightly less effecient to point and click or use the API Docs, the time lost is dwarfed by the time lost to solving syntax errors like this and having to keep looking stuff up in reference docs. Itâs frustrating fighting problems that simply donât exist when using the UI and I find it a better user of my time to help solve home automation problems rather than syntax errors.