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?
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.
Like:
rule "Test"
when
System started
then
logInfo ("Test", "Test started")
var DateTime NowTime =DateTime.now
var DateTime MidNigth =DateTime.now.withTimeAtStartOfDay
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")
}
end
Wow!
That is awesome, and for anyone reading this later, it works
Thank you so much!
Paul
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.