Motion sensor During the Day and socket timmer Triggered from Light switch

switch.rules


rule "Time ON 06:00 TO 12:00"

when

    Item TimeRuleTriger received update

    // System started 

    // or

    // Time cron "0 0,30 6,7,8,9,10,11 ? * * *"

then

if( vTimeOfDay2.state == "DAY0600" ||

    vTimeOfDay2.state == "DAY0630" ||

    vTimeOfDay2.state == "DAY0700" ||

    vTimeOfDay2.state == "DAY0730" ||

    vTimeOfDay2.state == "DAY0800" ||

    vTimeOfDay2.state == "DAY0830" ||

    vTimeOfDay2.state == "DAY0900" ||

    vTimeOfDay2.state == "DAY0930" ||

    vTimeOfDay2.state == "DAY1000" ||

    vTimeOfDay2.state == "DAY1030" ||

    vTimeOfDay2.state == "DAY1100" ||

    vTimeOfDay2.state == "DAY1130"  ){

    Time_06_00_TO_12_00 .sendCommand(ON)

    }

else {

    Time_06_00_TO_12_00 .sendCommand(OFF)

    }

end

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

rule "Time ON 07:00 TO 11:00"

when

    Item TimeRuleTriger received update

    // System started 

    // or

    // Time cron "0 30 9 ? * * *"

    // or

    // Time cron "0 0,30 10,11,12,13,14,15,16,17,18,19,20 ? * * *"

    // or

    // Time cron "0 0 21 ? * * *"

    // or

    // Time cron "0 30 21 ? * * *"

then

if (vTimeOfDay2.state == "DAY0700" ||

    vTimeOfDay2.state == "DAY0730" ||

    vTimeOfDay2.state == "DAY0800" ||

    vTimeOfDay2.state == "DAY0830" ||

    vTimeOfDay2.state == "DAY0900" ||

    vTimeOfDay2.state == "DAY0930" ||

    vTimeOfDay2.state == "DAY1000" ||

    vTimeOfDay2.state == "DAY1030"   ){

    Time_07_00_TO_11_00.sendCommand(ON)

    }

else 

{

    Time_07_00_TO_11_00.sendCommand(OFF)

    }

end

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

rule "Time ON 9:00 to 20:30"

when

    Item TimeRuleTriger received update

    // System started 

    // or

    // Time cron "0 30 9 ? * * *"

    // or

    // Time cron "0 0,30 10,11,12,13,14,15,16,17,18,19,20 ? * * *"

    // or

    // Time cron "0 0 21 ? * * *"

    // or

    // Time cron "0 30 21 ? * * *"

then

if (vTimeOfDay2.state == "DAY0900" ||

    vTimeOfDay2.state == "DAY0930" ||

    vTimeOfDay2.state == "DAY1000" ||

    vTimeOfDay2.state == "DAY1030" ||

    vTimeOfDay2.state == "DAY1100" ||

    vTimeOfDay2.state == "DAY1130" ||

    vTimeOfDay2.state == "DAY1200" ||

    vTimeOfDay2.state == "DAY1230" ||

    vTimeOfDay2.state == "DAY1300" ||

    vTimeOfDay2.state == "DAY1330" ||

    vTimeOfDay2.state == "DAY1400" ||

    vTimeOfDay2.state == "DAY1430" ||

    vTimeOfDay2.state == "DAY1500" ||

    vTimeOfDay2.state == "DAY1530" ||

    vTimeOfDay2.state == "DAY1600" ||

    vTimeOfDay2.state == "DAY1630" ||

    vTimeOfDay2.state == "DAY1700" ||

    vTimeOfDay2.state == "DAY1730" ||

    vTimeOfDay2.state == "DAY1800" ||

    vTimeOfDay2.state == "DAY1830" ||

    vTimeOfDay2.state == "DAY1900" ||

    vTimeOfDay2.state == "DAY1930" ||

    vTimeOfDay2.state == "DAY2000"  ){

    Time_09_00_TO_20_30.sendCommand(ON)

    }

else 

{

    Time_09_00_TO_20_30.sendCommand(OFF)

    }

end

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

rule "Motion Sensor Time ON 9:30 to 21:30"

when

    Item TimeRuleTriger received update

    // System started 

    // or

    // Time cron "0 30 9 ? * * *"

    // or

    // Time cron "0 0,30 10,11,12,13,14,15,16,17,18,19,20 ? * * *"

    // or

    // Time cron "0 0 21 ? * * *"

    // or

    // Time cron "0 30 21 ? * * *"

then

if (vTimeOfDay2.state == "DAY0930" ||

    vTimeOfDay2.state == "DAY1000" ||

    vTimeOfDay2.state == "DAY1030" ||

    vTimeOfDay2.state == "DAY1100" ||

    vTimeOfDay2.state == "DAY1130" ||

    vTimeOfDay2.state == "DAY1200" ||

    vTimeOfDay2.state == "DAY1230" ||

    vTimeOfDay2.state == "DAY1300" ||

    vTimeOfDay2.state == "DAY1330" ||

    vTimeOfDay2.state == "DAY1400" ||

    vTimeOfDay2.state == "DAY1430" ||

    vTimeOfDay2.state == "DAY1500" ||

    vTimeOfDay2.state == "DAY1530" ||

    vTimeOfDay2.state == "DAY1600" ||

    vTimeOfDay2.state == "DAY1630" ||

    vTimeOfDay2.state == "DAY1700" ||

    vTimeOfDay2.state == "DAY1730" ||

    vTimeOfDay2.state == "DAY1800" ||

    vTimeOfDay2.state == "DAY1830" ||

    vTimeOfDay2.state == "DAY1900" ||

    vTimeOfDay2.state == "DAY1930" ||

    vTimeOfDay2.state == "DAY2000" ||

    vTimeOfDay2.state == "DAY2030" ||

    vTimeOfDay2.state == "DAY2100"  ){

    Time_09_30_TO_21_30.sendCommand(ON)

    }

else 

{

    Time_09_30_TO_21_30.sendCommand(OFF)

    }

end

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

rule "Time Tost ON 12:00 Next Day 05:30"

when

   Item TimeRuleTriger received update

   // System started 

   // or

   // Time cron "0 0,30 0,1,2,3,4,5,12,13,14,15,16,17,18,19,20,21,22,23 ? * * *"

then

