Support with Rules

Hi there. I need some support with the rules in openremote. Please kindly help me with these questions and checking the rules I have pasted, which I cannot manage to trigger.

1- What steps ae required after defining the rules, so they can exported and used by the OR controller? i.e. after saving and synchronizing the controller, do I need to restart the OR controller?

2- When are the rules triggered? My understanding is that a change in status in one fo the switches used in the “when” part of a rule…should trigger the rule engine to run the rules, and if the conditions are met, then the “then” part of the rule is triggered.

3- Can you kindly take a look at these rules? My intention is to test how to change the value of a switch, based on the status of a virtual switch which is binded to a thirds switch. It is just a test, to learn how t use rules, however I do not seem to be able to get this working.

package org.openremote.controller.protocol
global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;
global org.openremote.controller.statuscache.LevelFacade levels;
import org.openremote.controller.protocol.;
import java.util.
;
import java.util.regex.*;

rule “binding switches_ON”
when
Event(source == “KitchenSwitch”, value == “on”)
then
execute.command( “VirtualSwitch_A_ON”);
end

rule “binding switches_OFF”
when
Event(source == “KitchenSwitch”, value == “off”)
then
execute.command( “VirtualSwitch_A_OFF”);
end

rule “test 1”
when

Event(source == “VirtualSwitch_A”, value == “on”)

then

execute.command( “WemoSwitch_ON” );

end

rule “test 2”
when

Event(source == “VirtualSwitch_A”, value == “off”)

then

execute.command( “WemoSwitch_OFF” );

end

  1. No you don’t need to restart the controller. However, you should check logs/boot.log to see if there are any errors in the rule file. As I can see you miss
    import org.openremote.controller.model.event.*;

in the header.

  1. correct

  2. to understand how rules are triggered it is good to look on logs/rules/drools.log file

Thank you Michal. Rules are now working, after adding import org.openremote.controller.model.event.*;
A follow up question, you mentioned two logs to check, the one in ~/openremote/logs/boot.log and ~/openremote/logs/rules/drools.log . Is there any other log that shows when a rule was triggered?

Thanks again!

David.

~/openremote/logs/dev/dev.log

Hi Michal

I took a look at the ~/openremote/logs/dev/dev.log and it seems like the system stopped writing to it three days ago. Is there a reason why the system would do this?

I guess my question should have been “how do I fix it”… I know that my rules are working, but I can’t find info about the in this log.
Thanks again.

Hi
I have a clean install now of the OR controller, however it seems I’m facing the same problem, the log files only show information until yesterday and I can’t figure out if my rules are running properly (I know some of them are working, but some other do not seem to be working). I have attached the log files hoping someone can take a look at them and point me in the right direction.

Thanks in advance !

David.

boot.log (214 KB)

dev.log (139 KB)

drools.log (8.64 KB)

zwave.log (27 KB)

It might be helpful to see you actual rules files (.drl file) and specify which rule you feel is not getting executed correctly vs. how you expect it to execute.

Sure, I have added the rules below. All of them are working now. However, the logs don’t show when they have been executed. I believe this is related to the fact that the system has somehow created three different log folders in the following paths:

~/openremote/webapps/controller/logs/

~/openremote/webapps/controller/WEB-INF/logs/

~/openremote/logs/

Any idea why this may be?

Here are the rules.

package
org.openremote.controller.protocol

import
org.openremote.controller.protocol.*;

import
org.openremote.controller.model.event.*;

import java.util.*;

import
java.util.regex.*;

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

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

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

/*
--------------------- Sample rules -----------------------------------------*/

rule “binding
switches_ON” when

Event( source ==
“KitchenSwitch_Sensor”, value == “on” )

then

execute.command(
“Livingroom_Mainlight_ON” );

execute.command(
“ColorBulb_KC_Red”, 100 );

end

rule “binding
switches_OFF” when

Event( source ==
“KitchenSwitch_Sensor”, value == “off” )

then

execute.command(
“Livingroom_Mainlight_OFF” );

execute.command(
“ColorBulb_KC_Red”, 10 );

end

/--------------------------------Macros-------------------------------------------/

rule “Macro
Everything OFF” when

Event( source ==
“Macro_All_Off_STATUS”, value ==“on”)

then

execute.command(“Mode_FAN_AUTO_OFF”);

execute.command(“Macro_All_LightsON_OFF”);

execute.command(“KitchenSwitch_OFF”);

