Program time on and off

Hello

I have programmed some lights to turn on and off with the sun thanks to ASTRO BUILDING, what I needed now is to be able to decide when they turn on or off because I do not want them to stay overnight, now I do it with a simple rule off but I would like to choose the time and day.

I have tried to modify the ALAMARCLOCK rule but I am not able to make it work by attaching my rule and the file of items.

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*

import java.util.ArrayList

rule "Programacion luces valla"
when
	Item Program_Luces_valla received update or
	Time cron "0 00 02 * * ?"
    //Time cron "0 27 * * * ?"

then
	var ArrayList dayOfWeekSetting = newArrayList(
		Monday_Program_Luces_valla.state, 
		Tuesday_Program_Luces_valla.state, 
		Wednesday_Program_Luces_valla.state, 
		Thursday_Program_Luces_valla.state, 
		Friday_Program_Luces_valla.state, 
		Saturday_Program_Luces_valla.state, 
		Sunday_Program_Luces_valla.state
	)
    if (dayOfWeekSetting.get(now.getDayOfWeek-1) == OFF){
    	sendCommand(Program_Luces_valla_DayofWeek, OFF)
    	return false
    }
    
    if (Program_Luces_valla.state == ON) {
		logInfo("ScheduleProgramB", "Running Program B Scheduler")
       
        // convert our start time to a joda.time.DateTime for today
		
		var int minutes = (Program_Luces_valla_StartTime_Minutes.state as DecimalType).intValue()
		var int hours = (Program_Luces_valla_StartTime_Hours.state as DecimalType).intValue()
		var DateTime startTime = parse(now.getYear() + "-" + now.getMonthOfYear() + "-" + now.getDayOfMonth() + "T" + hours + ":" + minutes)
        //var DateTime startTime = now
		logInfo("ScheduleProgramB", "Start Time:  " + startTime)
        var DateTime endTime  
        
        if (startTime.isAfter(now)){
               if (Program_Luces_valla_StartTime) 

        sendCommand(Lucesvalla, OFF) 
    								}  
    }

rule "Set Programa apagado Startime"
when
    Item Program_Luces_valla_StartTime_Minutes received update or
    Item Program_Luces_valla_StartTime_Hours received update
then
	if (Program_Luces_valla_StartTime_Minutes.state == 60){
		Program_Luces_valla_StartTime_Minutes.sendCommand(0)
	}
	if (Program_Luces_valla_StartTime_Hours.state == 24){
		Program_Luces_valla_StartTime_Hours.sendCommand(0)
	}
    var int minutes = (Program_Luces_valla_StartTime_Minutes.state as DecimalType).intValue()
    var int hours = (Program_Luces_valla_StartTime_Hours.state as DecimalType).intValue()

   	// work out when the program is to start
	var DateTime startTime = parse(now.getYear() + "-" + now.getMonthOfYear() + "-" + now.getDayOfMonth() + "T" + hours + ":" + minutes)

    // update the alarm display time    
    Program_Luces_valla_StartTime.sendCommand(String::format("%02d:%02d", startTime.getHourOfDay(), startTime.getMinuteOfHour()))
end

rule "Programacion luces encendido valla"
when
	Item Program_Luces_valla_ON received update or
	Time cron "0 0 0 * * ?"
    //Time cron "0 27 * * * ?"

then
	var ArrayList dayOfWeekSetting = newArrayList(
		Monday_Program_Luces_valla_ON.state, 
		Tuesday_Program_Luces_valla_ON.state, 
		Wednesday_Program_Luces_valla_ON.state, 
		Thursday_Program_Luces_valla_ON.state, 
		Friday_Program_Luces_valla_ON.state, 
		Saturday_Program_Luces_valla_ON.state, 
		Sunday_Program_Luces_valla_ON.state
	)
    if (dayOfWeekSetting.get(now.getDayOfWeek-1) == OFF){
    	sendCommand(Program_Luces_valla_ON_DayofWeek, OFF)
    	return false
    }
    
    if (Program_Luces_valla_ON.state == ON) {
		logInfo("ScheduleProgramB", "Running Program B Scheduler")
       
      // convert our start time to a joda.time.DateTime for today
		
		var int minutes = (Program_Luces_ON_valla_StartTime_Minutes.state as DecimalType).intValue()
		var int hours = (Program_Luces_valla_ON_StartTime_Hours.state as DecimalType).intValue()
		var DateTime startTime = parse(now.getYear() + "-" + now.getMonthOfYear() + "-" + now.getDayOfMonth() + "T" + hours + ":" + minutes)
        //var DateTime startTime = now
		logInfo("ScheduleProgramB", "Start Time:  " + startTime)
        var DateTime endTime  
        
				if (startTime.isAfter(now)){
               if (Program_Luces_valla_StartTime) 

        sendCommand(Lucesvalla, ON) 
    								}  
						
		}
 
end

rule "Set Programa apagado Startime"
when
    Item Program_Luces_valla_ON_StartTime_Minutes received update or
    Item Program_Luces_valla_ON_StartTime_Hours received update