if( vTimeOfDay2.state == "DAY1200" ||

    vTimeOfDay2.state == "DAY1230" ||

    vTimeOfDay2.state == "DAY1300" ||

    vTimeOfDay2.state == "DAY1330" ||

    vTimeOfDay2.state == "DAY1400" ||

    vTimeOfDay2.state == "DAY1430" ||

    vTimeOfDay2.state == "DAY1500" ||

    vTimeOfDay2.state == "DAY1530" ||

    vTimeOfDay2.state == "DAY1600" ||

    vTimeOfDay2.state == "DAY1630" ||

    vTimeOfDay2.state == "DAY1700" ||

    vTimeOfDay2.state == "DAY1730" ||

    vTimeOfDay2.state == "DAY1800" ||

    vTimeOfDay2.state == "DAY1830" ||

    vTimeOfDay2.state == "DAY1900" ||

    vTimeOfDay2.state == "DAY1930" ||

    vTimeOfDay2.state == "DAY2000" ||

    vTimeOfDay2.state == "DAY2030" ||

    vTimeOfDay2.state == "DAY2100" ||

    vTimeOfDay2.state == "DAY2130" ||

    vTimeOfDay2.state == "DAY2200" ||

    vTimeOfDay2.state == "DAY2230" ||

    vTimeOfDay2.state == "DAY2300" ||

    vTimeOfDay2.state == "DAY2330" ||

    vTimeOfDay2.state == "DAY0000" ||

    vTimeOfDay2.state == "DAY0030" ||

    vTimeOfDay2.state == "DAY0100" ||

    vTimeOfDay2.state == "DAY0130" ||

    vTimeOfDay2.state == "DAY0200" ||

    vTimeOfDay2.state == "DAY0230" ||

    vTimeOfDay2.state == "DAY0300" ||

    vTimeOfDay2.state == "DAY0330" ||

    vTimeOfDay2.state == "DAY0400" ||

    vTimeOfDay2.state == "DAY0430" ||

    vTimeOfDay2.state == "DAY0500" ||

    vTimeOfDay2.state == "DAY0530"  ){

    Time_12_30_TO_05_30.sendCommand(ON)

    }

else {

    Time_12_30_TO_05_30.sendCommand(OFF)

    }

end

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

rule "Time ON 14:30 TO 17:30"

when

    Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY1430" ||

    vTimeOfDay2.state == "DAY1500" ||

    vTimeOfDay2.state == "DAY1530" ||

    vTimeOfDay2.state == "DAY1600" ||

    vTimeOfDay2.state == "DAY1630" ||

    vTimeOfDay2.state == "DAY1700"  ){

    Time_14_30_TO_17_30.sendCommand(ON)

    }

else 

{

    Time_14_30_TO_17_30.sendCommand(OFF)

    }

end

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

rule "Time ON 23:00 TO 09:00"

when

    Item TimeRuleTriger received update

    // System started 

    // or

    // Time cron "0 30 23 ? * * *"

    // or

    // Time cron "0 0,30 0,1,2,3,4,5,6,7 ? * * *"

    // or

    // Time cron "0 0 8 ? * * *"

then

if( vTimeOfDay2.state == "DAY2300" ||

    vTimeOfDay2.state == "DAY2330" ||

    vTimeOfDay2.state == "DAY0000" ||

    vTimeOfDay2.state == "DAY0030" ||

    vTimeOfDay2.state == "DAY0100" ||

    vTimeOfDay2.state == "DAY0130" ||

    vTimeOfDay2.state == "DAY0200" ||

    vTimeOfDay2.state == "DAY0230" ||

    vTimeOfDay2.state == "DAY0300" ||

    vTimeOfDay2.state == "DAY0330" ||

    vTimeOfDay2.state == "DAY0400" ||

    vTimeOfDay2.state == "DAY0430" ||

    vTimeOfDay2.state == "DAY0500" ||

    vTimeOfDay2.state == "DAY0530" ||

    vTimeOfDay2.state == "DAY0600" ||

    vTimeOfDay2.state == "DAY0630" ||

    vTimeOfDay2.state == "DAY0700" ||

    vTimeOfDay2.state == "DAY0730" ||

    vTimeOfDay2.state == "DAY0800" ||

    vTimeOfDay2.state == "DAY0830"  ){

    Time_23_00_TO_09_00.sendCommand(ON)

    }

else {

    Time_23_00_TO_09_00.sendCommand(OFF)

    }

end

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

rule "Time ON 23:30 to 09:30"

when

    Item TimeRuleTriger received update

    // System started 

    // or

    // Time cron "0 0,30 23 ? * * *"

    // or

    // Time cron "0 0,30 0,1,2,3,4,5,6,7,8 ? * * *"

    // or

    // Time cron "0 0 9 ? * * *"

then

if( vTimeOfDay2.state == "DAY2300" ||

    vTimeOfDay2.state == "DAY2330" ||

    vTimeOfDay2.state == "DAY0000" ||

    vTimeOfDay2.state == "DAY0030" ||

    vTimeOfDay2.state == "DAY0100" ||

    vTimeOfDay2.state == "DAY0130" ||

    vTimeOfDay2.state == "DAY0200" ||

    vTimeOfDay2.state == "DAY0230" ||

    vTimeOfDay2.state == "DAY0300" ||

    vTimeOfDay2.state == "DAY0330" ||

    vTimeOfDay2.state == "DAY0400" ||

    vTimeOfDay2.state == "DAY0430" ||

    vTimeOfDay2.state == "DAY0500" ||

    vTimeOfDay2.state == "DAY0530" ||

    vTimeOfDay2.state == "DAY0600" ||

    vTimeOfDay2.state == "DAY0630" ||

    vTimeOfDay2.state == "DAY0700" ||

    vTimeOfDay2.state == "DAY0730" ||

    vTimeOfDay2.state == "DAY0800" ||

    vTimeOfDay2.state == "DAY0830" ||

    vTimeOfDay2.state == "DAY0900"  ){

    Time_23_00_TO_09_30.sendCommand(ON)

    }

else {

    Time_23_00_TO_09_30.sendCommand(OFF)

    }

end

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

rule "Time ON 23:30 TO 08:30"

when

    Item TimeRuleTriger received update

    // System started 

    // or

    // Time cron "0 30 23 ? * * *"

    // or

    // Time cron "0 0,30 0,1,2,3,4,5,6,7 ? * * *"

    // or

    // Time cron "0 0 8 ? * * *"

then

if( vTimeOfDay2.state == "DAY2330" ||

    vTimeOfDay2.state == "DAY0000" ||

    vTimeOfDay2.state == "DAY0030" ||

    vTimeOfDay2.state == "DAY0100" ||

    vTimeOfDay2.state == "DAY0130" ||

    vTimeOfDay2.state == "DAY0200" ||

    vTimeOfDay2.state == "DAY0230" ||

    vTimeOfDay2.state == "DAY0300" ||

    vTimeOfDay2.state == "DAY0330" ||

    vTimeOfDay2.state == "DAY0400" ||

    vTimeOfDay2.state == "DAY0430" ||

    vTimeOfDay2.state == "DAY0500" ||

    vTimeOfDay2.state == "DAY0530" ||

    vTimeOfDay2.state == "DAY0600" ||

    vTimeOfDay2.state == "DAY0630" ||

    vTimeOfDay2.state == "DAY0700" ||

    vTimeOfDay2.state == "DAY0730" ||

    vTimeOfDay2.state == "DAY0800"  ){

    Time_23_30_TO_08_30.sendCommand(ON)

    }

