Access Keys:
Skip to content (Access Key - 0)
 

One more question about rules.

Kenneth Stridh

On Apr 26, 2012 15:51

Hi!

I've tried to write a rule who should fired once every hour and half hour, but I have problems getting it to fire only once per time point.

I created a datetime (custom) sensor with the command formatted as "mm.ss" and a rule that looks like this:

package org.openremote.controller.model.event
global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;

rule "Every 30min"
when
CustomState ( source == "minsec", val : value, eval(Float.valueOf((String)val) == 0.0) || eval(Float.valueOf((String)val) == 30.0))
then
System.out.println (Float.valueOf($minsek.getValue()));
end

The rule works and fire when it should, but the problem is that it fire about 6 times per time point.

I have tried with rule attributes as "no-loop true", "duration (950ms)" and "timer (int: 0s 2s), but I can't get it to work as I think it should.

When I tried with the attribute "timer", I get it to work on simple rules, but if I do a longer more complex rule, it will not work.

For example, this one works: (it is fired every 15 seconds).

package org.openremote.controller.model.event
global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;

import java.io.*;
import java.util.*;
import java.lang.Float;

rule "Every 30min"
timer (int: 1s 15s)
when
eval(true)
then
System.out.println("Fire!");
end

But this doesn't work: (mostly it fired continuously, but sometimes it ain't fired at all).

package org.openremote.controller.model.event
global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;

rule "Test1"
timer (int: 1s 15s)
when
eval(true)
$templivingroom : CustomState (source == "Temp Vardagsrum")
$bedroom : CustomState (source == "Temp Sovrum")
$kidsroom1 : CustomState (source == "Temp Barnrum 1n")
$tempFTXin : CustomState (source == "Temp Tilluft")
then
System.out.println (Double.parseDouble($bedroom.getValue()));
System.out.println("FIRE!");
end

Am I doing something wrong?

I would be very grateful if someone had a suggestion on how I could get it to work.