execute.command(“FrontLight_OFF”);

execute.command(“WemoSwitch_OFF”);

execute.command(“Outdoor_Light_Front_OFF”);

execute.command(“CeilingFan_MB_OFF”);

execute.command(“CeilingFan_GR_OFF”);

execute.command(“Livingroom_Mainlight_OFF”);

execute.command(“Gameroom_Mainlight_OFF”);

execute.command(“Livingroom_Lamps_OFF”);

execute.command(“Masterbedroom_Lights_OFF”);

execute.command(“Masterbedroom_Lamps_OFF”);

execute.command(“Masterbathroom_Dimmer_OFF”);

execute.command(“ZW_Lamp_Dimmer1_OFF”);

execute.command(“Patio_Light_OFF”);

execute.command(“Gameroom_TV_OFF”);

execute.command(“ZW_Lamp_Switch_1_OFF”);

end

rule “Macro All
Lights ON” when

Event( source ==
“Macro_All_LightsON_STATUS”, value ==“on”)

then

execute.command(“Macro_All_LightsOFF_OFF”);

execute.command(“KitchenSwitch_ON”);

execute.command(“FrontLight_ON”);

execute.command(“Outdoor_Light_Front_ON”);

execute.command(“Livingroom_Mainlight_ON”);

execute.command(“Gameroom_Mainlight_ON”);

execute.command(“Livingroom_Lamps_ON”);

execute.command(“Masterbedroom_Lights_ON”);

execute.command(“Masterbedroom_Lamps_ON”);

execute.command(“Masterbathroom_Dimmer_ON”);

execute.command(“ZW_Lamp_Dimmer1_ON”);

execute.command(“Patio_Light_ON”);

execute.command(“Macro_All_LightsON_OFF”);

end

rule “Macro All
Lights OFF” when

Event( source ==
“Macro_ALL_LightsOFF_STATUS”, value ==“on”)

then

execute.command(“Macro_All_LightsON_OFF”);

execute.command(“KitchenSwitch_OFF”);

execute.command(“FrontLight_OFF”);

execute.command(“Outdoor_Light_Front_OFF”);

execute.command(“Livingroom_Mainlight_OFF”);

execute.command(“Gameroom_Mainlight_OFF”);

execute.command(“Livingroom_Lamps_OFF”);

execute.command(“Masterbedroom_Lights_OFF”);

execute.command(“Masterbedroom_Lamps_OFF”);

execute.command(“Masterbathroom_Dimmer_OFF”);

execute.command(“ZW_Lamp_Dimmer1_OFF”);

execute.command(“Patio_Light_OFF”);

execute.command(“Macro_ALL_LightsOFF_OFF”);

end

/-------------------------------Modes
--------------------------------------
/

rule “Mode
People At Home ON_Morning”

timer (cron: 0 0 7 *

  • ?) when eval (true) then

execute.command(“Mode_PeopleAtHome_ON”);

end

/*-------- Eliminar
cuando estemos todos en la oficina

rule “Mode People At Home OFF_Morning”

timer (cron: 0 0 9 * * ?) when eval (true)
then

execute.command(“Mode_PeopleAtHome_OFF”);

end

rule “Mode People At Home ON_Afternoon”

timer (cron: 0 0 17 * * ?) when eval (true)
then

execute.command(“Mode_PeopleAtHome_ON”);

end

-----*/

rule “Mode
People At Home OFF_Afternoon”

timer (cron: 0 0 22

    • ?) when eval (true) then

execute.command(“Mode_PeopleAtHome_OFF”);

end

/*
--------------------------- ceiling fan
rules --------------------------------
*/

rule “increase
speed ceiling fan when too hot”
when

Event( source
== “Multisensor_Living_Temp”,
value >= 80 )

Switch( source ==
“Mode_PeopleAtHome_STATUS”, value == “on”)

Switch( source ==
“Mode_FAN_AUTO_STATUS”, value == “on”)

then

execute.command(“CeilingFan_DIM”,
100 );

execute.command(“CeilingFan_MB_DIM”, 100 );

execute.command(“CeilingFan_GR_DIM”, 100 );

end

rule “increase
speed ceiling fan when hot” when

Event( source ==
“Multisensor_Living_Temp” , value >= 76 )

Switch( source ==
“Mode_PeopleAtHome_STATUS”, value == “on”)

Switch( source ==
“Mode_FAN_AUTO_STATUS”, value == “on”)

then