then
	if (Program_Luces_valla_ON_StartTime_Minutes.state == 60){
		Program_Luces_valla_ON_StartTime_Minutes.sendCommand(0)
	}
	if (Program_Luces_valla_ON_StartTime_Hours.state == 24){
		Program_Luces_valla_ON_StartTime_Hours.sendCommand(0)
	}
    var int minutes = (Program_Luces_valla_ON_StartTime_Minutes.state as DecimalType).intValue()
    var int hours = (Program_Luces_valla_ON_StartTime_Hours.state as DecimalType).intValue()

   	// work out when the program is to start
	var DateTime startTime = parse(now.getYear() + "-" + now.getMonthOfYear() + "-" + now.getDayOfMonth() + "T" + hours + ":" + minutes)

    // update the alarm display time    
    Program_Luces_valla_ON_StartTime.sendCommand(String::format("%02d:%02d", startTime.getHourOfDay(), startTime.getMinuteOfHour()))
end

Items

/* Program luces valla Settings */	
Switch	Program_Luces_valla	"Program B [%s]"	<power>	(ProgramBSettings)
Switch	Program_Luces_valla_DayofWeek	"Program B Day Of Week [%s]"	<power>	(ProgramBSettings)
String	Program_Luces_valla_StartTime	"Start Time [%s]"	<calendar>	(ProgramBSettings)
Number	Program_Luces_valla_StartTime_Hours	"Hours [%d]"	(ProgramBSettings)
Number	Program_Luces_valla_StartTime_Minutes	"Minutes [%d]"	(ProgramBSettings)		

Switch	Monday_Program_Luces_valla "Monday [%s]" <power>	(ProgramBSettings)
Switch	Tuesday_Program_Luces_valla "Tuesday [%s]" <power>	(ProgramBSettings)
Switch	Wednesday_Program_Luces_valla "Wednesday [%s]" <power>	(ProgramBSettings)
Switch	Thursday_Program_Luces_valla "Thursday [%s]" <power>	(ProgramBSettings)
Switch	Friday_Program_Luces_valla "Friday [%s]" <power>	(ProgramBSettings)
Switch	Saturday_Program_Luces_valla "Saturday [%s]" <power>	(ProgramBSettings)
Switch	Sunday_Program_Luces_valla "Sunday [%s]" <power>	(ProgramBSettings)

/* Program luces valla Settings */	
Switch	Program_Luces_valla_ON	"Program B [%s]"	<power>	(ProgramBSettings)
Switch	Program_Luces_valla_ON_DayofWeek	"Program B Day Of Week [%s]"	<power>	(ProgramBSettings)
String	Program_Luces_valla_ON_StartTime	"Start Time [%s]"	<calendar>	(ProgramBSettings)
Number	Program_Luces_valla_ON_StartTime_Hours	"Hours [%d]"	(ProgramBSettings)
Number	Program_Luces_valla_ON_StartTime_Minutes	"Minutes [%d]"	(ProgramBSettings)		

Switch	Monday_Program_Luces_valla_ON "Monday [%s]" <power>	(ProgramBSettings)
Switch	Tuesday_Program_Luces_valla_ON "Tuesday [%s]" <power>	(ProgramBSettings)
Switch	Wednesday_Program_Luces_valla_ON "Wednesday [%s]" <power>	(ProgramBSettings)
Switch	Thursday_Program_Luces_valla_ON "Thursday [%s]" <power>	(ProgramBSettings)
Switch	Friday_Program_Luces_valla_ON "Friday [%s]" <power>	(ProgramBSettings)
Switch	Saturday_Program_Luces_valla_ON "Saturday [%s]" <power>	(ProgramBSettings)
Switch	Sunday_Program_Luces_valla_ON "Sunday [%s]" <power>	(ProgramBSettings)

Switch	Lucesvalla	"Luces Valla"	<switch>	(TodasLucesCalle_GRP)		{ souliss="T11:1:2", autoupdate="false" }

a greeting I hope your help.

What specifically doesn’t work?

Errors in the log?

hello, in the log does not come out anything refreshes the rule and does not leave any error just do not turn off or turn on the lights, a greeting

Add some logging to the rule to see if the rule is even running. If it isn’t you know the problem is with your rule trigger.

If the Rule is running, keep adding log statements until you can narrow down the problem to a specific section.

Missing end in rule file or copy pasta error.

Same name of rule!!!

hello effectively the colleague @josar was right there were those two mistakes, unfortunately once corrected the code I still have the same problems. a greeting

hello I made some changes but if it still does not work here I put them in case you see what is wrong
a greeting

var DateTime endTime  
    
        if (startTime.isAfter(now)) [| 
               if (Program_Luces_valla_StartTime) 

         Lucesvalla.sendCommand(OFF)
    							 ]

and this is an error that is now in the log

2018-03-01 23:37:23.780 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Set Program B Startime': Cannot cast org.openhab.core.types.UnDefType to org.openhab.core.library.types.DecimalType

018-03-01 23:19:48.661 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Set Programa apagado Startime': Cannot cast org.openhab.core.types.UnDefType to org.openhab.core.library.types.DecimalType
2018-03-01 23:19:49.183 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Set Programa apagado Startime': Cannot cast org.openhab.core.types.UnDefType to org.openhab.core.library.types.DecimalType
2018-03-01 23:19:49.527 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Set Programa apagado Startime': Cannot cast org.openhab.core.types.UnDefType to org.openhab.core.library.types.DecimalType
2018-03-01 23:19:49.807 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Set Programa apagado Startime': Cannot cast org.openhab.core.types.UnDefType to org.openhab.core.library.types.DecimalType

You should use VSCode with openhab extension.
It really helps avoid problems. Just some examples.

grafik

grafik

grafik

grafik

grafik

you have to take the state

Program_Luces_valla_StartTime.state

I think this two Items are missing.

Program_Luces_valla_ON_StartTime_Minutes
Program_Luces_valla_ON_StartTime_Hours