Hi, I am trying to create a DP to define schedules, day activities, etc…For the purposes of keeping it simple, consider the following rule which takes the Season string (from the Astro Binding) and if the condition is true, then it assigns a value with a timestamp of 6:00am (of the current day):
rule "test"
when
Time cron "0 0/1 * 1/1 * ? *"
then
var rule_name = "DayState"
if( Season.state=="AUTUMN" ) {
logInfo(rule_name,"Logical Conditon Works!")
}
val test_1 = new DateTime(now.withTimeAtStartOfDay.plusHours(6))
logInfo(rule_name,"test_1 value is: " + test_1 )
end
As one will expect, it yields:
19:51:00.048 [INFO ] [lipse.smarthome.model.script.DayState] - Logical Conditon Works!
19:51:00.050 [INFO ] [lipse.smarthome.model.script.DayState] - test_1 value is: 2018-11-25T06:00:00.000-06:00
So far so good…but, if I add the value assignment inside the logical statement like this:
rule "test"
when
Time cron "0 0/1 * 1/1 * ? *"
then
var rule_name = "DayState"
if( Season.state=="AUTUMN" ) {
logInfo(rule_name,"Logical Conditon Works!")
val test_1 = new DateTime(now.withTimeAtStartOfDay.plusHours(6))
}
logInfo(rule_name,"test_1 value is: " + test_1 )
end
Then my problem starts… first, upon saving I get:
19:57:10.611 [INFO ] [del.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'test.rules', using it anyway:
The value of the local variable test_1 is not used
19:57:10.613 [INFO ] [del.core.internal.ModelRepositoryImpl] - Loading model 'test.rules'
Then when the rules executes:
19:58:00.064 [INFO ] [lipse.smarthome.model.script.DayState] - Logical Conditon Works!
19:58:00.065 [ERROR] [untime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'test': The name 'test_1' cannot be resolved to an item or type; line 10, column 45, length 6
For the life of me I cannot understand why is not working… I am sure this has been discussed many times in other posts… have tried searching in the forums but have not been able to find a solution. Any help is much appreciated!
Thanks.