This page last changed on Dec 29, 2013 by dclaeys.

Hi,

I am currently experimenting with Rules (Crons,etc...)and
The Idea is to switch a light on for 10seconds:

  • from Monday to Friday at 07:00
  • from Saturday to Sunday at 09:00

I made 2 rules for it, with 2 times almost the exact code.
My question is if I can make it any shorter (in 1 rule) since its only the time (09:00 i.o 07:00) that is different.

This is my code below:

package org.openremote.controller.protocol

global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;
global org.openremote.controller.statuscache.LevelFacade levels;

import org.openremote.controller.protocol.*;
import org.openremote.controller.model.event.*;
import java.lang.Float;
import java.sql.Timestamp;
import java.util.Date;

rule "WakeUp_2-6"
timer (cron: 0 0 7 ? * 2-6)
when
eval(true)
then
execute.command("On");
try

Unknown macro: { Thread.sleep(10000); }

catch(InterruptedException ex)

Unknown macro: { Thread.currentThread().interrupt(); }

execute.command("Off");
end

rule "WakeUp_7-1"
timer (cron: 0 0 9 ? * 7-1)
when
eval(true)
then
execute.command("On");
try

}
catch(InterruptedException ex)

Unknown macro: { Thread.currentThread().interrupt(); }

execute.command("Off");
end
/******/


Rule2-6.GIF (image/gif)
Rule7-1.GIF (image/gif)

Sorry, something went wrong with the copying of my code:

Are my codes

Posted by dclaeys at Dec 29, 2013 07:55

Sorry, something went wrong with the copying of my code

For better readability you could enclose your code within {code}..{code} tags (see markup instructions). Do not place a / inside the end tag.

Posted by pz1 at Dec 29, 2013 08:45

Pieter,

Ok, Thanks, I will use it next time.
Any Idea if I can reduce/shorten it into 1 rule?

Regards,
Dieter

Posted by dclaeys at Dec 29, 2013 08:50

Sorry I am only a beginner with rules. I know very little about Java. I remember I've seen somewhere that the use of sleep can be dangerous, because it puts the execution of all rules on hold. (I am using Z-Wave switches that allow to program the delay before it switches off)

Posted by pz1 at Dec 29, 2013 08:59
Document generated by Confluence on Jun 05, 2016 09:39