Please advice me about running a time schedule multiple, start & end time

Hello all.

I’m trying to run a schedule time based rules, from UI .
I need to assign at least a five jobs per day, for a single switch
job-1 - start_time - end_time
job-2 - start_time - end_time
job-3 - start_time - end_time
job-4 - start_time - end_time
job-5 - start_time - end_time

I’m overthinking about how to accomplish that, but I just cant think about just a start path to do it

Thanks

There are multiple ways to accomplish this. Somewhere on the forum there is a scheduler (graphic one), I couldn’t find fast.

I did it with rules and switches, but for me i’ve only 2 time settings and 2 switches. I’ll share it with you, maybe you can find a path to start to do it.

What it does: I can set a timer to automatic send a command UP(omhoog) or DOWN(omlaag) to my rollershutters (2: back and front).

rules:

rule "auto Timer setting time"
when
	Member of RollerShutters_Auto_Timer_HoursMinutes received update
then
	logInfo("tijd veranderd",triggeringItem.toString)
	val tname = triggeringItem.name 
	val tdir = tname.split("_").get(3)
	RollerShutters_Auto_Timer.members.findFirst[i|i.name.contains(tdir)].sendCommand(OFF)
end

rule "Auto Rollershutter based on time"
when
	Member of RollerShutters_Auto_Timer received update
then
	val tdir = triggeringItem.name.split("_").get(3)
	val tstate = triggeringItem.state
	val timer_time = RollerShutters_Auto_Timer_Time.allMembers.findFirst[i|i.name.contains(tdir)]
	val timer_hour = (RollerShutters_Auto_Timer_HoursMinutes.allMembers.findFirst[i|i.name.contains(tdir+"_Hour")].state as Number).intValue
	val timer_minute = (RollerShutters_Auto_Timer_HoursMinutes.allMembers.findFirst[i|i.name.contains(tdir+"_Minute")].state as Number).intValue
	if (now.isBefore(now.withTime(timer_hour,timer_minute,0,0)) ){
		timer_time.postUpdate(now.withTime(timer_hour,timer_minute,0,0).toString)
	}else{
		timer_time.postUpdate(now.withTime(timer_hour,timer_minute,0,0).plusHours(24).toString)
	}
	if (tstate==ON){
		switch tdir{
			case "Down" :{
				if (RSTimerDown === null){
					logInfo("RSTimerDown","start Timer Down")
					RSTimerDown = createTimer(new DateTime(RollerShutters_Auto_Timer_Down_Time.state.toString), [|
						logInfo("RSTimerDown","Timer wordt uitgevoerd")
						RollerShutters_Auto_Timer_Down.allMembers.filter[i|i.state==ON].forEach[i|
							checkFirstRS.apply(RollerShutters.members.findFirst[j|j.name.contains(i.name.split("_").get(1))] as GenericItem, DOWN)
						]
						RollerShutters_Auto_Timer_Down_Time.postUpdate(now.plusDays(1).toString)
						RSTimerDown.reschedule(now.plusDays(1))
					])
				}
			}
			case "Up" :{
				if (RSTimerUp === null){
					logInfo("RSTimerUp","start Timer Up")
					RSTimerUp = createTimer(new DateTime(RollerShutters_Auto_Timer_Up_Time.state.toString), [|
						logInfo("RSTimerUp","Timer wordt uitgevoerd")
						RollerShutters_Auto_Timer_Up.allMembers.filter[i|i.state==ON].forEach[i|
							checkFirstRS.apply(RollerShutters.members.findFirst[j|j.name.contains(i.name.split("_").get(1))] as GenericItem, UP)
						]
						RollerShutters_Auto_Timer_Up_Time.postUpdate(now.plusDays(1).toString)
						RSTimerUp.reschedule(now.plusDays(1))
					])
				}
			}
		}
	}else{
		switch tdir{
			case "Down": {
				if (RollerShutters_Auto_Timer_Down.state == OFF){
					logInfo("RSTimerDown","stop Timer Down")
					RSTimerDown?.cancel
					RSTimerDown = null
				}	
			}
			case "Up": {
				if (RollerShutters_Auto_Timer_Up.state == OFF){
					logInfo("RSTimerUp","stop Timer Up")
					RSTimerUp?.cancel
					RSTimerUp = null
				}	
			}
		}
	}