else {

    Time_23_30_TO_08_30.sendCommand(OFF)

    }

end

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

// 2 ΩΥΕΣ

rule "Time ON 08:00 to 10:00"

when

    Item TimeRuleTriger received update

  

then

if (vTimeOfDay2.state == "DAY0800" ||

    vTimeOfDay2.state == "DAY0830" ||

    vTimeOfDay2.state == "DAY0900" ||

    vTimeOfDay2.state == "DAY0930"  ){

    Time_08_00_TO_10_00.sendCommand(ON)

    }

else {

    Time_08_00_TO_10_00.sendCommand(OFF)

}

end

rule "Time ON 10:00 to 12:00"

when

 Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY1000" ||

    vTimeOfDay2.state == "DAY1030" ||

    vTimeOfDay2.state == "DAY1100" ||

    vTimeOfDay2.state == "DAY1130"  ){

    Time_10_00_TO_12_00.sendCommand(ON)

    }

else { 

    Time_10_00_TO_12_00.sendCommand(OFF)

}

end

rule "Time ON 12:00 to 14:00"

when

    Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY1200" ||

    vTimeOfDay2.state == "DAY1230" ||

    vTimeOfDay2.state == "DAY1300" ||

    vTimeOfDay2.state == "DAY1330"  ){

    Time_12_00_TO_14_00.sendCommand(ON)

    }

else { 

    Time_12_00_TO_14_00.sendCommand(OFF)

}

end

rule "Time ON 14:00 to 16:00"

when

    Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY1400" ||

    vTimeOfDay2.state == "DAY1430" ||

    vTimeOfDay2.state == "DAY1500" ||

    vTimeOfDay2.state == "DAY1530"  ){

    Time_14_00_TO_16_00.sendCommand(ON)

    }

else { 

    Time_14_00_TO_16_00.sendCommand(OFF)

}

end

rule "Time ON 16:00 to 18:00"

when

    Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY1600" ||

    vTimeOfDay2.state == "DAY1630" ||

    vTimeOfDay2.state == "DAY1700" ||

    vTimeOfDay2.state == "DAY1730"  ){

    Time_16_00_TO_18_00.sendCommand(ON)

    }

else { 

    Time_16_00_TO_18_00.sendCommand(OFF)

}

end

rule "Time ON 18:00 to 20:00"

when

    Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY1800" ||

    vTimeOfDay2.state == "DAY1830" ||

    vTimeOfDay2.state == "DAY1900" ||

    vTimeOfDay2.state == "DAY1930"  ){

    Time_18_00_TO_20_00.sendCommand(ON)

    }

else {

     Time_18_00_TO_20_00.sendCommand(OFF)

}

end

rule "Time ON 20:00 to 22:00"

when

    Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY2000" ||

    vTimeOfDay2.state == "DAY2030" ||

    vTimeOfDay2.state == "DAY2100" ||

    vTimeOfDay2.state == "DAY2130"  ){

    Time_20_00_TO_22_00.sendCommand(ON)

    }

else { 

    Time_20_00_TO_22_00.sendCommand(OFF)

}

end

rule "Time ON 22:00 to 00:00"

when

    Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY2200" ||

    vTimeOfDay2.state == "DAY2230" ||

    vTimeOfDay2.state == "DAY2300" ||

    vTimeOfDay2.state == "DAY2330"  ){

    Time_22_00_TO_00_00.sendCommand(ON)

    }

else { 

    Time_22_00_TO_00_00.sendCommand(OFF)

}

end

rule "Time ON  00:00 to 02:00"

when

    Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY0000" ||

    vTimeOfDay2.state == "DAY0030" ||

    vTimeOfDay2.state == "DAY0100" ||

    vTimeOfDay2.state == "DAY0130"  ){

    Time_00_00_TO_02_00.sendCommand(ON)

    }

else { 

    Time_00_00_TO_02_00.sendCommand(OFF)

}

end

rule "Time ON  02:00 to 04:00"

when

    Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY0200" ||

    vTimeOfDay2.state == "DAY0230" ||

    vTimeOfDay2.state == "DAY0300" ||

    vTimeOfDay2.state == "DAY0330"  ){

    Time_02_00_TO_04_00.sendCommand(ON)

    }

else { 

    Time_02_00_TO_04_00.sendCommand(OFF)

}

end

rule "Time ON  04:00 to 06:00"

when

    Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY0400" ||

    vTimeOfDay2.state == "DAY0430" ||

    vTimeOfDay2.state == "DAY0500" ||

    vTimeOfDay2.state == "DAY0530"  ){

    Time_04_00_TO_06_00.sendCommand(ON)

    }

else { 

    Time_04_00_TO_06_00.sendCommand(OFF)

}

end

rule "Time ON  06:00 to 08:00"

when

    Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY0600" ||

    vTimeOfDay2.state == "DAY0630" ||

    vTimeOfDay2.state == "DAY0700" ||

    vTimeOfDay2.state == "DAY0730"  ){

    Time_06_00_TO_08_00.sendCommand(ON)

    }

else { 

    Time_06_00_TO_08_00.sendCommand(OFF)

}

end

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// 30 ΛΕΠ΀Α

rule "Time ON 08:00 "

when

    Item TimeRuleTriger received update

then

if (vTimeOfDay2.state == "DAY0800"   ){

    Time_08_00.sendCommand(ON)

    }

else {

    Time_08_00.sendCommand(OFF)

}

end

rule "Time ON 08:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0830") {

     Time_08_30.sendCommand(ON)

 }

else {

    Time_08_30.sendCommand(OFF)

    }

end

rule "Time ON 09:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0900") {

     Time_09_00.sendCommand(ON)

 }

else {

    Time_09_00.sendCommand(OFF)

    }

end

rule "Time ON 09:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0930") {

     Time_09_30.sendCommand(ON)

 }

else {

    Time_09_30.sendCommand(OFF)

    }

end

rule "Time ON 10:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1000") {

     Time_10_00.sendCommand(ON)

 }

else {

    Time_10_00.sendCommand(OFF)

    }

end

rule "Time ON 10:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1030") {

     Time_10_30.sendCommand(ON)

 }

else {

    Time_10_30.sendCommand(OFF)

    }

end