/Kenneth

 
Labels:
Participants: Administrator , Guillaume Carlier , Juha Lindfors , Kenneth Stridh , Marcus Redeker , Nejc Šmid , Nir Aviry
  1. Apr 27, 2012

    Marcus Redeker says:

    I think "timer(cron: ...)" will be more elegant for your needs. Each full hour a...

    I think "timer(cron: ...)" will be more elegant for your needs. Each full hour and half hour should be:

    timer (cron: 0 0,30 * * * ?)

    1. Apr 27, 2012

      Kenneth Stridh says:

      Thank you Markus. You are absolutely right "timer (cron: ...)" is much more ele...

      Thank you Markus.

      You are absolutely right "timer (cron: ...)" is much more elegant.

      I don't know why, but I thought the "timer (cron: ...)" was a new attribute that was only implemented in the latest version of Drools. What version of Drools have you implemented? Can I also use the calendar attribute?

      But even with the "timer (cron: 0 .30 ***)" the rule is fired several times (first time it was fired two times the second time it was fired six times).

      I have been testing pretty much now and something is strange.

      1. Apr 27, 2012

        Marcus Redeker says:

        We use Drools 5.1.1 in the moment. I think for calendar to work we will have to ...

        We use Drools 5.1.1 in the moment.
        I think for calendar to work we will have to configure the KnowledgeBase correct, which I think is not done yet.

        If you have any more info about "something is strange", anything might help.

        1. Apr 27, 2012

          Kenneth Stridh says:

          What kind of info are you thinking of? Unfortunately I don't have more info than...

          What kind of info are you thinking of? Unfortunately I don't have more info than what I have tried to describe.

          (That the rules goes of (fire) several times even though I try to limit it to just once with the "no-loop" or "timer" attributes)

          For me as a novice, it is as if it get stuck in a loop inside the "then" part of the rule.

          If I write a rule with "timer (cron: 0 .30 ***)" then it should fired once each full hour and half hour, but it is fired 2-6 times each full hour and half hour.

          It's the same with "no-loop true" if I understand everything correctly, it shall make the rule only fired once per event, but the rule is fired several times anyway. Likewise with timer (int: 0s 30s) fired several times each 30th second.

          The problem occurs only if I have a little more complex rule.

          For example, works this rule (Writes "Fire!" once each full hour and half hour).

          rule "Every 30min"
          timer (cron: 0 0,30 * * * ?)
          when
          eval(true)
          then
          System.out.println("Fire!");
          end

          But this writing "Fire!" + the temp values, ​​2-6 times each full hour and half hour (sometimes it may be only once).

          rule "Every 30min"
          timer (cron: 0 0,30 * * * ?)
          when
          eval(true)
          $outdoortemp : CustomState (source == "Utetemperatur")
          $templivingroom : CustomState (source == "Temp Vardagsrum")
          $bedroom : CustomState (source == "Temp Sovrum")
          $kidsroom1 : CustomState (source == "Temp Barnrum 1n")
          $tempFTXin : CustomState (source == "Temp Tilluft")
          then
          System.out.println("Fire!");
          System.out.println (Double.parseDouble($bedroom.getValue()));
          System.out.println (Double.parseDouble($kidsroom1.getValue()));
          System.out.println (Double.parseDouble($tempFTXin.getValue()));
          System.out.println (Double.parseDouble($templivingroom.getValue()));
          System.out.println (Double.parseDouble($outdoortemp.getValue()));
          end

          Can you fire complex rules only once, each full hour and half hour with the "timer (cron: 0 0.30 ***)"?

          1. Jul 20, 2012

            Marcus Redeker says:

            Kenneth, is this still an issue? I just created a test with one sensor and that ...

            Kenneth, is this still an issue? I just created a test with one sensor and that works fine.
            Maybe this is related to the fact that you have multiple sensors in one rule or maybe, you have other events that could cause the rule to be triggered because of the "eval(true)".
            Maybe every time the rule engine is fired (which is with each sensor event) this causes the rule to be triggered in addition to the timer?
            Just an idea.

            1. Aug 04, 2012

              Kenneth Stridh says:

              Hi Markus and excuse the late response (I'm on vacation with limited internet ac...

              Hi Markus and excuse the late response (I'm on vacation with limited internet access).

              Yes, it still happens (2-6 times per day) that my rules for logging temperatures, energy consumption and power triggers more than once (with less than one second intervals) each hour and half hour.

              "Maybe every time the rule engine is fired (which is with each sensor event) this causes the rule to be triggered in addition to the timer?"

              Yes, of course. You're probably right.

              A bit embarrassing, but as a beginner on both java and rules I hadn't realized that this line
              "$outdoortemp : CustomState (source == "Utetemperatur")"
              also triggers the rule each time the temperature sensor sends out a new temperature. I thought that it only declare the variable and initialize it with the latest temperature value.

              It is probably a temperature value that change at the same time, the timer trigger the rule.

              Is it possible to read the sensor value and store it in the variable from the "then" part of the rule instead?

              Is it possible to send a read request (of a temperature value) from a rule?

        2. Jul 10, 2012

          Nejc Šmid says:

          Hi all I have one more question related to the rules. Let's say that I have one...

          Hi all

          I have one more question related to the rules. Let's say that I have one pushbutton and one relay (for switching light). I can turn on and off relay through regular switch and now I would like to manage this relay also through pushbutton.
          Rule that I'm looking for, should look like this:

          When
          pushbutton state is 1 (is pressed)(is pressed less then 1s - I would like to add a time component) and relay is on

          then
          turn relay off
          and

          When
          pushbutton state is 1 (is pressed)(is pressed less then 1s - I would like to add a time component) and relay is off

          then
          turn relay on
          and

          Any suggestion?

          Regards,
          Nejc

          1. Jul 10, 2012

            Marcus Redeker says:

            Why a button and not just the switch UI object? If push button, why the time com...

            Why a button and not just the switch UI object? If push button, why the time component?

            1. Jul 10, 2012

              Nejc Šmid says:

              At home we have light switches to turn on and off lights. For test I connect one...

              At home we have light switches to turn on and off lights. For test I connect one of them to 1-wire chip (DS2408) and now I can read its state(1/0). I also control relays with this 1-wire chip. I can control this relays with android application (openremote) but now I would like to control this relays also with light switch. To do this I first thought of a simple rule but there is a problem. If I turn relay ON with light switch (state 1) and then turn OFF with android application, light switch should still be in ON position (state 1). So the simple rule is not an option. Then I thought of the switch that acting as a button (http://www.p-wholesale.com/cn-pro/5/304to1/push-button-switchm82k12-10-291852.html). It could trigger rules.

              Why the time component? Because if there is no time component the rule will be caught in a loop until the button is pressed (on and off loop). The time component could also increase switches functionality. If it's pressed less then 1s, turn light on/off and if it's press more than 1s, turn all lights on/off.

              I hope that I have succeeded to explain my problem.

              1. Jul 20, 2012

                Marcus Redeker says:

                Ok, I think I understood you. But since 1-wire is stateless and always has to b...

                Ok, I think I understood you.
                But since 1-wire is stateless and always has to be polled to give the current status it might not be the perfect protocol for this since you need a lot of polling.

                Using a push-button switch and not a on/off switch for the wall switch is correct because otherwise the wall switch could still be "on" while openremote already turned the light "off".
                You could probably implement a toggle rule (if status=off turn on else turn off). This rule can be triggered from either the android command or the wall switch and the status is just updated by reading the status of the relay every 500ms or so.

                1. Oct 05, 2012

                  Nejc Šmid says:

                  Hello Thanks Marcus for the reply, but I still need some more help. The first...

                  Hello

                  Thanks Marcus for the reply, but I still need some more help.

                  The first question: What is the best way to trigger switches in rules. I find two solutions:

                  -execute.command("command switch on");
                  -switches.name("switch name").on();

                  Am I right? Are both correct?

                  The second question: I would like to create temperature level rule where limit value can be control with the slider.

                  This is my plan:
                  -create virtual command (name: virtual, command: status, Address: address)
                  -create sensor for virtual command (name: sensor virtual, Command: virtual, type: range, Min:0, Max:30)
                  -create slider (name: slider, sensor: sensor virtual, setValue: virtual)

                  -create a rule:

                  rule "turn on heating"

                  when

                  Level( source == "temperature sensor", value > (hear must be slider value) )//maybe: address. getValue()

                  then

                  execute.command("command switch on");

                  end

                  I have problem with inserting slider value in the rule. Is command parameter: status in virtual command right choice?

                  The third question: What is the best way to implement if /else logic in the rule (toggle rule). Is in creating two rules or inserting if/else in one rule. How to use if/else in the rule?

                  Thanks all.

                  Regards,
                  Nejc

                  1. Oct 05, 2012

                    Administrator says:

                    The first question: What is the best way to trigger switches in rules. I find t...

                    The first question: What is the best way to trigger switches in rules. I find two solutions:

                    -execute.command("command switch on");
                    -switches.name("switch name").on();

                    Am I right? Are both correct?

                    I think both would work, yes. If they do, matter of taste then whether you prefer conceptually operate on 'switch object' level or 'command object' level.

                  2. Oct 05, 2012

                    Administrator says:

                    The third question: What is the best way to implement if /else logic in the rul...

                    The third question: What is the best way to implement if /else logic in the rule (toggle rule). Is in creating two rules or inserting if/else in one rule. How to use if/else in the rule?

                    Two rules I guess is more natural for a declarative engine. Maybe this document offers some ideas? http://stackoverflow.com/questions/7993659/if-then-else-with-rule-engines

                  3. Oct 05, 2012

                    Administrator says:

                    rule "turn on heating" when Level( source == "temperature senso...

                    rule "turn on heating"

                    when

                    Level( source == "temperature sensor", value > (hear must be slider value) )//maybe: address. getValue()

                    then

                    execute.command("command switch on");

                    end

                    I have problem with inserting slider value in the rule. Is command parameter: status in virtual command right choice?

                    You could assign the limiter value to a variable like so (untested):

                    when
                    
                      Level ( source == "MyVirtualSensorThingy", $limitvalue : value )
                      Level( source == "temperature sensor", value > $limitvalue )
                    
                    then
                    
                    execute.command("command switch on");
                    
                    end
                    
                    

                    Here's an example for reference: http://bit.ly/VpPPnC

                    Maybe that helps?

                    1. Oct 05, 2012

                      Nejc Šmid says:

                      Thanks! I appreciate your help. Regards, Nejc

                      Thanks!

                      I appreciate your help.

                      Regards,
                      Nejc

                    2. Oct 05, 2012

                      Nejc Šmid says:

                      If I attach to my third question. I created two rules. These two rules are neede...

                      If I attach to my third question. I created two rules. These two rules are needed because I would like to use physical push-button in combination with my phone to turn ON/OFF the lamp. As I expected loop appears (although it is push-button, duration of value == "1" is too long). I was looking for a solution. I found attribute no-loop, but it prevents the further activation for the rule. I even found attribute duration, but it is also not useful.

                      My rule:

                      rule " turn OFF the lamp if it is ON and push-button is pressed"

                      when
                      CustomState(source == "button sensor", value == "1")
                      CustomState(source == "rele1 sensor", value == "on")
                      then
                      execute.command("rele1 OFF");
                      end

                      rule " turn ON the lamp if it is OFF and push-button is pressed "

                      when
                      CustomState(source == " button sensor", value == "1")
                      CustomState(source == "rele1 sensor", value == "off")
                      then
                      execute.command("rele1 ON");
                      end

                      Any suggestions?

                      Regards,
                      Nejc

                      1. Oct 05, 2012

                        Juha Lindfors says:

                        One way to skin the cat might be to insert a new boolean fact into the knowledge...

                        One way to skin the cat might be to insert a new boolean fact into the knowledge base and use its existence to trigger a rule:

                        
                        
                        /*
                         * This example demonstrates creation of new facts from within the rules, in this
                         * case a vacation object that can be used to determine differing behavior on event
                         * actions.
                         */
                        declare Vacation
                        
                          onVacation : boolean
                        
                        end
                        
                        
                        
                        /* Insert a new vacation fact */
                        
                        rule "I'm going on vacation"
                        
                        when
                        
                          Event ( source == "vacation start" )
                        
                        then
                        
                          Vacation vacation = new Vacation();
                        
                          insert ( vacation );
                        
                        end
                        
                        
                        
                        /* Retract the vacation fact */
                        
                        rule "I'm back from vacation"
                        
                        when
                        
                          Event ( source == "vacation end" )
                        
                          $vacation : Vacation()
                        
                        then
                        
                        // do something here...
                        
                          retract ( $vacation );
                        
                        end
                        
                        

                        Where the first rule injects a fact and the second rule checks the existence of the fact and then does something and retracts the fact.

                        For reference, the entire example is here: http://bit.ly/SP4naw

                        1. Oct 05, 2012

                          Juha Lindfors says:

                          Sorry missed the second part that shows testing of fact existence: /* Set ...

                          Sorry missed the second part that shows testing of fact existence:

                          
                          /* Set night temperatures differently depending on presence of vacation fact */
                          
                          rule "Set Night Temperature"
                          
                          when
                          
                            CustomState ( source == "time of day", value == "night" ) and not Vacation()
                          
                          then
                          
                            execute.command("temp", 18);
                          
                          end
                          
                          
                          rule "Set Night Temperature when on Vacation"
                          
                          when
                          
                            CustomState ( source == "time of day", value == "night" ) and exists Vacation()
                          
                          then
                          
                            execute.command("temp", 15);
                            
                          end
                          
                          
                          1. Oct 06, 2012

                            Nejc Šmid says:

                            I managed to fix rules so that now operates. Thanks for the help. Tested rules:...

                            I managed to fix rules so that now operates. Thanks for the help.

                            Tested rules:

                            declare Button
                            onButton : boolean
                            end

                            rule "button is not pressed"
                            when
                            CustomState(source == " button sensor ", value == "0")
                            then
                            Button button = new Button();
                            insert ( button );
                            end

                            rule " turn OFF the lamp if it is ON and push-button is pressed"
                            when
                            CustomState(source == "button sensor", value == "1") and exists Button()
                            CustomState(source == "rele1 sensor", value == "on")
                            $button : Button()
                            then
                            retract ( $button );
                            execute.command("rele1 OFF");
                            end

                            rule " turn ON the lamp if it is OFF and push-button is pressed "
                            when
                            CustomState(source == " button sensor", value == "1") and exists Button()
                            CustomState(source == "rele1 sensor", value == "off")
                            $button : Button()
                            then
                            retract ( $button );
                            execute.command("rele1 ON");
                            end

                            Regards,
                            Nejc

                    3. Oct 09, 2012

                      Nejc Šmid says:

                      Hi I have problems with definition of this rule (rule from my second question)....

                      Hi

                      I have problems with definition of this rule (rule from my second question).
                      I could not find what was wrong (no error, but rule not working), so I decided to progressively build up rule.

                      I stuck to this rule:
                      rule "slider value is > 20 and virtual switch is on "
                      when
                      Switch( source == "virtual switch sensor", value == "on")
                      Level( source == "virtual slider sensor", value > 20)
                      then
                      execute.command("rele2 OFF");
                      end

                      rule " slider value is <= 20 and virtual switch is on "
                      when
                      Switch( source == " virtual switch sensor ", value == "on")
                      Level( source == " virtual slider sensor ", value <= 20)
                      then
                      execute.command("rele2 ON");
                      end

                      I have virtual slider with virtual slider sensor which is type RANGE: 0-40. Rule just with Switch and execute.command works.
                      I have no errors but the switch does not turn on when the slider value is less than 20.

                      Thanks.

                      Regards,
                      Nejc

                      1. Oct 09, 2012

                        Marcus Redeker says:

                        Is "rele2" a switch object? If that is the case, you need execute.command("rele2...

                        Is "rele2" a switch object?
                        If that is the case, you need execute.command("rele2", "on");
                        Also, make sure the names are typed correct. I can see spaces in the sesond rule where the source name is written.

                        1. Oct 09, 2012

                          Nejc Šmid says:

                          "rele2" is custom 1-wire PIO command and it works (tested on other rules). Name...

                          "rele2" is custom 1-wire PIO command and it works (tested on other rules).

                          Names are typed correctly (yes, it is spaces in the second rule, but this is the result of mycopying). The names of my devices are actually different (written in my language).

                        2. Oct 10, 2012

                          Nejc Šmid says:

                          Now I tested this rule with a slider type LEVEL (before I have type RANGE) and i...

                          Now I tested this rule with a slider type LEVEL (before I have type RANGE) and it works. But I want to have range slider (from 10 to 40 degrees celsius).

                        3. Oct 09, 2012

                          Nejc Šmid says:

                          I'm looking for suggestions to solve this rule problem. Operating rule: rule "...

                          I'm looking for suggestions to solve this rule problem.

                          Operating rule:

                          rule "radiator turns off"
                          when
                          CustomState(source == "temperature sensor", val : value, eval(Float.valueOf((String)val) > 23.0))
                          then
                          execute.command("rele2 OFF");
                          end

                          rule "radiator turns on"
                          when
                          CustomState(source == "temperature sensor", val : value, eval(Float.valueOf((String)val) > 23.0))
                          then
                          execute.command("rele2 ON");
                          end

                          I added a slider to control the condition:

                          rule "radiator turns off"
                          when
                          Level (source == "slider sensor", $condition : value )
                          CustomState(source == "temperature sensor", val : value, eval(Float.valueOf((String)val) > $condition))
                          then
                          execute.command("rele2 OFF");
                          end

                          rule "radiator turns on"
                          when
                          Level (source == " slider sensor ", $condition : value )
                          CustomState(source == "temperature sensor", val : value, eval(Float.valueOf((String)val) <= $condition))
                          then
                          execute.command("rele2 ON");
                          end

                          I got this errors:

                          ERROR 2012-10-09 19:22:56,859 : Rule Compilation error The operator <= is undefined for the argument type(s) Float, Object
                          ERROR [Controller Definition File Watcher for Default Deployer]: Rule Compilation error The operator <= is undefined for the argument type(s) Float, Object
                          ERROR 2012-10-09 19:22:56,859 : Rule Compilation error The operator > is undefined for the argument type(s) Float, Object
                          ERROR [Controller Definition File Watcher for Default Deployer]: Rule Compilation error The operator > is undefined for the argument type(s) Float, Object
                          Rule Compilation error : [Rule name='radiator turns on'] ...

                          What type is output value of slider?

                          Thanks,
                          Nejc

                          1. Oct 09, 2012

                            Juha Lindfors says:

                            What type is output value of slider? It's an integer between the min/max value...

                            What type is output value of slider?

                            It's an integer between the min/max values of the range (step of 1), or between 0-100 if level (step of 1)

                            1. Oct 10, 2012

                              Nejc Šmid says:

                              So I need a line in the rule that compare string (1-wire temperature) and intege...

                              So I need a line in the rule that compare string (1-wire temperature) and integer (slider).

                              For example:
                              CustomState(source == "temperature sensor", string > integer)

                              Any suggestions?

                              I tried with this:

                              Level(source == "slider sensor", $condition : value )
                              CustomState(source == "temperature sensor", (int)Float.parseFloat((String)value) > $condition )

                              ...but without success.

                              1. Oct 11, 2012

                                Marcus Redeker says:

                                Float.valueOf() returns a Float object which cannot be used with ">". Float.p...

                                Float.valueOf() returns a Float object which cannot be used with ">".
                                Float.parseFloat() return a float value that can be used with ">".

                                Your last example should work. Do you see an error?

                                1. Oct 11, 2012

                                  Nejc Šmid says:

                                  This is my rule: rule "radiator se prizge" //heating on when Level(source == "v...

                                  This is my rule:

                                  rule "radiator se prizge" //heating on
                                  when
                                  Level(source == "v test senzor", $condition1 : value )// virtual level slider
                                  Switch(source == "stikalo virtual stikalo", value == "on") //virtual switch that turn on rule
                                  CustomState(source == "temperatura senzor", (int)Float.parseFloat((String)value) > $condition1 )
                                  then
                                  execute.command("rele2 ON");
                                  end

                                  rule "radiator se ugasne " //heating off
                                  when
                                  Level(source == "v test senzor", $condition2 : value ) //vitual level slider
                                  Switch(source == "stikalo virtual stikalo", value == "on") //virtual switch that turn on rule
                                  CustomState(source == "temperatura senzor", (int)Float.parseFloat((String)value) <= $condition2 )
                                  then
                                  execute.command("rele2 OFF");
                                  end

                                  Errors:

                                  ERROR 2012-10-11 11:19:18,679 : Rule definition 'modeler_rules.drl' could not be deployed. See errors below.
                                  ERROR [Controller Definition File Watcher for Default Deployer]: Rule definition 'modeler_rules.drl' could not be deployed. See errors below.
                                  ERROR 2012-10-11 11:19:18,682 : [ERR 101] Line 16:48 no viable alternative at input ')' in rule "radiator se prizge " in pattern CustomState
                                  ERROR [Controller Definition File Watcher for Default Deployer]: [ERR 101] Line 16:48 no viable alternative at input ')' in rule "radiator se prizge " in pattern CustomState
                                  ERROR 2012-10-11 11:19:18,683 : [ERR 101] Line 16:73 no viable alternative at input ')' in rule "radiator se prizge " in pattern Float.parseFloat
                                  ERROR [Controller Definition File Watcher for Default Deployer]: [ERR 101] Line 16:73 no viable alternative at input ')' in rule "radiator se prizge " in pattern Float.parseFloat
                                  ERROR 2012-10-11 11:19:18,683 : [ERR 101] Line 25:48 no viable alternative at input ')' in rule "radiator se ugasne " in pattern CustomState
                                  ERROR [Controller Definition File Watcher for Default Deployer]: [ERR 101] Line 25:48 no viable alternative at input ')' in rule "radiator se ugasne " in pattern CustomState
                                  ERROR 2012-10-11 11:19:18,683 : [ERR 101] Line 25:73 no viable alternative at input ')' in rule "radiator se ugasne " in pattern Float.parseFloat
                                  ERROR [Controller Definition File Watcher for Default Deployer]: [ERR 101] Line 25:73 no viable alternative at input ')' in rule "radiator se ugasne " in pattern Float.parseFloat ...

                                  1. Oct 13, 2012

                                    Marcus Redeker says:

                                    Can you try this one: CustomState(source == "temperatura senzor", eval(Float....

                                    Can you try this one:

                                    CustomState(source == "temperatura senzor", eval(Float.parseFloat((String)value) <= $condition2 )
                                    
                                    1. Oct 13, 2012

                                      Nejc Šmid says:

                                      Still errors: ERROR 2012-10-13 21:07:52,261 : Rule Compilation error The operat...

                                      Still errors:

                                      ERROR 2012-10-13 21:07:52,261 : Rule Compilation error The operator <= is undefined for the argument type(s) float, Object
                                      ERROR [Controller Definition File Watcher for Default Deployer]: Rule Compilation error The operator <= is undefined for the argument type(s) float, Object
                                      ERROR 2012-10-13 21:07:52,261 : Rule Compilation error The operator > is undefined for the argument type(s) float, Object
                                      ERROR [Controller Definition File Watcher for Default Deployer]: Rule Compilation error The operator > is undefined for the argument type(s) float, Object
                                      Rule Compilation error : [Rule name='radiator se ugasne']
                                      org/openremote/controller/model/event/Rule_radiator_se_ugasne_0.java (9:527) : The operator <= is undefined for the argument type(s) float, Object
                                      Rule Compilation error : [Rule name='radiator se prizge']
                                      org/openremote/controller/model/event/Rule_radiator_se_prizge_0.java (9:527) : The operator > is undefined for the argument type(s) float, Object

                                      Rules:

                                      rule "radiator se prizge "
                                      when
                                      Level(source == "v test senzor", $condition1 : value )
                                      Switch(source == "stikalo virtual stikalo", value == "on")
                                      CustomState(source == "temperatura senzor", eval(Float.parseFloat((String)value) > $condition1 ))
                                      then
                                      execute.command("rele2 ON");
                                      end

                                      rule "radiator se ugasne "
                                      when
                                      Level(source == "v test senzor", $condition2 : value )
                                      Switch(source == "stikalo virtual stikalo", value == "on")
                                      CustomState(source == "temperatura senzor", eval(Float.parseFloat((String)value) <= $condition2 ))
                                      then
                                      execute.command("rele2 OFF");
                                      end

                                      Thanks Marcus for your help.

                                      1. Oct 14, 2012

                                        Marcus Redeker says:

                                        Ok, value is treated as object. So we need another cast New try: CustomStat...

                                        Ok, value is treated as object. So we need another cast
                                        New try:

                                        CustomState(source == "temperatura senzor", eval(Float.parseFloat((String)value) > ((Integer)$condition1).intValue() ))
                                        
                                        1. Oct 15, 2012

                                          Nejc Šmid says:

                                          That's it Now rule works as expected, but still something missing. The problem...

                                          That's it

                                          Now rule works as expected, but still something missing. The problem is that rule has worked only if I used LEVEL slider, in the case if I used RANGE slider it didn't worked.

                                          Any idea why this is happening?

                                          Thanks again!

                                          Regards,
                                          Nejc

                                        2. Oct 15, 2012

                                          Nejc Šmid says:

                                          This problem is now completely solved I replaced Level() with Range() and now r...

                                          This problem is now completely solved I replaced Level() with Range() and now rule also works with RANGE slider.

                                          Regards,
                                          Nejc

                                    2. Oct 14, 2012

                                      Nejc Šmid says:

                                      Hi Marcus. I saw that Guillaume Carlier succeeded in creating interface like I ...

                                      Hi Marcus.

                                      I saw that Guillaume Carlier succeeded in creating interface like I have been trying to achieve for quite some time. (http://www.openremote.org/display/project/2012/10/09/OpenRemote+with+Zibase+Thermostat+Control) Do you have his contact? Likely he used the rules and his rules implementation will be a great help.
                                      I also have many problems with the shape of the sliders in the new android application.

                                      Regards,
                                      Nejc

                                      1. Oct 14, 2012

                                        Marcus Redeker says:

                                        I asked Juha, if he has any information.

                                        I asked Juha, if he has any information.

                                      2. Oct 15, 2012

                                        Guillaume Carlier says:

                                        Hi Nejc, Unfortunately I do not use rules for the Thermostat you mentionned, so...

                                        Hi Nejc,

                                        Unfortunately I do not use rules for the Thermostat you mentionned, so I can't help you. Actually all commands are sent using HTTP get > Php script > Zibase variables (french box) > Php > xml < OR polling

                                        regards

                                        Guillaume

                                        1. Oct 15, 2012

                                          Nejc Šmid says:

                                          Hi Guillaume, Actually is Marcus just found the right combination and now i hav...

                                          Hi Guillaume,

                                          Actually is Marcus just found the right combination and now i have operating rules.

                                          Did you have any problems with sliders design.

                                          Thanks for the reply.

                                          Regards,
                                          Nejc

                                          1. Oct 15, 2012

                                            Guillaume Carlier says:

                                            Hello, No problem with sliders, using an Ipad Regards Guillaume

                                            Hello,

                                            No problem with sliders, using an Ipad

                                            Regards

                                            Guillaume

                                2. Oct 13, 2012

                                  Nejc Šmid says:

                                  Any suggestions to solve this problem? Thanks, Nejc

                                  Any suggestions to solve this problem?

                                  Thanks,
                                  Nejc

                                  1. Oct 21, 2012

                                    Nir Aviry says:

                                    Hi, I am trying to write my own rules to handle the Schneider blinds that opera...

                                    Hi,

                                    I am trying to write my own rules to handle the Schneider blinds that operate differently from other manufacturers and also my weather station (Temp, Rain, Wind and Light).
                                    I see the code of the various examples and I was also trying to understand Drool from the JBoss documenation which is around Eclipse and I am missing few basic things:
                                    1. Are all the top declaration like package...., global etc. required? Some examples have them and some not.
                                    2. What is the connection between parameters and status I read and the code. My guess in that the definition sources == <name of a status item>.
                                    3. I am not sure I understand how do I send a switching command (for instance turning off a curtain switch). I see the above example - execute.command("rele2 OFF");
                                    What is not clear to me is the link between the rele2 and the actual relay. If the name of the relay in the project is rele2, then it is all clear.

                                    I would also recommand to put all examples with some words in one thread. This would be more efficient.

                                    Thanks,

                                    Nir

                                    1. Oct 22, 2012

                                      Marcus Redeker says:

                                      Package is needed to tell drools which package the generated java files will get...

                                      Package is needed to tell drools which package the generated java files will get.
                                      That package also includes our classes already which would not be found otherwise.
                                      Global is needed if you need some other of our classes like CommandFacade.

                                      Here is an example that listens on a switch (here a KNX switch) which sends either on or off.
                                      Based on that switch a command is triggered.
                                      You can just add another command within the "then" part to execute 2 commands.

                                      package org.openremote.controller.model.event
                                      
                                      global org.openremote.controller.statuscache.CommandFacade execute;
                                      global org.openremote.controller.statuscache.SwitchFacade switches;
                                      
                                      import org.openremote.controller.protocol.Event;
                                      
                                      rule "Turn Music on via KNX"
                                      when
                                        $evt:Event(source == "SwitchSensor", value == "on")
                                      then
                                        execute.command("Zone6 Power (ON)");
                                      end
                                      
                                      rule "Turn Music off via KNX"
                                      when
                                        $evt:Event(source == "SwitchSensor", value == "off")
                                      then
                                        execute.command("Zone6 Power (OFF)");
                                      end
                                      
                                      1. Oct 23, 2012

                                        Kenneth Stridh says:

                                        Hi Markus. One more question. If I have a sensor value that I want to use in a...

                                        Hi Markus.

                                        One more question.

                                        If I have a sensor value that I want to use in a rule, but I don't want a change in the sensor value should trigger the rule. Is it possible to initialize a variable with the sensor value without triggering the rule each time the sensor value is changing?

                                        For example, outside the rule or in the "then" part?

                                        Thanks,
                                        Kenneth

                                        1. Oct 23, 2012

                                          Marcus Redeker says:

                                          Maybe this will help: package org.openremote.controller.model.event globa...

                                          Maybe this will help:

                                          package org.openremote.controller.model.event
                                          
                                          global org.openremote.controller.statuscache.CommandFacade execute;
                                          global org.openremote.controller.statuscache.SwitchFacade switches;
                                          
                                          import org.openremote.controller.protocol.Event;
                                          
                                          rule "Demo rule"
                                          when
                                            Level(source == "sensor-name", $currentVal : value ) //This stores the value of the sensor in currentVal
                                            <-- here you still need the condition when the rule should be executed, otherwise each change of "sensor-name" will execute this rule -->
                                          then
                                            // Whatever you want todo goes here. You can eg. work with the value
                                            execute.command("SetRoomHeating", eval(((Integer)value)+5);
                                          end
                                          
                                          1. Oct 23, 2012

                                            Kenneth Stridh says:

                                            Thanks Markus! It helped a lot. I'll try if I can make it work for me too. //...

                                            Thanks Markus!

                                            It helped a lot.

                                            I'll try if I can make it work for me too.

                                            //Kenneth

                                      2. Oct 23, 2012

                                        Nir Aviry says:

                                        Hi Marcus. Line 1 is understood. Lines 2 & 3 are understood except for the ...

                                        Hi Marcus.

                                        Line 1 is understood.
                                        Lines 2 & 3 are understood except for the fact that I have no idea where can I find documentation of your classes and what classes exists.
                                        Line 4 (Import) - not sure I understand what is being imported (one event, all the events or so).

                                        As for the rest are the names SwitchSensor and Zone6 Power the exact names used under the definitions of the various switches under devices?

                                        One last thing. How do I get time, date etc. into the rules? I want to run events that are driven from time of day etc.

                                        Thanks,

                                        Nir

                                        1. Oct 23, 2012

                                          Marcus Redeker says:

                                          There is not much documentation yet except looking at the code and the test clas...

                                          There is not much documentation yet except looking at the code and the test classes from Juha.
                                          Hopefully sooner or later that will change

                                          Line4: The java class "org.openremote.controller.protocol.Event" is imported.
                                          My example does not include it, but earlier in this thread you can see an examples where it is used.
                                          Yes, the names are the names of sensors or commands used in the designer.

                                          Timer based rules are mentioned a few time in the forums already.

                                          1. Oct 23, 2012

                                            Nir Aviry says:

                                            Hi, Now things are clearer. I understand the starting point. Thanks. Nir

                                            Hi,

                                            Now things are clearer. I understand the starting point.

                                            Thanks.

                                            Nir

                                            1. Oct 24, 2012

                                              Nir Aviry says:

                                              One thing is not clear to me. All these commands like timer cron etc appear in e...

                                              One thing is not clear to me. All these commands like timer cron etc appear in examples. I guess there are some more. Where can I find documentation?

                                              1. Oct 24, 2012

                                                Marcus Redeker says:

                                                http://www.jboss.org/drools/
                                                1. Nov 21, 2012

                                                  Nir Aviry says:

                                                  I am trying to put some rules to practice and what I get is: 1. Error I do not u...

                                                  I am trying to put some rules to practice and what I get is:
                                                  1. Error I do not understand (rule name System_Init)
                                                  2. 2 Rules that does not do anything but does not generate any error (Test_Study_Light_On & Test_Study_Light_Off)

                                                  This is the rule file:

                                                  package org.openremote.controller.model.event

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

                                                  import org.openremote.controller.protocol.Event;

                                                  /* ------------------------------------------ */
                                                  /* Set Time to turn off Water Tank */
                                                  /* ------------------------------------------ */

                                                  /* ------------------------------------------ */

                                                  rule "Init_System"
                                                  when
                                                  eval (true)
                                                  then
                                                  int Default_Water_Tank_Time = 120;
                                                  int Current_Water_Tank_Time = Default_Water_Tank_Time;
                                                  int Time_Count = Current_Water_Tank_Time;

                                                  $Water_Tank_Previous_State : CustomState(source == "Water Tank Panel Status Light", value == "on");
                                                  $WTS_On_State : eval (false);
                                                  end

                                                  rule "Test_Study_Light_On"
                                                  when
                                                  CustomState(source == "Study Main Light Panel Status", value == "on")
                                                  then
                                                  execute.command("Entrance Closete Lights (ON)");
                                                  System.out.println("Study Main Light is On !");
                                                  end

                                                  rule "Test_Study_Light_Off"
                                                  when
                                                  CustomState(source == "Study Main Light Panel Status", value == "off")
                                                  then
                                                  execute.command("Entrance Closete Lights (OFF)");
                                                  System.out.println("Study Main Light is Off !");
                                                  end

                                                  This is what I get in the log file.

                                                  ERROR 2012-11-21 19:43:45,599 : Rule definition 'modeler_rules.drl' could not be deployed. See errors below.
                                                  ERROR 2012-11-21 19:43:45,600 : Rule Compilation error source cannot be resolved
                                                  value cannot be resolved
                                                  The method eval(boolean) is undefined for the type Rule_Init_System_0
                                                  ERROR 2012-11-21 19:43:45,604 : There was an error parsing the rule definition 'modeler_rules.drl' : Could not parse knowledge.
                                                  java.lang.IllegalArgumentException: Could not parse knowledge.
                                                  at org.drools.builder.impl.KnowledgeBuilderImpl.newKnowledgeBase(KnowledgeBuilderImpl.java:58)
                                                  at org.openremote.controller.statuscache.rules.RuleEngine.getValidKnowledgePackages(RuleEngine.java:532)
                                                  at org.openremote.controller.statuscache.rules.RuleEngine.start(RuleEngine.java:253)
                                                  at org.openremote.controller.statuscache.EventProcessorChain.start(EventProcessorChain.java:112)
                                                  at org.openremote.controller.statuscache.StatusCache.start(StatusCache.java:120)
                                                  at org.openremote.controller.deployer.Version20ModelBuilder.buildSensorModel(Version20ModelBuilder.java:633)
                                                  at org.openremote.controller.deployer.Version20ModelBuilder.build(Version20ModelBuilder.java:555)
                                                  at org.openremote.controller.deployer.AbstractModelBuilder.buildModel(AbstractModelBuilder.java:154)
                                                  at org.openremote.controller.service.Deployer.startup(Deployer.java:840)
                                                  at org.openremote.controller.service.Deployer.softRestart(Deployer.java:420)
                                                  at org.openremote.controller.service.Deployer$ControllerDefinitionWatch.run(Deployer.java:1268)
                                                  at java.lang.Thread.run(Unknown Source)

                                                  1. Nov 21, 2012

                                                    Marcus Redeker says:

                                                    Your init rule is not working. This means every time rules are triggered (which ...

                                                    Your init rule is not working. This means every time rules are triggered (which is with each sensor change) that rule will fire. Besides the eval(true) is not correct as you can see in your error already.

                                                    The other rules don't do anything because the whole rule subsystem is not started because of the problem in your first rule.

                                                    1. Nov 22, 2012

                                                      Nir Aviry says:

                                                      1. I am not much of a Java expert but I have seen some examples with the eval(tr...

                                                      1. I am not much of a Java expert but I have seen some examples with the eval(true) so I do not understand the error. It is missing run once which I will add. I added this rule just to test parameter initialization in this way.
                                                      2. The 2nd rule was on his own also (without the 1st rule) but did not do anything. The Study Main Light was turned On using the actual switch and using OR. I had no errors in the log file yet Closete light did not turn on.

                                                      1. Nov 24, 2012

                                                        Nir Aviry says:

                                                        Finally it works. The issue here is lack of documentation. Please add some words...

                                                        Finally it works.
                                                        The issue here is lack of documentation.
                                                        Please add some words about Switch, Level, CustomState, when "on" or "1" is to be used.
                                                        Except for few examples no information.
                                                        Now I understand the "head" of this but it was all guessing.
                                                        It is very basic yet with no minimal documentation it takes hours to get it to work.

                                                        1. Nov 25, 2012

                                                          Marcus Redeker says:

                                                          You would be the perfect candidate to start a small documentation

                                                          You would be the perfect candidate to start a small documentation

                                                          1. Nov 26, 2012

                                                            Nir Aviry says:

                                                            Maybe. The only issue is to find out all the commands contained in the OR packag...

                                                            Maybe. The only issue is to find out all the commands contained in the OR packages.
                                                            From the examples I have seen:
                                                            Level
                                                            Switch
                                                            execute.command
                                                            CustomState

                                                            I have no idea if there is any documentation of these and maybe other commands that were implemented.
                                                            If you can shade some light on this issue I might be of help.

                                                            1. Nov 26, 2012

                                                              Marcus Redeker says:

                                                              When a sensor changes a value, an event is fired which triggers the rule engine....

                                                              When a sensor changes a value, an event is fired which triggers the rule engine.
                                                              The following events are available:

                                                              • CustomState
                                                              • Range
                                                              • Level
                                                              • Switch
                                                                They can be found in the java package: org.openremote.controller.model.event

                                                              The CommandFacade which is defined as a global 'execute' can be used to trigger commands from within a rule.

                                                              You can find all kind off examples in the test rules: http://openremote.svn.sourceforge.net/viewvc/openremote/tags/project/Controller/Controller_2_0_1/test/org/openremote/controller/fixture/statuscache/rules/

Adaptavist Theme Builder Powered by Atlassian Confluence