end

rule "Trigger Rollershutter based on time rule after refresh or restart"
when
	System started
then
	logInfo("reset","Timer reset na herstart")
	RollerShutters_Auto_Timer?.allMembers.filter[i|i.state == ON].forEach[j|j.postUpdate(ON)]

end

items:

Switch					RollerShutters_Front_Auto_Timer_Up		"Rolluiken op tijd omhoog voorzijde"											(RollerShutters_Auto_Timer_Up)
Switch					RollerShutters_Front_Auto_Timer_Down	"Rolluiken op tijd omlaag voorzijde"											(RollerShutters_Auto_Timer_Down)
Switch					RollerShutters_Back_Auto_Timer_Up		"Rolluiken op tijd omhoog acherzijde"											(RollerShutters_Auto_Timer_Up)
Switch					RollerShutters_Back_Auto_Timer_Down		"Rolluiken op tijd omlaag achterzijde"											(RollerShutters_Auto_Timer_Down)
Switch					RollerShutters_Front_Auto_Sun_Up		"Rolluiken zon tijd omhoog voorzijde"											(RollerShutters_Auto_Timer_Up)
Switch					RollerShutters_Front_Auto_Sun_Down		"Rolluiken zon tijd omlaag voorzijde"											(RollerShutters_Auto_Timer_Down)
Switch					RollerShutters_Back_Auto_Sun_Up			"Rolluiken zon tijd omhoog acherzijde"											(RollerShutters_Auto_Timer_Up)
Switch					RollerShutters_Back_Auto_Sun_Down		"Rolluiken zon tijd omlaag achterzijde"											(RollerShutters_Auto_Timer_Down)
DateTime				RollerShutters_Auto_Timer_Up_Time		"Rolluiken op tijd ingesteld omhoog [%1$tH:%1$tM]"				<time>			(RollerShutters_Auto_Timer_Time)
DateTime				RollerShutters_Auto_Timer_Down_Time		"Rolluiken op tijd ingesteld omlaag [%1$tH:%1$tM]"				<time>			(RollerShutters_Auto_Timer_Time)
Number					RollerShutters_Auto_Timer_Up_Hour		"Rolluiken op tijd omhoog uur [%d]"								<time>			(RollerShutters_Auto_Timer_HoursMinutes)
Number					RollerShutters_Auto_Timer_Up_Minute		"Rolluiken op tijd omhoog minuten [%d]"							<time>			(RollerShutters_Auto_Timer_HoursMinutes)
Number					RollerShutters_Auto_Timer_Down_Hour		"Rolluiken op tijd omlaag uur [%d]"								<time>			(RollerShutters_Auto_Timer_HoursMinutes)
Number					RollerShutters_Auto_Timer_Down_Minute	"Rolluiken op tijd omlaag minuten [%d]"							<time>			(RollerShutters_Auto_Timer_HoursMinutes)

