This page last changed on Dec 01, 2013 by annesodom.

Hi,

Thank you for all the good job ! OpenRemote is a very nice UI...

I have sevral rules working allready working...

I would like to use cron with variables, I want to be able to set a sensor in UI to set an hour to activate a rule

is it possible to use a rule like :

rule "test"
timer (cron: 0 0 $hour ? * 2-6)
when eval(true) then
execute.command("dOn");
end

hour is a In virutal memory variable

How could I get this rule work ?

Thank's

Dominique


VHOUR.png (image/png)
VhourSlider.png (image/png)
addition.png (image/png)

Missing closing bracket ')' in the first clause ?

Posted by pz1 at Dec 01, 2013 20:05

This rule is ok when I replace $hour by 12 ie...

Can I use a variable in cron fonction ?

Thank's

Posted by annesodom at Dec 01, 2013 22:19

Argh, I hadn't looked at the cron expression itself. Afaik you cannot use a variable in the cron expression.

Posted by pz1 at Dec 02, 2013 07:34

;-(

Do you know how I could enter a value in the UI and get a cron action with this value ?

Posted by annesodom at Dec 02, 2013 08:51

Suppose that your variable resides in a virtual memory command VHOUR and you want the cron statement execute on this value. You will also need a time sensor (use TimeDate protocol to get hour, let's call it TDHOUR). The rule should be (not tested, so please let me know if it works):

rule "test"
  timer (cron:0 0 * ? * 2-6)
when
  CustomState(source=="TDHOUR", $v: value)
  CustomState(source=="VHOUR", value==$v)
then
  execute.command("dOn");
end
Posted by aktur at Dec 02, 2013 11:23

@ Michal: I'll give this a try later this week. I have been pondering on such a thing for quite a while. I am experimenting with starting laundromat and/or dish washer on a certain minimum level of solar energy production, while also setting a deadline for those tasks to be finished.
Thanks

Posted by pz1 at Dec 02, 2013 11:46

I tried this rule, but I could not get it work...
I have a slider with a VHOUR between 0 and 23,
I created a TimeDate sensor... tried with hh:mm and also only with hh

Nothing works...

What am I doing false ?

Thanks

Posted by annesodom at Dec 02, 2013 19:41

My example is for sensors of custom type. Make sure that you have the same.
Further you can take a look in log file if you see any errors during loading rules (boot.log).
By removing the test value==$v the rule should be triggered every hour regardless of sensor values, does it do that?
The DateTime protocol should be hh.

Posted by aktur at Dec 02, 2013 20:00

I can make a command formatted with hh.
You are right, I get an error when I create a virtual custom sensor :

XML Element : <sensor xmlns="http://www.openremote.org" id="663" name="TDHOUR" type="custom">
<include type="command" ref="394" />
<state name="hh" value="" />
</sensor>

What custom state idems do I have to create ?
Thanks

Posted by annesodom at Dec 02, 2013 21:12

Custom state values leave empty. This way the sensor will return just string which virtual command holds.

Posted by aktur at Dec 02, 2013 21:22

Thank you for all your advices... I tried this, but I get an error while creatign sensor in the log...

ERROR 2013-12-02 23:06:00,050 : Creating sensor failed. Error :
XML Element : <sensor xmlns="http://www.openremote.org" id="409" name="heure" type="custom">
<include type="command" ref="391" />
</sensor>
java.lang.NullPointerException:
at java.math.BigDecimal.<init>(BigDecimal.java:739)
at com.luckycatlabs.sunrisesunset.dto.Location.<init>(Unknown Source)
at org.openremote.controller.protocol.datetime.DateTimeCommand.<init>(DateTimeCommand.java:85)
at org.openremote.controller.protocol.datetime.DateTimeCommandBuilder.build(DateTimeCommandBuilder.java:112)
at org.openremote.controller.command.CommandFactory.getCommand(CommandFactory.java:164)
at org.openremote.controller.model.xml.Version20SensorBuilder.parseSensorEventProducer(Version20SensorBuilder.java:420)
at org.openremote.controller.model.xml.Version20SensorBuilder.build(Version20SensorBuilder.java:287)
at org.openremote.controller.deployer.Version20ModelBuilder.buildSensorObjectModelFromXML(Version20ModelBuilder.java:817)
at org.openremote.controller.deployer.Version20ModelBuilder.buildSensorModel(Version20ModelBuilder.java:663)
at org.openremote.controller.deployer.Version20ModelBuilder.build(Version20ModelBuilder.java:557)
at org.openremote.controller.deployer.AbstractModelBuilder.buildModel(AbstractModelBuilder.java:154)
at org.openremote.controller.service.Deployer.startup(Deployer.java:858)
at org.openremote.controller.service.Deployer.softRestart(Deployer.java:440)
at org.openremote.controller.service.Deployer$ControllerDefinitionWatch.run(Deployer.java:1324)
at java.lang.Thread.run(Thread.java:679)

I am trying to understand Openremote.... but I don't know java...
can you tell me something about this error ?

Posted by annesodom at Dec 02, 2013 22:12

I found why this error... wrong attribute in command...

So I have no error in log.

With only cron fonction, the rule fires

But when I compare my two values nothing happens ;-(

I create a label in designer to see the value of the virtual sensor : "TDHOUR"... but I can allways see Label Text and no value, so the rule cannot fire.

Thanks

Posted by annesodom at Dec 02, 2013 22:39

The not updating label of TDHOUR sensor is the first thing you should solve before returning to the rule.

Posted by aktur at Dec 03, 2013 09:12


@Dominique,
This puzzles me. I made an in memory virtual command VHOUR where the command is status, and defined a sensor type:custom using it. My PRO designer does not allow to make a slider with a sensor of type:custom.
How did you manage?

Posted by pz1 at Dec 03, 2013 12:33

My Raspberry seems to be out... I'll install all again and come back when it works again...

Pieter, I made a sensor form a virtual command type:range (0-23) for hours...

Posted by annesodom at Dec 03, 2013 15:37

I just installed my raspberry.. now it is working.

I tried this rule

rule "sliderhm"
timer (cron: 0 * * ? * *)
when eval(true)
then
execute.command("dOn");
end

This rule fires every minute...

Then I tried to modify the rule with 2 variables : TDHOUR (system hour) and VHOUR (manual sensor value)

rule "sliderhm"
timer (cron: 0 * * ? * *)
when
CustomState(source=="TDHOUR", $h:value)
CustomState(source=="VHOUR", value==$h)
then
execute.command("dOn");
end

I can see the two variables on the UI When I set them to the same time, the rule does not fire...

I had a look in the logs, no more errors...

Has somebody an idear ?

Is there a file where I can find more about the rules actions ?

Thanks

Posted by annesodom at Dec 03, 2013 22:39

As you said your VHOUR is a range type of device. IIRC CustomState is meant for sensors of type:custom only. So your rule tries to compare string with integer I guess. For integers you need to use LevelState which requires the following addition to your rule header:

global org.openremote.controller.statuscache.LevelFacade levels;

I assume the LevelFacade takes care of sensors of type level and range, but I do not know for sure.

The starting point of rules documentation is Designer 2.0 - Controller Rules. At the bottom of the page there is a link to the Drools manual. I think chapter 4 is the most interesting. The notion of the different facades should be added somewhere to the OpenRemote Controller Rules docs.

I am in the process of collecting good rule examples from the forum pages. (See My Pages - Scratch pads for a link to rules) You need to log in to the forum to read that space.

Posted by pz1 at Dec 04, 2013 08:08

Ok I tried to add the LevelState in the header...

I modified my rule in :

rule "sliderhm"
timer (cron: 0 * * ? * *)
when
CustomState(source=="TDHOUR", $h:Integer.valueOf(value))
CustomState(source=="VHOUR", value==$h)
then
execute.command("dOn");
end

It does not fire...

I take a look in the Drools manual, but it is a bit difficult for a newbie...

For the rules you want to collect, I can make a tuorial for a rule I actually use witch get lights off at sunset if a switch is on in the UI...

I am sorry but the actual discussion should not be your good rules examples because it does not fire yet !!!

Can you tell me how you have the code in an other color in your posts ?

Thank you

Posted by annesodom at Dec 04, 2013 22:35

I am not a programmer, and only know about rules from copying other examples. So I am not really the person to help you. So for what it is worth, I think at least the VHOUR thing should be a LevelState:

LevelState(source=="VHOUR", value==$h)

Can you tell me how you have the code in an other color in your posts ?

enclose your code within {code}..{code} tags (see markup instructions). Do not place a / inside the end tag!

Posted by pz1 at Dec 05, 2013 07:35

I don't know with LevelState, but when both sensors, TDHOUR and VHOUR are of type custom then the rule "test" works. I've just checked it on my eBox.

Posted by aktur at Dec 05, 2013 08:14

The reason I suggested LevelState was because Dominique uses a slider to set VHOUR. Slider needs a range type sensor, which returns an integer.

Posted by pz1 at Dec 05, 2013 09:19

I was unaware that you can set virtual command from slider. How you dot that? I.e. what is the write command?

Posted by aktur at Dec 05, 2013 11:43

Sofar I have only tested this on screen. The command I use is described earlier in this thread I made a slider for that and placed the slider and a label connected to the sensor on screen. If I move the slider I see the label value change.

Posted by pz1 at Dec 05, 2013 12:12

But in this comment you describe the read command which is status for in the memory virtual command. What I'm asking is how you can get value back from slider (by moving it) to virtual command. With other commands you use ${param} to get the value from a slider. However, for in memory you can only use on|off|status. ${param} is not allowed.
Or am I missing something... obviously

Posted by aktur at Dec 05, 2013 12:25

I made a command :
Protocol : In-memory Virtual Command
Command : status
Adress : time

I have a range sensor on this adress, and a slider on the sensor.

In my UI I have a label with the sensor, and it returns the "time" variable I set in my slider...

Posted by annesodom at Dec 05, 2013 12:43

I don't use ${param}, just status. It looks as if for the Virtual command, status is command and ${param} combined.

Posted by pz1 at Dec 05, 2013 12:54

Yes that's exactly it :
My slider gives me the value I chose back the In-Memory Virutal command with only the status command...

So I have my two values :

  • one comming from Date with H formatted
  • one comming from my slyder.

I get the same value, but probabbly not teh same format...

Posted by annesodom at Dec 05, 2013 13:39

Well, this is what I've done and it didn't work. Value wasn't changing, so I thought that I was doing something wrong... After you send the picture, EUREKA, need to reboot my eBox Now it is working. Would be nice to have a sensor which would indicate that reboot is necessary, could be used for the watchdog.

Posted by aktur at Dec 05, 2013 13:46

Try to change both sensors to the same type. In your case range.

Posted by aktur at Dec 05, 2013 13:50

I just discovered that LevelState does not exist; should be Level

Posted by pz1 at Dec 15, 2013 14:12

hi Pieter,

Thank's for giving me an anser....

I have been trying to get this rule fire !!! but I never succeeded...

I have allso tried to use integer in my rules but I allways get an error in boot.log ;-((

With your new information I Just tried this :

rule "sliderhm"
timer (cron: 0 * * ? * *)
when
CustomState(source=="TDHOUR", $h:value)
Level(source=="VHOUR", value==$h)
then
execute.command("dOn");
end

I have no error in the logs, but it does not work...

Posted by annesodom at Dec 15, 2013 15:07

Sorry my knowledge it to little to help. I am wrestling myself with some simple math operations on Level sensors.

Posted by pz1 at Dec 15, 2013 17:46

On further thought, reading older threads about rules, and reading this thread again, as your sensor is of type:range, I think you should use Range instead of Level

Range(source=="VHOUR", value==$h)

I don't know if this will bring you any further, as there may still be other problems in your rule. The usage of Range in my own rule did not make it work yet (:

Posted by pz1 at Dec 15, 2013 21:23

The problem is probably the fact that == operator does not work between strings and integers. A type conversion is necessary. This code should do the trick:

declare TDHOURint
  value: int
end

rule "Init TDHOUR"
when
  not TDHOURint()
then 
  insert(new TDHOURint(-1));
end

rule "Conv TDHOUR"
no-loop true
when
  CustomState(source=="TDHOUR", $h:value)
  $e: TDHOURint()
then
  $e.setValue(Integer.parseInt($h.toString()));
  update($e);
end
  
rule "sliderhm"
timer (cron: 0 * * ? * *)
when
  TDHOURint($h: value)
  Range(source=="VHOUR", value==$h)
then
  execute.command("dOn");
end
Posted by aktur at Dec 16, 2013 11:56

@Michal
May I hijack this thread for a related question on one of my solar energy rules? In principle it is simple. I just want to do some arithmatic on the range outputs of my two inverters

rule "Combine Solar Power"
when
   Range( source=="SolarPowerLevel", $w1 : value)
   Range( source=="SolarPowerLevel2", $w2 : value)
then
  CombinedSolarPower = $w1 + $w2;
  execute.command("VirtualCombinedSolarPower", CombinedSolarPower);
end

The log says:

ERROR 2013-12-15 22:07:14,750 : Rule Compilation error CombinedSolarPower cannot be resolved
The operator + is undefined for the argument type(s) java.lang.Object, java.lang.Object
CombinedSolarPower cannot be resolved

I did assume $w1 and $w2 are integers because I did convert them to Integer with the XPATH Expression in the HTTP-call. And because range only accepts Integer. (See my description on solar power)

Posted by pz1 at Dec 16, 2013 12:22

Pieter, no problem, please do hijack. In your example you have also a problem that CombinedSolarPower is of undefined type. You would need to declare it like:

  int CombinedSolarPower = (Integer) $w1 + (Integer) $w2;
Posted by aktur at Dec 16, 2013 12:38

Thanks, that did the trick as you can see

Posted by pz1 at Dec 16, 2013 13:12

Another solution would be to define additional sensor for the in memory command time but type custom. I.e. you would have two sensors for the same virtual memory command time, one of type range to use in the slider and one of type custom to use it in rules. Then the following rule would work (assuming your custom sensor has a name "VHOURcustom"):

rule "sliderhm"
timer (cron: 0 * * ? * *)
when
  CustomState(source=="TDHOUR", $h:value)
  CustomState(source=="VHOURcustom", value==$h)
then
  execute.command("dOn");
end

In this solution you would have less in the rule file and more one sensor in the designer.

Posted by aktur at Dec 16, 2013 15:53

Geat !!!! It works !!!!

Thank's for all your advices...

The easyest way to use 2 sliders (one for hour an one for minutes) and compare them to the actual time is :

create a command :
Protocol : In-memory Virtual Command
Command : status
Adress : time

create a sensor
range form 0 to 23
with adress : time (thank's Michal)

so you can compare your slider value with your range sensor...

Thank you for your forum and your help !!!

If someone wants to set an hour and minute in the UI to activate a command... let me know I can give you some advices... I have been looking for this for hours ;-((

Posted by annesodom at Dec 18, 2013 21:41

If someone wants to set an hour and minute in the UI to activate a command... let me know I can give you some advices... I have been looking for this for hours ;-((

Maybe consider writing a how to document out of it? We can make wiki available if you're up for it.

Posted by juha at Dec 19, 2013 04:46

My "math" rule mentioned earlier in this thread has already made its way to my emerging page on solar power production.

Virtual commands should have a page on its own. Some of what has been stated here could go there. I am happy to contribute to that.

Posted by pz1 at Dec 19, 2013 08:25

I got stuck on a further exension of my rule menioned before. The rule gives me the value in Watts now. I tried to extend it to produce kWatts:

rule "Combine Solar Power"
when
   Range( source=="SolarPowerLevel", $w1 : value)
   Range( source=="SolarPowerLevel2", $w2 : value)
then
  Integer CombinedSolarPower = (Integer) $w1 + (Integer) $w2;   <-- Changed from int to Integer
  Double CombinedSolarkW = CombinedSolarPower.doubleValue()/1000;  <-- added
  execute.command("VirtualCombinedSolarPower", CombinedSolarPower);
  execute.command("VirtualCombinedSolarkWString", CombinedSolarkW.toString()); <--added
end

I do not get errors during compilation, but VirtualCombinedSolarkWString doesn't display anything. CombinedSolarPower displays as expected

Posted by pz1 at Dec 22, 2013 14:48

How about changing the line to:

  execute.command("VirtualCombinedSolarkWString", CombinedSolarPower/1000.0);
Posted by aktur at Dec 22, 2013 19:53

Thanks Michal, I did change the last line to what you suggested:

rule "Combine Solar Power"
when
   Range( source=="SolarPowerLevel", $w1 : value)
   Range( source=="SolarPowerLevel2", $w2 : value)
then
  Integer CombinedSolarPower = (Integer) $w1 + (Integer) $w2;   Integer
  execute.command("VirtualCombinedSolarPower", CombinedSolarPower);
  execute.command("VirtualCombinedSolarkWString", CombinedSolarPower/1000.0);
end

I get the following error message:

ERROR 2013-12-23 09:15:07,517 : Rule definition 'modeler_rules.drl' could not be deployed. See errors below.
ERROR 2013-12-23 09:15:07,591 : Rule Compilation error The method command(String, String) in the type CommandFacade is not applicable for the arguments (String, double)
The method command(String, String) in the type CommandFacade is not applicable for the arguments (String, double)

The error appears twice, because the full rule code contains equivalent lines for production data (kWh)

Posted by pz1 at Dec 23, 2013 08:36

Oh, now it is simple. Change the line into:

  execute.command("VirtualCombinedSolarkWString",String.format("%.3f", CombinedSolarPower/1000.0));

Dividing integer by float does proper conversion to float type. This was the intention of the code snippet I've sent.

Posted by aktur at Dec 23, 2013 09:03

Thanks Michal, that did the trick.
Except for that I had to use command VirtualCombinedSolarkW instead of the sensor VirtualCombinedSolarkWString

I am describing the application in OpenRemote 2.0 How To - Monitor Solar Power - FuturePower4All PVlogger#Calculations with solar data

I do appreciate your explanation of why it works as it does.

Posted by pz1 at Dec 23, 2013 14:41

Could you please show a picture of your sliders?

Alex

Posted by sattva at Dec 27, 2013 00:06

Hi Pieter,

Thanks for the offer – yes I think we should have separate reference pages for virtual commands. I'll try to set up some page template/location as soon as I find time. If you're able to start working on content already, then all the better (I'm pretty swamped right now).

– Juha

Posted by juha at Jan 07, 2014 13:19

Coincidentally yesterday I had made a first write-up on Virtual devices in the application page about optimising the use of solar energy. That is in my private space. It has to be brought in line/formatted with the other protocol pages. It is now more or less aligned with other protocol pages in my private space: Draft OpenRemote 2.0 How To - In-memory Virtual Command Protocol

Comments/questions on the content are welcome here.
Pieter

Posted by pz1 at Jan 07, 2014 13:41

Hey everyone,
I'm trying to achieve the same result as above but I'm getting some very strange behaviour.
My code is:

package org.openremote.controller.model.event

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.*;

rule "Wekker"

timer (cron: 0 * * ? * *)

when

   Range( source=="SystemUur", $uur:value)
   Range( source=="WekkerUur", value==$uur)
   Range( source=="SystemMinuut", $minuut:value)
   Range( source=="WekkerMinuut", value==$minuut)

then

  execute.command("Berging_AAN/UIT (ON)");

end

This works as long as you don't resynch the config from the controller with the designer.
Once you go through a resynch the controller starts spitting out the following error at high rate:

ERROR [Polling Sensor Thread ID = 232000, Name ='WekkerUur']: Error in executing rule : null -- Event Range Event (ID = 232000, Source = 'WekkerUur', Value = '11', Boundaries = [0...23]) not processed!
java.lang.NullPointerException
	at org.drools.core.util.RightTupleIndexHashTable.remove(RightTupleIndexHashTable.java:264)
	at org.drools.reteoo.JoinNode.retractRightTuple(JoinNode.java:148)
	at org.drools.reteoo.ObjectTypeNode.retractObject(ObjectTypeNode.java:232)
	at org.drools.reteoo.EntryPointNode.retractObject(EntryPointNode.java:231)
	at org.drools.common.AbstractWorkingMemory.retract(AbstractWorkingMemory.java:1288)
	at org.drools.common.AbstractWorkingMemory.retract(AbstractWorkingMemory.java:1242)
	at org.drools.impl.StatefulKnowledgeSessionImpl.retract(StatefulKnowledgeSessionImpl.java:255)
	at org.openremote.controller.statuscache.rules.RuleEngine.push(Unknown Source)
	at org.openremote.controller.statuscache.EventProcessorChain.push(Unknown Source)
	at org.openremote.controller.statuscache.StatusCache.update(Unknown Source)
	at org.openremote.controller.model.sensor.Sensor.update(Unknown Source)
	at org.openremote.controller.model.sensor.Sensor$DeviceReader.run(Unknown Source)
	at java.lang.Thread.run(Thread.java:701)

When I now reboot the controller it works as before.

The sensor itself is just a range sensor which can vary between 0-23

Anyone any idea, quite anoying I have to reboot my controller after a resynch.
Thanks
Stijn

Posted by garfield.arbuckle at Jan 13, 2014 11:58

With my quite complex rule file I have this all the time. After resync I have to hard reboot the eBox. Nice that you were able to narrow it down to a single rule. This should be a nice test case to fish for this bug.

Posted by aktur at Jan 13, 2014 12:12

Thanks Michal for confirming. I feel less alone now .
Ok is anyone up for fishing? I've got the bait right above .

Posted by garfield.arbuckle at Jan 13, 2014 12:18

My slider definition

Posted by pz1 at Jan 13, 2014 18:36

I can confirm this behaviour with an even simpler rule that only monitors the hour:

package org.openremote.controller.model.event
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.*;

rule "Start washing"
timer (cron: * 2 * ? * *)
when
  Range( source=="SensorCurrentHour", $hour:value)
  Range( source=="WasherDeadlineH", value <= $hour)
then
  execute.command("5-1ON");
end

For me this also only works after a restart of the OR controller on my Synology. It also is no longer working after a resync.

inserted:19:44 I just noted in the dev.log that after a synchronisation the defined "virtual" sensor of type type:range is not processed.
The same as what Stijn reported before. Something funny happening with sensors at sync???

I thought it could be a problem with the cron expression, because it is fired at the same? moment as when the hour and minute change.
So I played a bit with non=zero values in the cron statement. Did not make a difference.

There is an other thing that I do not understand. If I leave out the timer the rule never fires.
My understanding is that this timer is used to reduce the number of checks on conditions in order to improve performance.
Pieter

Posted by pz1 at Jan 14, 2014 15:39

Hey Pieter,
It was the same for me, if I only matched on hour or minute the error occurred, not only when I matched on hour and minute.
The timer needs to be set to run every minute because the rule needs to be checked every minute to check if the set time and actual time match.
Although you would think that the change of the value of the system time sensor would trigger the rule as it changes every minute.
Stijn

Posted by garfield.arbuckle at Jan 14, 2014 16:20

One more thing I noticed: With a resync all/most? virtual command values remain unaffected, with a controller restart all are reset to zero.

Posted by pz1 at Jan 14, 2014 16:36

The timer needs to be set to run every minute because the rule needs to be checked every minute to check if the set time and actual time match.

I don't think so. This rule has a time element (isNight) but does not need a timer:

rule "Sunshades Up" when
CustomState( source == "SunScreenDocked", value=="false")
(CustomState( source == "isItRaining", value=="true") or 
 CustomState( source=="isNight_sensor", value=="true") or 
 Event( source == "WindGust", value > 38 )
)
then
  execute.command( "SunScreenUP" );
end

I think the timer is needed so the rule does not fire to often (see example here)
At least that is how I interpreted it.

Posted by pz1 at Jan 14, 2014 16:47

Has anyone from the development team had any time to have a look at this?
It's quite annoying that a resynch breaks the rule.
Thanks
Stijn

Posted by garfield.arbuckle at Jan 29, 2014 09:52

That looks like an NPE from Drools so it's likely an issue with the rule engine. First thing to try is to upgrade Drools. I think Michal at least is using a more recent version but still seems to report having the same issue.

Posted by juha at Jan 31, 2014 16:10

"If someone wants to set an hour and minute in the UI to activate a command... let me know I can give you some advices... I have been looking for this for hours ;-(("

Hello Dominique,

I've worked on this for 2 days. A can't compare Heures and minutes in the same rule. I thing there's a lot of bugs in Drools 5.1.1 compilation. Sometime a code works and 10 minutes latter the same code doesn't. Anyway, this what I used

---------------------
package org.openremote.controller.protocol

global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;
import org.openremote.controller.protocol.*;
import org.openremote.controller.model.event.*;

rule "test"
timer (cron: 0/5 * * * * ?)
when
$evt : Range ( source == "SDTheures", $tm1 : value )
and Range ( source == "Sheur", value == $tm1 )

then

execute.command("Cave ON");

end

-----------------

SDTheures is a the date. (Date/time protocol Date H)
Sheur my slider range sensor.

Well some times, it works.

I can change the rule for my minutes slider;
------
$evt : Range ( source == "SDTminu", $tm1:value )
and Range ( source == "Sminu", value == $tm1 )
------

But I've never managed to make a working and with both condition.

If you've find a way to execute a command on a chosen time with sliders, L'll be realy glad to see your code.

Posted by michelrahal at Mar 22, 2014 11:17

You don't need the timer(cron:... ) statement.

Please add this to your rules and see if it works better:

declare Range
  @role(event)
end
Posted by aktur at Mar 22, 2014 11:27

That's fast reply, tks .
I tried what you said:
-------------------------
package org.openremote.controller.protocol

global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;
import org.openremote.controller.protocol.*;
import org.openremote.controller.model.event.*;

declare Range
@role(event)
end

rule "test"
// timer (cron: 0/10 * * * * ?)
when
Range ( source == "SDTHeures", $uur:value )
Range ( source == "Sheur", value == $uur )
Range ( source == "SDTminu", $tm1:value )
Range ( source == "Sminu", value == $tm1 )
then

execute.command("Cave ON");

end
-------------------
But It doesn't ligth my Cave
Why do you thing I don't need timer? When does the program will check de conditions if I don't use cron?

Posted by michelrahal at Mar 22, 2014 11:45

You not need the timer because the program should change conditions each time something is changed, either from time sensor or slider.
However, if this doesn't work for you then I expect that it is caused by the default drools configuration. I personally use a different configuration. You can try my custom builds and see if this help. Pro controller https://dl.dropboxusercontent.com/u/2892838/OpenRemote-Controller-2.1.0_ORCJAVA-348.zip is here and free one here https://dl.dropboxusercontent.com/u/2892838/OpenRemote-Controller-2.1.0_SNAPSHOT-2013-06-17.zip
The also have rules logger so you can get better insight what is going on.

Posted by aktur at Mar 22, 2014 12:01

Hi everybody, I was gone for a few month... I'm back, I just see the discussions you had...

Here is a rule that fires on my raspberry... You don't need a cron on this rule because the CPU just tests the rules all the time..

I had allso a problem whit my CPU Charge (up to 90 % with 350 rule lines and 5 screens.. This was due to an incompatibility between the raspbian an the java 7. I installed the java 8 and my CPU got back to 20 % !!!

rule "LightOn"
when
Event(source=="time", $htime:value)
Event(source =="htimeInt", value==$htime)
Event(source =="minute", $mtime:value)
Event(source =="minuteInt", value==$mtime)
then
execute.command("on");

Last tip, if you have problems with rules fireing... restart your device... somtimes Openremote just getts silly and does not fire rules... after restart everything is OK !!!
end

Posted by annesodom at Mar 22, 2014 16:54

Thank you guys :-D
It works perfectly like that.
I lost a lot of time by testing some working changes without restarting the controler after synchornisation.
I use a synology NAS. Just stop and restart openremote processe do the trick, I don't need to restart the all box.

Posted by michelrahal at Mar 23, 2014 09:47

Hey Dominique, can you clarify your code for me a little bit? Where are you getting your htimeInt and minuteInt. Do you have to do some type of integer conversion? Also, what does your import/global section look like?

Posted by voltron43 at May 29, 2014 02:34

Hy Nicholas,

You have to create a command "hour" whith DateTime Protocol with "date" returned and formatted "H"
Then you create a sensor with the command "hour" with type "range" and minimum "0" maximum "23"

So you don't need to convert anything to integer. You "write" the value in a variable with the function DateTime, and you read the same variable with a range type. so you get an integer.

Sorry I don't understand what you mean with the import/global section...

Posted by annesodom at Jun 03, 2014 21:26

Dominique he means the code at the top usually like the following.

package org.openremote.controller.model.event
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.*;
Posted by leafsfan at Jul 14, 2014 16:01
Document generated by Confluence on Jun 05, 2016 09:31