This page last changed on Aug 21, 2014 by hari152.

package org.openremote.controller.protocol

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

rule "Switch on the fan"

timer (cron: 0 51 14 * * ?)

when eval(true)

then

execute.command("Device 9-On");
end

The device Switches on 14.15, I want to switch it off at 14.20. How do I set the rule?
Please help
Thanks.

Exactly like you did the "on" rule:

rule "Switch off the fan"

timer (cron: 0 20 14 * * ?)

when eval(true)

then

execute.command("Device 9-Off");
end

Assuming your command to switch the fan off is named "Device 9-Off".

Posted by druciak at Aug 21, 2014 20:18

i mean i want to switch on and off the fan in the same rule.

can i type this two times will it work.

rule "Switch on the fan"

timer (cron: 0 20 14 * * ?)

when eval(true)

then

execute.command("Device 9-On");
end

rule "Switch off the fan"

timer (cron: 0 25 14 * * ?)

when eval(true)

then

execute.command("Device 9-Off");
end

Posted by hari152 at Aug 22, 2014 02:07

Yes, this is exactly what I meant. You need two rules, one to switch on, and another one to switch it off. Your example will definitely work.

Posted by druciak at Aug 22, 2014 08:06

Thanks

Posted by hari152 at Aug 25, 2014 04:01

Is it possible to turn the rule on and off with a switch in the GUI?
Please help.

Thanks.

Posted by hari152 at Aug 25, 2014 05:45

Yes, it is. You need a in-memory virtual command and replace your 'when eval(true)' with something like this: 'Switch(source == "Enable rule", value == "on")'.

Posted by druciak at Aug 25, 2014 07:51

It worked Thanks.

Posted by hari152 at Aug 25, 2014 10:01

Now I want to set the time to switch on and off the fan from the GUI. How can it be done?
please help.
Thanks

Posted by hari152 at Aug 26, 2014 02:27

There's no easy way AFAIK. The only way that comes to my mind is:
1. Prepare 2 in-memory commands for hours and minutes.
2. Prepare 2 range sensors and 2 sliders, for hours 0-23, for minutes 0-59.
3. Create DateTime command for current time: name: "DayTime", function "date", format "H:m"
4. Modify your rules:

rule "Switch on the fan"
when
   Level(source == "Hours", $hours : value) and
   Level(source == "Minutes", $minutes : value) and
   CustomState(source == "DayTime", value == String.format("%s:%s", $hours.toString(), $minutes.toString()) and
   Switch(source == "Enable rule", value == "on")
then
   execute.command("Device 9-On");
end

This rule shows the general idea, I haven't tested it, I don't even know if it compiles.

Posted by druciak at Aug 30, 2014 08:09
Document generated by Confluence on Jun 05, 2016 09:35