sitemap

				Group item=RollerShutters_Auto_Timer {
					Frame label="omhoog"{
						Text item=RollerShutters_Auto_Timer_Up_Time label="Ingestelde tijd"
						Text label="" icon=""
						Setpoint item=RollerShutters_Auto_Timer_Up_Hour label="uur" minValue=0 maxValue=23 step=1 visibility=[RollerShutters_Auto_Timer_Up == OFF]
						Setpoint item=RollerShutters_Auto_Timer_Up_Minute label="minuten" minValue=0 maxValue=59 step=15 visibility=[RollerShutters_Auto_Timer_Up == OFF]
						Switch item=RollerShutters_Front_Auto_Timer_Up label="Voorzijde" mappings=[ON=AAN, OFF=UIT]
						Switch item=RollerShutters_Back_Auto_Timer_Up label="Achterzijde" mappings=[ON=AAN, OFF=UIT]
					}
					Frame label="omlaag"{
						Text item=RollerShutters_Auto_Timer_Down_Time label="Ingestelde tijd"
						Text label="" icon=""
						Setpoint item=RollerShutters_Auto_Timer_Down_Hour label="uur" minValue=0 maxValue=23 step=1 visibility=[RollerShutters_Auto_Timer_Down == OFF]
						Setpoint item=RollerShutters_Auto_Timer_Down_Minute label="minuten" minValue=0 maxValue=59 step=15 visibility=[RollerShutters_Auto_Timer_Down == OFF]
						Switch item=RollerShutters_Front_Auto_Timer_Down label="Voorzijde" mappings=[ON=AAN, OFF=UIT]
						Switch item=RollerShutters_Back_Auto_Timer_Down label="Achterzijde" mappings=[ON=AAN, OFF=UIT]
					}
				}
1 Like

@ljsquare thanks, I’ll try your solution right now

If there anyone can help me , please , thanks

If you want to do this from a UI then install the Rule Engine in PaperUI and then create two rules for each schedule, with each rule’s trigger being a cron trigger. One rule to turn the switch on at a specific time and another rule to run the switch off. So you would have a total of ten rules for your five jobs. This documentation has what you need

If you forego the UI and use a .rules file instead you can accomplish this with two cron triggered rules for all five jobs, one rule to turn the switch on at the desired times and another rule to turn the switch off

. For an example assume we want the switch on from 10am to 11am , 1 pm to 3 pm, and 6pm to 7 pm. The rule to turn the switch on would be something like:

rule SwitchOn
when Time cron "0 0 10 * * ? *" 
  or Time cron "0 0 13 * * ? *"
  or Time cron "0 0 18 * * ? *"
then sendCommand(MySwitch, ON)
end

And the rule to turn the switch off would be something like:

rule SwitchOff
when Time cron "0 0 11 * * ? *" 
  or Time cron "0 0 15 * * ? *"
  or Time cron "0 0 19 * * ? *"
then sendCommand(MySwitch, OFF)
end

This code is not tested but it should be enough to get you started.

HTH
,
Jim

1 Like

Tanks this solution looks easy.
I’ve installed the Rule Engine , But I’ve never worked with it before , I’m confused with its options

You can set them up like the time of day pattern.

1 Like

Now that you have the rules engine installed you will see a :“Rules” option in the menu going down the left hand side of PaperUI. Clicking on Rules will take you to the the rule list screen which will be blank since you don’t yet have any rules.

Click on the blue circle with a plus sign in it and then click on “new rule” in the pop-up to create a rule. Then follow these steps

Fill in the Name (e.g. Job 1 Start) field.
Fill in the Description (e.g. Rule to start job 1) field.
Press the blue circle with the plus sign that is beside “When…”
Select “it is a fixed time of day” from the drop down list
Click Next.
Enter the time that you want the rule to run (e.g. enter “08:00 am”)
Click “OK”.
Click the blue circle with the plus sign beside “Then…”
Select “send a command” from the drop down.
Click Next.
Select your switch from the “Item” drop down.
Select “ON” from the “command” drop down
Click OK.
In the upper left had corner there is now a blue circle with a check mark in it. Click on that to save the rule. The rule will now appear in the drop down list.

Repeat those steps for the rule to turn the switch off for Job 1 using the time that you want the item to turn off, and using the “OFF” command instead of the “ON” command.

Job 1 is now scheduled. Repeat the two rules for each of the jobs that you want to schedule.

Jim

1 Like

Thanks Jim, I’ll give it a try

@JimH Thanks Jim , That worked ! :))