rule "Time ON 11:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1100") {

     Time_11_00.sendCommand(ON)

 }

else {

    Time_11_00.sendCommand(OFF)

    }

end

rule "Time ON 11:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1130") {

     Time_11_30.sendCommand(ON)

 }

else {

    Time_11_30.sendCommand(OFF)

    }

end

rule "Time ON 12:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1200") {

     Time_12_00.sendCommand(ON)

 }

else {

    Time_12_00.sendCommand(OFF)

    }

end

rule "Time ON 12:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1230") {

     Time_12_30.sendCommand(ON)

 }

else {

    Time_12_30.sendCommand(OFF)

    }

end

rule "Time ON 13:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1300") {

     Time_13_00.sendCommand(ON)

 }

else {

    Time_13_00.sendCommand(OFF)

    }

end

rule "Time ON 13:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1330") {

     Time_13_30.sendCommand(ON)

 }

else {

    Time_13_30.sendCommand(OFF)

    }

end

rule "Time ON 14:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1400") {

     Time_14_00.sendCommand(ON)

 }

else {

    Time_14_00.sendCommand(OFF)

    }

end

rule "Time ON 14:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1430") {

     Time_14_30.sendCommand(ON)

 }

else {

    Time_14_30.sendCommand(OFF)

    }

end

rule "Time ON 15:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1500") {

     Time_15_00.sendCommand(ON)

 }

else {

    Time_15_00.sendCommand(OFF)

    }

end

rule "Time ON 15:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1530") {

     Time_15_30.sendCommand(ON)

 }

else {

    Time_15_30.sendCommand(OFF)

    }

end

rule "Time ON 16:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1600") {

     Time_16_00.sendCommand(ON)

 }

else {

    Time_16_00.sendCommand(OFF)

    }

end

rule "Time ON 16:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1630") {

     Time_16_30.sendCommand(ON)

 }

else {

    Time_16_30.sendCommand(OFF)

    }

end

rule "Time ON 17:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1700") {

     Time_17_00.sendCommand(ON)

 }

else {

    Time_17_00.sendCommand(OFF)

    }

end

rule "Time ON 17:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1730") {

     Time_17_30.sendCommand(ON)

 }

else {

    Time_17_30.sendCommand(OFF)

    }

end

rule "Time ON 18:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1800") {

     Time_18_00.sendCommand(ON)

 }

else {

    Time_18_00.sendCommand(OFF)

    }

end

rule "Time ON 18:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1830") {

     Time_18_30.sendCommand(ON)

 }

else {

    Time_18_30.sendCommand(OFF)

    }

end

rule "Time ON 19:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1900") {

     Time_19_00.sendCommand(ON)

 }

else {

    Time_19_00.sendCommand(OFF)

    }

end

rule "Time ON 19:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1930") {

     Time_19_30.sendCommand(ON)

 }

else {

    Time_19_30.sendCommand(OFF)

    }

end

rule "Time ON 20:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY2000") {

     Time_20_00.sendCommand(ON)

 }

else {

    Time_20_00.sendCommand(OFF)

    }

end

rule "Time ON 20:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY2030") {

     Time_20_30.sendCommand(ON)

 }

else {

    Time_20_30.sendCommand(OFF)

    }

end

rule "Time ON 21:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY2100") {

     Time_21_00.sendCommand(ON)

 }

else {

    Time_21_00.sendCommand(OFF)

    }

end

rule "Time ON 21:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY2130") {

     Time_21_30.sendCommand(ON)

 }

else {

    Time_21_30.sendCommand(OFF)

    }

end

rule "Time ON 22:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY2200") {

     Time_22_00.sendCommand(ON)

 }

else {

    Time_22_00.sendCommand(OFF)

    }

end

rule "Time ON 22:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY2230") {

     Time_22_30.sendCommand(ON)

 }

else {

    Time_22_30.sendCommand(OFF)

    }

end

rule "Time ON 23:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY2300") {

     Time_23_00.sendCommand(ON)

 }

else {

    Time_23_00.sendCommand(OFF)

    }

end

rule "Time ON 23:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY2330") {

     Time_23_30.sendCommand(ON)

 }

else {

    Time_23_30.sendCommand(OFF)

    }

end

rule "Time ON 00:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0000") {

     Time_00_00.sendCommand(ON)

 }

else {

    Time_00_00.sendCommand(OFF)

    }

end

rule "Time ON 00:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0030") {

     Time_00_30.sendCommand(ON)

 }

else {

    Time_00_30.sendCommand(OFF)

    }

end

rule "Time ON 01:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0100") {

     Time_01_00.sendCommand(ON)

 }

else {

    Time_01_00.sendCommand(OFF)

    }

end

rule "Time ON 01:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0130") {

     Time_01_30.sendCommand(ON)

 }

else {

    Time_01_30.sendCommand(OFF)

    }

end

rule "Time ON 02:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0200") {

     Time_02_00.sendCommand(ON)

 }

else {

    Time_02_00.sendCommand(OFF)

    }

end

rule "Time ON 02:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0230") {

     Time_02_30.sendCommand(ON)

 }

else {

    Time_02_30.sendCommand(OFF)

    }

end

rule "Time ON 03:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0300") {

     Time_03_00.sendCommand(ON)

 }

else {

    Time_03_00.sendCommand(OFF)

    }

end

rule "Time ON 03:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0330") {

     Time_03_30.sendCommand(ON)

 }

else {

    Time_03_30.sendCommand(OFF)

    }

end

rule "Time ON 04:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0400") {

     Time_04_00.sendCommand(ON)

 }

else {

    Time_04_00.sendCommand(OFF)

    }

end

rule "Time ON 04:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0430") {

     Time_04_30.sendCommand(ON)

 }

else {

    Time_04_30.sendCommand(OFF)

    }

end

rule "Time ON 05:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0500") {

     Time_05_00.sendCommand(ON)

 }

else {

    Time_05_00.sendCommand(OFF)

    }

end

rule "Time ON 05:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0530") {

     Time_05_30.sendCommand(ON)

 }

else {

    Time_05_30.sendCommand(OFF)

    }

end

rule "Time ON 06:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0600") {

     Time_06_00.sendCommand(ON)

 }

else {

    Time_06_00.sendCommand(OFF)

    }

end

rule "Time ON 06:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0630") {

     Time_06_30.sendCommand(ON)

 }

else {

    Time_06_30.sendCommand(OFF)

    }

end

rule "Time ON 07:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0700") {

     Time_07_00.sendCommand(ON)

 }

else {

    Time_07_00.sendCommand(OFF)

    }

end

rule "Time ON 07:30"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0730") {

     Time_07_30.sendCommand(ON)

 }

