Random light rule

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

topic with 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

It’s a warning at most, not an error. You don’t have to change anything.

From the docs

// Convert DateTimeType to Joda DateTime
val jodaVariantOne = new DateTime(MyDateTimeItem.state.toString)
if (gPresence = OFF && now.isBefore(new DateTime(Sunrise_Time.state.toString) || now.isAfter(new DateTime(Sunset_Time.state.toString))) {

Thank you Rich for the clarification. I now understand that I can continue to use the current code for now and will re-evaluate it when Openhab 3.0 comes