Hi,
I try to use the random lamp rule from the topic below
but i get a sort of error:
2019-12-30 18:06:45.473 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'switches.rules', using it anyway:
The method getCalendar() from the type DateTimeType is deprecated
The method getCalendar() from the type DateTimeType is deprecated
I have to change something in the rule below
if ((gPresence = OFF) && (now.isBefore((Sunrise_Time.state as DateTimeType).calendar.timeInMillis) || now.isAfter((Sunset_Time.state as DateTimeType).calendar.timeInMillis))) {
Sunrise_Time.state as DateTimeType).calendar.timeInMillis
I found some info in https://community.openhab.org/t/solved-datetimetype-is-deprecated/37296
I don’t know how to apply this (syntax) to the below code
rule "Randomly turn on & off lights between 07.00-23.00 if before or after sunset and if alarm is activated"
when
Time cron "0 */10 7-23 * * ?"
then
if ((gPresence = OFF) && (now.isBefore((Sunrise_Time.state as DateTimeType).calendar.timeInMillis) || now.isAfter((Sunset_Time.state as DateTimeType).calendar.timeInMillis))) {
// Only turn a light on/off ocasionally
if ((new java.util.Random).nextInt(2) == 1) {
// Create a timer with a random value
var int randomTime = (new java.util.Random).nextInt(300)
logInfo("org.openhab","Setting random lights timer to " + randomTime + " seconds.")
tRandomLights = createTimer(now.plusSeconds(randomTime)) [|
var randLightIndex = (new java.util.Random).nextInt(gLights_Random.members.size)
var randLightStateCurrent = gLights_Random.members.get(randLightIndex).state
var randLightStateNew = if (randLightStateCurrent == ON) OFF else ON
logInfo("org.openhab","Switching light " + gLights_Random.members.get(randLightIndex).name + " from " + randLightStateCurrent + " to " + randLightStateNew)
sendCommand(gLights_Random.members.get(randLightIndex), randLightStateNew)
]
}
}
end
all help and insights are appreciated