else {

    Time_07_30.sendCommand(OFF)

    }

end

 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// 1 ΩΥΑ

rule "Time ON 00:00 TO 01:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0000" ||

     vTimeOfDay2.state == "DAY0030"  ) {

     Time_00_00_TO_01_00.sendCommand(ON)

 }

else {

    Time_00_00_TO_01_00.sendCommand(OFF)

    }

end

rule "Time ON 01:00 TO 02:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0100" ||

     vTimeOfDay2.state == "DAY0030"  ) {

     Time_01_00_TO_02_00.sendCommand(ON)

 }

else {

    Time_01_00_TO_02_00.sendCommand(OFF)

    }

end

rule "Time ON 02:00 TO 03:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0200" ||

     vTimeOfDay2.state == "DAY0230"  ) {

     Time_02_00_TO_03_00.sendCommand(ON)

 }

else {

    Time_02_00_TO_03_00.sendCommand(OFF)

    }

end

rule "Time ON 03:00 TO 04:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0300" ||

     vTimeOfDay2.state == "DAY0330"  ) {

     Time_03_00_TO_04_00.sendCommand(ON)

 }

else {

    Time_03_00_TO_04_00.sendCommand(OFF)

    }

end

rule "Time ON 04:00 TO 05:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0400" ||

     vTimeOfDay2.state == "DAY0430"  ) {

     Time_04_00_TO_05_00.sendCommand(ON)

 }

else {

    Time_04_00_TO_05_00.sendCommand(OFF)

    }

end

rule "Time ON 05:00 TO 06:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0500" ||

     vTimeOfDay2.state == "DAY0530"  ) {

     Time_05_00_TO_06_00.sendCommand(ON)

 }

else {

    Time_05_00_TO_06_00.sendCommand(OFF)

    }

end

rule "Time ON 06:00 TO 07:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0600" ||

     vTimeOfDay2.state == "DAY0630"  ) {

     Time_06_00_TO_07_00.sendCommand(ON)

 }

else {

    Time_06_00_TO_07_00.sendCommand(OFF)

    }

end

rule "Time ON 07:00 TO 08:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0700" ||

     vTimeOfDay2.state == "DAY0730"  ) {

     Time_07_00_TO_08_00.sendCommand(ON)

 }

else {

    Time_07_00_TO_08_00.sendCommand(OFF)

    }

end

rule "Time ON 08:00 TO 09:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0800" ||

     vTimeOfDay2.state == "DAY0830"  ) {

     Time_08_00_TO_09_00.sendCommand(ON)

 }

else {

    Time_08_00_TO_09_00.sendCommand(OFF)

    }

end

rule "Time ON 09:00 TO 10:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY0900" ||

     vTimeOfDay2.state == "DAY0930"  ) {

     Time_09_00_TO_10_00.sendCommand(ON)

 }

else {

    Time_09_00_TO_10_00.sendCommand(OFF)

    }

end

rule "Time ON 10:00 TO 11:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1000" ||

     vTimeOfDay2.state == "DAY1030"  ) {

     Time_10_00_TO_11_00.sendCommand(ON)

 }

else {

    Time_10_00_TO_11_00.sendCommand(OFF)

    }

end

rule "Time ON 11:00 TO 12:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1100" ||

     vTimeOfDay2.state == "DAY1130"  ) {

     Time_11_00_TO_12_00.sendCommand(ON)

 }

else {

    Time_11_00_TO_12_00.sendCommand(OFF)

    }

end

rule "Time ON 12:00 TO 13:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1200" ||

     vTimeOfDay2.state == "DAY1230"  ) {

     Time_12_00_TO_13_00.sendCommand(ON)

 }

else {

    Time_12_00_TO_13_00.sendCommand(OFF)

    }

end

rule "Time ON 13:00 TO 14:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1300" ||

     vTimeOfDay2.state == "DAY1330"  ) {

     Time_13_00_TO_14_00.sendCommand(ON)

 }

else {

    Time_13_00_TO_14_00.sendCommand(OFF)

    }

end

rule "Time ON 14:00 TO 15:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1400" ||

     vTimeOfDay2.state == "DAY1430"  ) {

     Time_14_00_TO_15_00.sendCommand(ON)

 }

else {

    Time_14_00_TO_15_00.sendCommand(OFF)

    }

end

rule "Time ON 15:00 TO 16:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1500" ||

     vTimeOfDay2.state == "DAY1530"  ) {

     Time_15_00_TO_16_00.sendCommand(ON)

 }

else {

    Time_15_00_TO_16_00.sendCommand(OFF)

    }

end

rule "Time ON 16:00 TO 17:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1600" ||

     vTimeOfDay2.state == "DAY1630"  ) {

     Time_16_00_TO_17_00.sendCommand(ON)

 }

else {

    Time_16_00_TO_17_00.sendCommand(OFF)

    }

end

rule "Time ON 17:00 TO 18:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1700" ||

     vTimeOfDay2.state == "DAY1730"  ) {

     Time_17_00_TO_18_00.sendCommand(ON)

 }

else {

    Time_17_00_TO_18_00.sendCommand(OFF)

    }

end

rule "Time ON 18:00 TO 19:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY1800" ||

     vTimeOfDay2.state == "DAY1830"  ) {

     Time_18_00_TO_19_00.sendCommand(ON)

 }

else {

    Time_18_00_TO_19_00.sendCommand(OFF)

    }

end

rule "Time ON 20:00 TO 21:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY2000" ||

     vTimeOfDay2.state == "DAY2030"  ) {

     Time_20_00_TO_21_00.sendCommand(ON)

 }

else {

    Time_20_00_TO_21_00.sendCommand(OFF)

    }

end

rule "Time ON 21:00 TO 22:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY2100" ||

     vTimeOfDay2.state == "DAY2130"  ) {

     Time_21_00_TO_22_00.sendCommand(ON)

 }

else {

    Time_21_00_TO_22_00.sendCommand(OFF)

    }

end

rule "Time ON 22:00 TO 23:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY2200" ||

     vTimeOfDay2.state == "DAY2230"  ) {

     Time_22_00_TO_23_00.sendCommand(ON)

 }

else {

    Time_22_00_TO_23_00.sendCommand(OFF)

    }

end

rule "Time ON 23:00 TO 00:00"

when

 Item TimeRuleTriger received update

 then

 if (vTimeOfDay2.state == "DAY2300" ||

     vTimeOfDay2.state == "DAY2330"  ) {

     Time_23_00_TO_00_00.sendCommand(ON)

 }

else {

    Time_23_00_TO_00_00.sendCommand(OFF)

    }

end

For the love of Pete why?

