SOLVED
I am trying to make a rule that simply switches off a light after a given time+ a random value. Tried several, either the rule just didnt delay or didnt work.
I now came up with this (should switch off a light at 2pm +5-30 min (so 14.05-14.30)
rule "General - lightsoff"
when
Time cron "0 00 14 1/1 * ? *" //
then
var Integer RandomInterval = (Math::floor((Math::random * (30 - 5) + 5).doubleValue).intValue)
LightsOffTimer = createTimer(now.plusMinutes(RandomInterval)) [|sendCommand(b2, OFF)]
end
but I get an error thrown: Couldnāt invoke āassignValueToā for feature JvmVoid: (eProxyURI: burglar.rules#|::0.2.0.2.0.1::0::/1
What am i doing wrong?
Update.. wait a minute. I put the global variable at the top⦠fault disappeared, lets see if it works now
More Update
OK that seem sto work, but I have a question left. If I want to add more commands between the brackets⦠do I seperate them with a "| " or just with a space.
So like [|command1 |command2 |command3]
or is it
[|command1 command2 command3]
or maybe seperate them with a comma?
ofcourse I am going to try all 3, but if someone knows the answer right away that would help
Even More update
apparently it is [ | command1 command2]
OK, Final Update
Though the Above rule didnt generate any Errors⦠it just didnt do what it was supposed to do, it always fired at the same time. I only had the impression it worked as after every āsaveā the rule was reloaded and a new random variable was generated
I am not really familiar with Xtend, but I presume putting the Global variable on top was necessary for the declaration, but that that would just read the random value once and re-yse that till a restart or a resave of the rule.
So, I presumed I needed to call the variable at its original position but declare it on top.
hence it became:
var Integer RandomInterval = (Math::floor((Math::random * (30 - 5) + 5).doubleValue).intValue)
rule "General - lightsoff"
when
Time cron "0 00 14 1/1 * ? *" //
then
Integer RandomInterval = (Math::floor((Math::random * (30 - 5) + 5).doubleValue).intValue)
LightsOffTimer = createTimer(now.plusMinutes(RandomInterval)) [|sendCommand(b2, OFF)]
end
In the declaration I could probably just use āvar Integer RandomInterval = 0ā but I just left it as it is.