This page last changed on Jan 26, 2014 by jissa.

I am trying to create a rule that I can use when I go on vacation that would turn the lights on at sunset + a random number of minutes so that it appears that the lights don't turn on everyday at the same time.

I create the rule as follows


import java.util.Random;

function int rand(int max)
{
  Random rnd = new Random();
  return rnd.nextInt(max);
}

function String srand(int max)
{
  int value = rand(max);
  return (""+value);
}

rule "Vacations Lights on"

  
  timer (cron: 0 * * * * ?) 

  when 
      eval (true) 
      $s1 : Event(source == "time_to_sunset" , value == eval(srand(30)))
      $s2 : Event(source == "vacation_sensor", value == "on")
  then

      execute.command("entry_light_on"); 

end

I have another rule that turns another light at 10 minutes before sunset and it works perfectly and the rule looks like this.

rule "Porch Lights on"

  timer (cron: 0 * * * * ?) 

  when 
      eval (true) 
      $s1 : Event(source == "time_to_sunset" , value == "10")
  then

      execute.command("porch_light_on"); 

end

vacation_sensor is a virtualcommand status and time_to_sunset is using the DateTime protocol to return minutes to sunset.

When I try to deploy it I get an error in dev.log

 Line 65:60 mismatched input '(' expecting ')' in rule "Vacations Lights on" in pattern Event 

What am I doing wrong? Is there another way to get the rule to do what I want.

Also,

I have a sensor that uses the DateTime protocol to display the date on the main page. I set the timezone to America/Los_Angeles to display the local time but it displays the Raspberry Pi time which is UTC. Is there a way to display a specific time zone date and time or not?

Thank you


Hello Jonny,

isn't there a ")" too much in your event $s1 at the end?

Johannes

Posted by orjo at Jan 26, 2014 08:03

Thank you.

I looked at it multiple times but missed that extra ).

In regards to datetime is there a way to display the time for a specific time zone

Posted by jissa at Jan 27, 2014 01:01
Document generated by Confluence on Jun 05, 2016 09:38