This page last changed on Feb 16, 2015 by mschrauf.

I can not explain why the following rule is called every full and half hour.

rule "PresenceOn"
when
Event(source=="PresenceSensor", value=="on")
then
log("PresenceOn");
end

The log-file looks like this:
INFO 2015-02-15 18:00:06,951 : PresenceOn
INFO 2015-02-15 18:30:05,424 : PresenceOn
INFO 2015-02-15 19:00:06,792 : PresenceOn
INFO 2015-02-15 19:30:05,351 : PresenceOn
INFO 2015-02-15 20:00:07,970 : PresenceOn

The command is an http call, which runs every 2 seconds.

And the sensor is a switch.

Actually, this is pretty simple. But the 30-minute re-call is not wanted. Is there a solution for this?


Event.JPG (image/jpeg)
sensor.JPG (image/jpeg)

It seems that your sensor has glitches every 30 minutes and these trigger the rule. You can check this by adding a rule:

rule "PresenceNotOn"
when
  Event(source=="PresenceSensor", value!="on")
then
  log("PresenceNotOn");
end

You can prevent from triggering a rule on (short) sensor glitches by using timer(int: {delay}) as long as {delay} is longer than the glitch.

Posted by aktur at Feb 17, 2015 10:03

It seems as you're right. Even though I still can't explain it.

Now I have four rules:

rule "PresenceOn"
when
	Event(source=="PresenceSensor", value=="on")
then
	log("PresenceOn");
end
rule "PresenceOff"
when
	Event(source=="PresenceSensor", value=="off")
then
	log("PresenceOff");
end
rule "PresenceNotOn"
when
	Event(source=="PresenceSensor", value!="on")
then
	log("PresenceNotOn");
end
rule "PresenceNotOff"
when
	Event(source=="PresenceSensor", value!="off")
then
	log("PresenceNotOff");
end

The log-file looks like this:

INFO 2015-02-17 19:00:03,570 : PresenceNotOff
INFO 2015-02-17 19:00:03,572 : PresenceNotOn
INFO 2015-02-17 19:00:07,627 : PresenceNotOff
INFO 2015-02-17 19:00:07,627 : PresenceOn

I don't understand how it happens that these rules are triggered if the sensor value certainly does not change.

Do you think this solves the problem:

rule "PresenceOn"
	timer (int: 10s)
when
	Event(source=="PresenceSensor", value=="on")
then
	log("PresenceOn");
end
Posted by mschrauf at Feb 17, 2015 18:20
timer (int: 10s)

Unfortunately, this has no effect, except that the rule is invoked 10 seconds later.

INFO 2015-02-18 01:00:03,944 : NotPresenceOff
INFO 2015-02-18 01:00:03,945 : NotPresenceOn
INFO 2015-02-18 01:00:09,096 : NotPresenceOff
INFO 2015-02-18 01:00:19,096 : PresenceOn         <-- 10s delay
INFO 2015-02-18 01:30:03,057 : NotPresenceOff
INFO 2015-02-18 01:30:03,057 : NotPresenceOn
INFO 2015-02-18 01:30:08,193 : NotPresenceOff
INFO 2015-02-18 01:30:18,192 : PresenceOn         <-- 10s delay
INFO 2015-02-18 02:00:03,661 : NotPresenceOff
INFO 2015-02-18 02:00:03,662 : NotPresenceOn
INFO 2015-02-18 02:00:08,801 : NotPresenceOff
INFO 2015-02-18 02:00:18,799 : PresenceOn         <-- 10s delay
INFO 2015-02-18 03:31:28,331 : NotPresenceOff
INFO 2015-02-18 03:31:28,331 : NotPresenceOn
INFO 2015-02-18 03:31:33,479 : NotPresenceOff
INFO 2015-02-18 03:31:43,479 : PresenceOn         <-- 10s delay
Posted by mschrauf at Feb 18, 2015 17:44

It seems that there is something wrong with your switch sensor as it takes state which is neither On nor Off. You can check this state with:

rule "PresenceX"
when
	Event(source=="PresenceSensor", $v:value)
then
	log("Presence"+$v.toString());
end

Anyway, to filter the glitch with timer() statement you need to create an In-memory virtual command (command: status) and a new switch sensor tied to this command. To filter it:

rule "Presence Filter"
	timer (int: 10s)
when
	Event(source=="PresenceSensor", $v:value)
then
	execute.command("In-memory virtual command's name", $v.toString() );
end

The new switch sensor will have all glitches up to 10s filtered out.

Posted by aktur at Feb 19, 2015 12:07

You're right. The sensor takes the state "N/A". How can that be possible?

INFO 2015-02-19 18:30:04,005 : Presence Value: N/A
INFO 2015-02-19 18:30:09,185 : Presence Value: on

But I think I have found a work-around:

declare Presence
  onPresence : boolean
end


rule "PresenceInsert"
when
	Event(source=="PresenceSensor", value=="on")
then
	Presence presence = new Presence();
	insert ( presence );
end


rule "PresenceRetract"
when
	Event(source=="PresenceSensor", value=="off")
	$presence : Presence()
then
	retract ( $presence );
end


rule "PresenceOn"
when
	exists Presence()
then
	Code...
	log("PresenceOn");
end


rule "PresenceOff"
when
	not Presence()
then
	Code...
	log("PresenceOff");
end

Posted by mschrauf at Feb 19, 2015 17:48
Document generated by Confluence on Jun 05, 2016 09:38