This is the worst way to go about this. If all you want is an Rule to trigger every half hour just use cron triggers on those Rules. I’m sorry, but I’m not going to look through hundreds of lines of code looking for some random error.

Add logging to your Rules to figure out what line of code the error is coming from.

But really, this is a really awful way to do what ever it is you are even trying to achieve. I can’t even tell anymore.

example


rule " Time 20:00 to 01:30  Led kitchen ON "

when

  Item CurrentTime  changed or

  Item Motion_Sensor_4_LUMI_Presence changed

then

    if ( Time_20_00_TO_22_00.state == ON || Time_22_00_TO_00_00.state == ON || Time_00_00_TO_01_00.state == ON || Time_01_00.state == ON ) {

        SLed_white_Kitchen.sendCommand("ON")

        SLed_white_Kitchen.postUpdate("ON")

        logInfo(filename, " Time 20:00 to 01:30  Led kitchen ON " )

    }

end

// items

// 30 ΛΕΠ΀Α

Switch      Time_00_00          "00:00"                         <time>      (VtimeOfDay2)   

Switch      Time_00_30          "00:30"                         <time>      (VtimeOfDay2)   

Switch      Time_01_00          "01:00"                         <time>      (VtimeOfDay2)   

// 1 ΩΥΑ

Switch      Time_00_00_TO_01_00 "00:00 >>> 01:00"               <time>      (VtimeOfDay2)   

Switch      Time_01_00_TO_02_00 "01:00 >>> 02:00"               <time>      (VtimeOfDay2)   

// 2 ΩΥΕΣ

Switch      Time_00_00_TO_02_00 "00:00 >>> 02:00"               <time>      (vTimeOfDay2)   

Switch      Time_02_00_TO_04_00 "02:00 >>> 04:00"               <time>      (vTimeOfDay2)

so i have for all hours switch timer

There are soooo many better tools at your disposal to do this.

if(now.getHourOfDay >20 || now.getHourOfDay <= 1)

Can replace

