Tolotos
(Tolotos)
October 21, 2018, 3:19pm
1
Hi,
I want to define time spans in a rule to controll the heaters.
Is it possible to define somthing like this:
// {{ON_1, OFF_1}, {ON_n, OFF_n}}
val heatingTimesMonday[][] = {{"5:00", "7:00"}, {"12:30", 21:00}}
val heatingTimesTuesday[][] = {{"5:00", "7:00"}, {"14:30", 21:00}}
val heatingTimesWednesday[][] = {{"5:00", "7:00"}, {"12:30", 14:00}, {"16:00", "21:00"}}
val heatingTimesThursday[][] = {{"5:00", "7:00"}, {"12:30", 21:00}}
val heatingTimesFriday[][] = {{"5:00", "7:00"}, {"12:30", 23:00}}
val heatingTimesSaturday[][] = {{"6:30", 23:00}}
val heatingTimesSunday[][] = {{"6:30", 21:00}}
And how can I check in a rule if the current time is in one of the time spans?
H102
(CM6.5 H102)
October 21, 2018, 3:35pm
2
Would something like this work for time:
if((now.getHourOfDay() >= 8) && (now.getHourOfDay() <= 20)){
Heater.sendCommand(ON)
Tolotos
(Tolotos)
October 21, 2018, 3:41pm
3
For WAF I need minutes too.
And the time definitions should be outside of the code to do changes smarter.
EDIT:
I think this will be a starting point:
val heatingTimesMonday = "5:00, 7:00, 12:30, 21:00".split(',')
var ii = 0
while (ii < heatingTimesMonday.length) {
logInfo("all.rules", "calculate Timespan " + heatingTimesMonday.get(ii) + " ==> " + heatingTimesMonday.get(ii + 1))
ii = ii + 2
}
H102
(CM6.5 H102)
October 21, 2018, 4:17pm
4
For the day of week you can also use something like this:
var Number day = now.getDayOfWeek
if ((day == 1) || (day == 2) || (day == 3) || (day == 4) || (day == 5)) {
Not sure but I think Monday = 1 Tuesday = 2 etc…
Have you looked at maybe using the Astro binding?
Tolotos
(Tolotos)
October 21, 2018, 4:22pm
5
Thanks,
A further question is: how can I create a DateTime for the current day and the time I have as one of the above strings? Like
val startDT = now
startDT.setHour("08:30".split(':').get(0))
startDT.setMinute("08:30".split(':').get(1))
H102
(CM6.5 H102)
October 21, 2018, 4:36pm
6
Maybe you can tweak this so suit your needs:
rule "Calculate time of day state"
when
Time cron "0 * * ? * *"
then
val String curr_time = now.toString("HH:mm")
val String night_start = "00:00"
var String morning_start = "06:00"
val String day_start = (Sun_Dawn_Start.state as DateTimeType).format("%1$tH:%1$tM")
val String evening_start = (Sun_Dusk_End.state as DateTimeType).format("%1$tH:%1$tM")
val String midnight_time = "24:00"
var new_val = "UNKNOWN"
if (day_start < morning_start) {
morning_start = day_start
}
switch true {
case night_start <= curr_time && curr_time < morning_start: new_val = "NIGHT"
case morning_start <= curr_time && curr_time < day_start: new_val = "MORNING"
case day_start <= curr_time && curr_time < evening_start: new_val = "DAY"
case evening_start <= curr_time && curr_time < midnight_time: new_val = "EVENING"
}
// logInfo("Time_Of_Day", "curr_time=" + curr_time + ", night_start=" + night_start + ", morning_start=" + morning_start
// + ", day_start=" + day_start + ", evening_start=" + evening_start + ", midnight_time=" + midnight_time
// + ", new_val=" + new_val)
if (Time_Of_Day.state.toString != new_val) {
logInfo("Time_Of_Day", "Current time of day is now " + new_val)
Time_Of_Day.sendCommand(new_val)
}
end
Tolotos
(Tolotos)
October 21, 2018, 5:32pm
7
val heatingTimesMonday = "5:00, 7:00, 12:30, 21:00".split(',')
var switchHeaterOn = false
var ii = 0
while (ii < heatingTimesMonday.length) {
val heatingOn = heatingTimesMonday.get(ii)
val heatingOff = heatingTimesMonday.get(ii + 1)
var onDT = new DateTime(now.toLocalDate().getYear(),
now.toLocalDate().getMonthOfYear(),
now.toLocalDate().getDayOfMonth(),
Integer::parseInt(heatingOn.split(':').get(0).trim()),
Integer::parseInt(heatingOn.split(':').get(1).trim()))
var offDT = new DateTime(now.toLocalDate().getYear(),
now.toLocalDate().getMonthOfYear(),
now.toLocalDate().getDayOfMonth(),
Integer::parseInt(heatingOff.split(':').get(0).trim()),
Integer::parseInt(heatingOff.split(':').get(1).trim()))
if(now.isAfter(onDT) && now.isBefore(offDT) {
switchHeaterOn = true
}
ii = ii + 2
}