I am trying to maintain a variable which can be used in several rules to show whether is it dark. The first rule poles every minute and should populate the var isdark as true or false. This seems to work as the logs are accurate.
The second rule though just gets an error on compile - saying that it can’t resolve the variable isdark. How do I pass the info from one rule to another?
import org.joda.time.*
import org.openhab.core.library.types.*
import org.openhab.core.library.types.PercentType
import org.openhab.core.library.items.SwitchItem
import org.openhab.model.script.actions.*
import org.openhab.model.script.actions.Timer
import org.openhab.core.persistence.*
import java.util.HashMap
import java.util.LinkedHashMap
import java.util.ArrayList
import java.util.Map
import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantLock
import java.util.Date
var Number office_group_counter = 0
rule “test whether it is dark”
when
Time cron “0 * * * * ?”
then
var DateTime daystart = new DateTime((dawnStart.state as DateTimeType).calendar.timeInMillis)
var DateTime dayend = new DateTime((duskEnd.state as DateTimeType).calendar.timeInMillis)
var boolean isdark = now.isBefore(daystart) || now.isAfter (dayend)
logInfo(“Alarm”, "variable daystart = " + daystart)
logInfo(“Alarm”, "variable dayend = " + dayend)
logInfo(“Alarm”, "timenow = " + now)
logInfo(“Alarm”, "is it dark = " + isdark)
end
rule “turn on lights if dark and movement detected”
when
Item ZONE12_GENERAL_STATUS received update OPEN
then
if (office_ceiling.state == OFF && isdark){
sendCommand(office_ceiling, ON)
office_group_counter = office_group_counter + 1
logInfo(“Alarm”, "movement in office and is it dark = " + isdark)
}
end