if ( Time_20_00_TO_22_00.state == ON || Time_22_00_TO_00_00.state == ON || Time_00_00_TO_01_00.state == ON || Time_01_00.state == ON ) {

And ALL of those Items.

Or, you can use the Time of Day design pattern properly and set a vTimeOfDay to “NIGHT” starting at 20:00 and ending at 01:00 and use

if(vTimeOfDay.state == "NIGHT")

in place of that.

In both cases you can eliminate hundreds of lines of code and dozens of Items and have code that is easier to read and understand.

To trigger a Rule at 20:00 use a Time cron trigger (which you already know how to do) or

Item vTimeOfDay changed to NIGHT

As best I can tell you are basically doing everything twice.

Rather than needing to do

if( vTimeOfDay2.state == "DAY0600" ||

    vTimeOfDay2.state == "DAY0630" ||

    vTimeOfDay2.state == "DAY0700" ||

    vTimeOfDay2.state == "DAY0730" ||

    vTimeOfDay2.state == "DAY0800" ||

    vTimeOfDay2.state == "DAY0830" ||

    vTimeOfDay2.state == "DAY0900" ||

    vTimeOfDay2.state == "DAY0930" ||

    vTimeOfDay2.state == "DAY1000" ||

    vTimeOfDay2.state == "DAY1030" ||

    vTimeOfDay2.state == "DAY1100" ||

    vTimeOfDay2.state == "DAY1130"  ){

Why not

    if(vTimeOfDay2.state == "MORNING"){

And just write the time of day Rule so vTimeOfDay2 remains set to “MORNING” between 06:00 and 11:30?

That’s how it’s supposed to work. If you try to use a design pattern and your code becomes longer and more complex you are not applying it correctly.

I am using your code
but I have a question
in winter curr = “AFTERNOON” // 17:00
what shall I do
thank you

    case now.isAfter(day17_30_start)       && now.isBefore(afternoon_start): curr = "QUITE_17_30"  // 17:30 

    case now.isAfter(afternoon_start)      && now.isBefore(day21_30_start):  curr = "AFTERNOON"    // 19:05
val logName = "Calc tod-state"

rule "Calculate time of day state" 

when

  System started or // run at system start in case the time changed when OH was offline

  Channel 'astro:sun:home:rise#event'    triggered START or

  Channel 'astro:sun:home:set#event'     triggered START or

  Channel 'astro:sun:minus90:set#event'  triggered START or

  Time cron "0 1 0 * * ? *" or // one minute after midnight so give Astro time to calculate the new day's times

  Time cron "0 0 6 * * ? *" or

  Time cron "0 0 23 * * ? *" or

  Time cron "0 0 9 ? * * *" or

  Time cron "0 0,30 11 ? * * *" or

  Time cron "0 0,30 14 ? * * *" or

  Time cron "0 0,30 17 ? * * *" or

  Item TimeRuleTriger received update

   

then

  logInfo(logName, "Calculating time of day...")

  // Calculate the times for the static tods and populate the associated Items

  // Update when changing static times

  // Jump to tomorrow and subtract to avoid problems at the change over to/from DST

   val day09_00_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(15)                             // 09:00

   vDay09_00_start_Time.postUpdate(day09_00_start.toString)

  val day11_30_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(13).plusMinutes(30)               // 11:30

   vDay11_30_start_Time.postUpdate(day11_30_start.toString)

   val day17_30_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(7).plusMinutes(30)                // 17:30

   vDay17_30_start_Time.postUpdate(day17_30_start.toString)

  val day14_30_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(10).plusMinutes(30)               // 14:30

   vDay14_30_start_Time.postUpdate(day14_30_start.toString)

  val day21_30_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(3).plusMinutes(30)                   // 21:30

   vDay21_30_start_Time.postUpdate(day21_30_start.toString)

  val morning_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(18)

  vMorning_Time.postUpdate(morning_start.toString) 

  val night_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(1)

  vNight_Time.postUpdate(night_start.toString)

  val bed_start = now.withTimeAtStartOfDay

  vBed_Time.postUpdate(bed_start.toString)

  // Convert the Astro Items to Joda DateTime

  val day_start = new DateTime(vSunrise_Time.state.toString) 

  val evening_start = new DateTime(vSunset_Time.state.toString)

  val afternoon_start = new DateTime(vEvening_Time.state.toString)

  // Calculate the current time of day

  var curr = "UNKNOWN"

  switch now {

    case now.isAfter(morning_start)        && now.isBefore(day_start):       curr = "MORNING"      // 06:00

    case now.isAfter(day_start)            && now.isBefore(day09_00_start):  curr = "DAY"          // 07:07

    case now.isAfter(day09_00_start)       && now.isBefore(day11_30_start):  curr = "DAY_9"        // 09:00 

    case now.isAfter(day11_30_start)       && now.isBefore(day14_30_start):  curr = "DAY_11_30"    // 11:30 

    case now.isAfter(day14_30_start)       && now.isBefore(evening_start):   curr = "QUITE_14_30"  // 14:30 

    case now.isAfter(evening_start)        && now.isBefore(day17_30_start):  curr = "EVENING"      // 16:33

    case now.isAfter(day17_30_start)       && now.isBefore(afternoon_start): curr = "QUITE_17_30"  // 17:30 

    case now.isAfter(afternoon_start)      && now.isBefore(day21_30_start):  curr = "AFTERNOON"    // 19:05

    case now.isAfter(day21_30_start)       && now.isBefore(night_start):     curr = "DAY_21_30"    // 21:30

    case now.isAfter(night_start):                                           curr = "NIGHT"        // 23:00

    case now.isAfter(bed_start)            && now.isBefore(morning_start):   curr = "BED"          // 00:00

  }

  // Publish the current state

  logInfo(logName, "Calculated time of day is " + curr)

  vTimeOfDay.sendCommand(curr)

end

// "MORNING"      // 06:00

// "DAY"          // 07:07

// "DAY_9"        // 09:00

// "DAY_11_30"    // 11:30

// "QUITE_14_30"  // 14:30

// "EVENING"      // 16:33

// "QUITE_17_30"  // 17:30

// "AFTERNOON"    // 19:05

// "DAY_21_30"    // 21:30

// "NIGHT"        // 23:00

// "BED"          // 00:00

Here is another attempt at explaining how this Rule works.

You break your day into time periods. Each time period has a name which should be meaningful and a start time. A time period lasts from the start time until the start of the next time period.

The Rule gets triggered at the start of every time period and at System started. You must have a trigger that causes the Rule to run at the start of every time period you have defined. Some of those start times may be defined by the Astro binding in which cases use the appropriate Channel trigger. Otherwise use a cron trigger that runs the Rule at the start of each time period.

When the Rule runs, it first gets or generates a DateTime for the start of each time period. This comes from an Item or by manipulating now.

Then we have a switch statement that checks to see if now is between the start of one time period and the start of the following time period. The checks must be in order starting with the first time period of the day.

Finally, we publish the name of the time of day to vTimeOfDay.

That’s all there is to it. So if you want to insert new time periods you just first:

  • come up with it’s start time and name
  • add a trigger to the Rule to cause the Rule to run at that start time
  • add a line to get the start time as a DateTime
  • Add a new case to the switch to test is now isAfter the start time and before the following time of day’s start time. You need to insert this case statement after the one that tests for the time period that occurs before this one and you need to change that case statement to check for isBefore this new time period’s start time.

So you want to change the start time for AFTERNOON? Go through the steps above:

  • modify the Rule trigger so it runs the rule at the new time
  • modify the creation of afternoon_start with the new start time (NOTE, in the original code afternoon_start is defined by an Astro event, not a static time)

You are not adding a new time period so you don’t need to change anything else.

@ rlkoshak Hello
I added to your code two extra hours

TimeOfDay.rules


val logName = "Calc tod-state "

// vTimeOfDay3.   

// "DAY_00_00" // 00:00

// "DAY_06_00" // 06:00

// "DAY_07_00" // 07:00

// "DAY_09_00" // 09:00

// "DAY_11_30" // 11:30

// "DAY_14_30" // 14:30

// "DAY_17_30" // 17:30

// "DAY_20_30" // 20:30

// "DAY_21_30" // 21:30

// "DAY_23_00" // 23:00

 

rule "Calculate time of day state" 

when

  System started or // run at system start in case the time changed when OH was offline

  Channel 'astro:sun:home:rise#event'    triggered START or

  Channel 'astro:sun:home:set#event'     triggered START or

  Channel 'astro:sun:minus90:set#event'  triggered START or

  Time cron "0 1 0 * * ? *" or // one minute after midnight so give Astro time to calculate the new day's times

  Time cron "0 0 6 * * ? *" or

  Time cron "0 0 11 * * ? *" or

  Time cron "0 0 22 * * ? *" or

  Time cron "0 0 23 * * ? *"

then

  logInfo(logName, "Calculating time of day...")

  // Calculate the times for the static tods and populate the associated Items

  // Update when changing static times

  // Jump to tomorrow and subtract to avoid problems at the change over to/from DST

   val night1_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(2)                                   // 22:00

   vNight1_start_Time.postUpdate(night1_start.toString)

  val morning_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(18)

  vMorning_Time.postUpdate(morning_start.toString) 

  val night_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(1)

  vNight_Time.postUpdate(night_start.toString)

   val noon_start_Time = now.withTimeAtStartOfDay.plusDays(1).minusHours(13)                             // 11:00

   vNoon_start_Time.postUpdate(noon_start_Time.toString)

  val bed_start = now.withTimeAtStartOfDay

  vBed_Time.postUpdate(bed_start.toString)

  // Convert the Astro Items to Joda DateTime

  val day_start = new DateTime(vSunrise_Time.state.toString) 

  val evening_start = new DateTime(vSunset_Time.state.toString)

  val afternoon_start = new DateTime(vEvening_Time.state.toString)

  // Calculate the current time of day

  var curr = "UNKNOWN"

  switch now {

    case now.isAfter(morning_start)   &&  now.isBefore(day_start):       curr = "MORNING"

    case now.isAfter(day_start)       &&  now.isBefore(noon_start_Time): curr = "DAY" 

    case now.isAfter(noon_start_Time) &&  now.isBefore(afternoon_start): curr = "NOON"

    case now.isAfter(evening_start)   &&  now.isBefore(afternoon_start): curr = "EVENING" 

    case now.isAfter(afternoon_start) &&  now.isBefore(night1_start):    curr = "AFTERNOON"

    case now.isAfter(night1_start)    &&  now.isBefore(night_start):     curr = "NIGHT_22" 

    case now.isAfter(night_start):                                       curr = "NIGHT"

    case now.isAfter(bed_start)       &&  now.isBefore(morning_start):   curr = "BED"

  }

  // Publish the current state

  logInfo(logName, "Calculated time of day is " + curr)

  vTimeOfDay.sendCommand(curr)

end

create switch TimeOfDay.rules
switch.rules


// TIME OF DAY.rules

// vTimeOfDay.state ==  

// "MORNING"    // 06:00

// "DAY"        // 07:00

// "NOON"       // 11:00

// "EVENING"    // 16:41

// "AFTERNOON"  // 19:13

// "NIGHT_22"   // 22:00

// "NIGHT"      // 23:00

// "BED"        // 00:00

rule "Time ON 11:00 To 06:00"

when

    System started or  // run at system start in case the time changed when OH was offline

    Item vTimeOfDay changed to NOON       or

    Item vTimeOfDay changed to EVENING    or

    Item vTimeOfDay changed to AFTERNOON  or

    Item vTimeOfDay changed to NIGHT_22   or

    Item vTimeOfDay changed to NIGHT      or

    Item vTimeOfDay changed to BED        or

    Item vTimeOfDay changed to MORNING

then

if( vTimeOfDay.state == "NOON"       ||

    vTimeOfDay.state == "EVENING"    ||

    vTimeOfDay.state == "AFTERNOON"  || 

    vTimeOfDay.state == "NIGHT_22"   ||

    vTimeOfDay.state == "NIGHT"      ||

    vTimeOfDay.state == "BED"         ){

    Time_11_00_TO_06_00.sendCommand(ON)

    }

else {

    Time_11_00_TO_06_00.sendCommand(OFF)

    }    

end

rule "Time ON 07:00 To 22:00"

when

    System started or  // run at system start in case the time changed when OH was offline

    Item vTimeOfDay changed to DAY       or

    Item vTimeOfDay changed to NOON      or

    Item vTimeOfDay changed to EVENING   or

    Item vTimeOfDay changed to AFTERNOON or

    Item vTimeOfDay changed to DAY

then

if( vTimeOfDay.state == "DAY"        ||

    vTimeOfDay.state == "NOON"       ||

    vTimeOfDay.state == "EVENING"    ||

    vTimeOfDay.state == "AFTERNOON"   ){

    Time_07_00_TO_22_00.sendCommand(ON)

    }

else {

    Time_07_00_TO_22_00.sendCommand(OFF)

    }    

end

rule "Time ON 06:00 To 11:00"

when

    System started or  // run at system start in case the time changed when OH was offline

    Item vTimeOfDay changed to DAY       or

    Item vTimeOfDay changed to NOON      or

    Item vTimeOfDay changed to EVENING   or

    Item vTimeOfDay changed to AFTERNOON or

    Item vTimeOfDay changed to NIGHT_22  or

    Item vTimeOfDay changed to NIGHT

then

if( vTimeOfDay.state == "DAY"        ||

    vTimeOfDay.state == "NOON"       ||

    vTimeOfDay.state == "EVENING"    ||

    vTimeOfDay.state == "AFTERNOON"  ||

    vTimeOfDay.state == "NIGHT_22"    ){

    Time_06_00_TO_11_00.sendCommand(ON)

    }

else {

    Time_06_00_TO_11_00.sendCommand(OFF)

    }

end

rule "Time ON 06:00 To 11:00"

when

    System started or  // run at system start in case the time changed when OH was offline

    Item vTimeOfDay changed to MORNING    or

    Item vTimeOfDay changed to DAY        or

    Item vTimeOfDay changed to NOON

then

if( vTimeOfDay.state == "MORNING"  ||

    vTimeOfDay.state == "DAY"       ){

    Time_06_00_TO_11_00.sendCommand(ON)

    }

else {

    Time_06_00_TO_11_00.sendCommand(OFF)

    }

end

rule "Night To Day Start"

when

    System started or  // run at system start in case the time changed when OH was offline

    Item vTimeOfDay changed to NIGHT    or

    Item vTimeOfDay changed to BED      or

    Item vTimeOfDay changed to MORNING  or

    Item vTimeOfDay changed to DAY

then

if( vTimeOfDay.state == "NIGHT"   ||

    vTimeOfDay.state == "BED"     ||

    vTimeOfDay.state == "MORNING"   ){

    Night_To_Day_Start.sendCommand(ON)

    }

else {

    Night_To_Day_Start.sendCommand(OFF)

    }

end

rule "Night Time"

when

    System started or  // run at system start in case the time changed when OH was offline

    Item vTimeOfDay changed to AFTERNOON or

    Item vTimeOfDay changed to NIGHT     or

    Item vTimeOfDay changed to BED       or

    Item vTimeOfDay changed to MORNING   or

    Item vTimeOfDay changed to DAY

then

if( vTimeOfDay.state == "AFTERNOON"  ||

    vTimeOfDay.state == "NIGHT"      ||

    vTimeOfDay.state == "BED"        ||

    vTimeOfDay.state == "MORNING"   ){

    NightTime.sendCommand(ON)

    }

else {

    NightTime.sendCommand(OFF)

    }

end

try to get to specific times switch
but I do not know how to do it
the way you showed me
I don’t understand how it works

if(now.getHourOfDay >20 || now.getHourOfDay <= 1)

the times I want to be


Switch      Time_23_30_TO_09_30     "23:30 next day 09:30"                               <time>          

Switch      Time_10_00_TO_05_30     "10:00 next day 05:30"                               <time>          

Switch      Time_14_30_TO_17_30     "14:30 >>> 17:30"

@ 5iver it helped me to a rule
quiet time
i got the code and we are using it in a switch

but I do not understand what he has done


rule "duite"

when

  Item TimeRuleTriger received update

then 

 if (now.getMinuteOfDay < 60 * 14 + 30 || now.getMinuteOfDay < 60 * 17 + 30){

     Quite_14_30_to_17_30.sendCommand(ON)

 }

else

{

    Quite_14_30_to_17_30.sendCommand(OFF)

}

end

if you could explain it to me
thank you


Switch      Time_23_30_TO_09_30     "23:30 next day 09:30"                               <time>      

Switch      Time_14_30_TO_17_30     "14:30 >>> 17:30"

I don’t know if it’s a good idea
what I want to do
thank you

That’s the part that doesn’t make sense. Why??? The whole point of my previous replies, the whole point of the Time of Day design pattern, is that you don’t need and shouldn’t use specific time switches at all.

Then figure out which times of day cover those time periods and check. Lets say that covers NIGHT, DAY and QUIET_TIME. Then you

if(vTimeOfDay.state == "NIGHT" || vTimeOfDay.state == "DAY" || vTimeOfDay.state == "QUIET_TIME")

You don’t need the Switches. You shouldn’t be using the switches. The whole point of the Time of Day code is so you don’t have to use the Switches.

Even if you don’t use the Time of Day code, you shouldn’t be using the Switches. You can use now to get what time it currently is.

Exactly the same thing I did with if(now.getHourOfDay > 20 || now.getHourOfDay <= 1) only he used minutes instead of hours. If the time is currently between 14:30 and 17:30 the if conditional returns true and Quiet_14_30_to_17_30 is commanded to ON.

If that’s the way you want to track time then get rid of the time of day stuff entirely. You don’t need both.

It would probably be a good thing for you to take an online programming course as well. These are pretty basic programming concepts you are struggling with which are pretty universal across all programming languages. If you take a intro to programming course like the ones offered for free from various sites simple stuff like if statements will make more sense.