execute.command(“CeilingFan_DIM”,
50 );

execute.command(“CeilingFan_MB_DIM”, 50 );

execute.command(“CeilingFan_GR_DIM”, 50 );

end

rule “turn on
ceiling fan when temp is 74” when

Event( source ==
“Multisensor_Living_Temp” , value >= 74 )

Switch( source ==
“Mode_PeopleAtHome_STATUS”, value == “on”)

Switch( source ==
“Mode_FAN_AUTO_STATUS”, value == “on”)

then

execute.command(“CeilingFan_DIM”,
30 );

execute.command(“CeilingFan_MB_DIM”, 30 );

execute.command(“CeilingFan_GR_DIM”, 30 );

end

rule “increase
speed ceiling fan when NOT hot” when

Event( source
== “Multisensor_Living_Temp”,
value <= 72 )

Switch( source ==
“Mode_PeopleAtHome_STATUS”, value == “on”)

Switch( source ==
“Mode_FAN_AUTO_STATUS”, value == “on”)

then

execute.command(“CeilingFan_OFF”);

execute.command(“CeilingFan_MB_OFF”);

execute.command(“CeilingFan_GR_OFF”);

end

rule "ceiling
fans OFF at 10:00 PM "

timer (cron: 0 0 22 * * ?)

when

eval(true)

then

execute.command(“CeilingFan_OFF”);

execute.command(“CeilingFan_MB_OFF”);

execute.command(“CeilingFan_GR_OFF”);

end

/*
----------------------------------- Outdoor lights
---------------------------------------- */

rule “outdoor
light on” when

Event( source == “Sensor_MinToSunset”, value == 30 )

then

execute.command(“Outdoor_Light_Front_ON”);

execute.command(“Patio_Light_ON”);

end

rule “outdoor
light off”

timer (cron: 0 0 22

    • ?) when eval (true) then

execute.command(“Outdoor_Light_Front_OFF”);

execute.command(“Patio_Light_OFF”);

end

/*
-----------------------------------Indoor
lights------------------------------------*/

rule “kitchen
light on”

when

Event( source == “Sensor_MinToSunset”, value == 30 )

then

execute.command(“Gameroom_Lamps_ON”);

execute.command(“Livingroom_Lamps_ON”);

execute.command(“KitchenSwitch_ON”);

execute.command(“ZW_Lamp_Dimmer1_DIM”, 50 );

execute.command(
“ColorBulb_KC_ON”);

execute.command(
“ColorBulb_KC_W_White”, 0 );

execute.command(
“ColorBulb_KC_C_White”, 0 );

execute.command(
“ColorBulb_KC_Green”, 50 );

execute.command(
“ColorBulb_KC_Red”, 100 );

execute.command(
“ColorBulb_KC_Blue”, 10 );

end

rule “kitchen
light off”

timer (cron: 0 30 22

    • ?) when eval (true) then

execute.command(
“ColorBulb_KC_OFF”);

execute.command(“KitchenSwitch_OFF”);

execute.command(“Livingroom_Lamps_OFF”);

execute.command(“Masterbathroom_Dimmer_OFF”);

end

/*
----------------------------- Fountain Rules
---------------------------------------*/

rule " Fountain
off"

timer (cron: 0 30 22

    • ?) when eval (true) then

execute.command(“ZW_Lamp_Switch_1_OFF”);

end

The drools.log file in the folder /logs/rules should show exactly when a rule is trigger and the state that triggers it- for example one of the entries in my drools.log file is as follows:

DEBUG 2017-06-20 20:51:53,785 (Drools): rule “Back door open” // (package org.openremote.controller.protocol)

Declarations

LHS objects(antecedents)

Class: “CustomState”

Fields:

Event Name: “MONOPRICE_DOORSENSE_C_STATUS”

Event Value: “1”

Thanks for the info. The problem seem to be related to file rights and starting Openremote manually from different folders, as I have been doing. This caused the system to create different log file structures, as previously described.

Solution:

1- complete the installation process described in https://github.com/openremote/Documentation/wiki/Raspberry-Pi , by adding the following steps:

chmod +x /etc/init.d/openremote // this step makes the script executable

*sudo update-rc.d openremote defaults // this *step adds symbolic links to the open remote script in the /etc/rc_.d folders Without this, the open remote script is not executed when the system starts

2- reboot the system

I will create a different issue for the installation process for a raspberry pi, with this data.

Thank you all for all your support !!