Set item by timebound rules

I am looking at using time as a condition for setting the state of an item at startup.

I would like the switch item to be set to on if the time at startup is between 0830 - 2130, and off otherwise.

Any ideas?

Since you want it triggered at startup the “System started” trigger could/should be used.
After that you only need the DateTimes for Now, the starting time and the ending time and compairing them.


rule "Test"

  System started
  logInfo ("Test", "Test started")
  var DateTime NowTime
  var DateTime MidNigth
  var DateTime StartTime=MidNigth.plusMinutes(510)
  var DateTime EndTime=MidNigth.plusMinutes(1290)
  logInfo ("Test", "StartTime: {}", NowTime)
  logInfo ("Test", "StartTime: {}", StartTime)
  logInfo ("Test", "EndTime: {}", EndTime)
  if ((NowTime.isAfter(StartTime)) && (NowTime.isBefore(EndTime))) {
     logInfo ("Test", "is in between") 
  } else {
      logInfo ("Test", "is NOT in between") 

That is awesome, and for anyone reading this later, it works :slight_smile:
Thank you so much!

Just to close the loop, if you have other time periods throughout the day, you can expand opus’s solution using the Time of Day Design Pattern.