and if you are asking about what is inside astro.rules, here it is.
delta04@oh-main-dk:~/docker/smarthome$ cat openhab/conf/rules/astro.rules
import java.util.Date
// Time of Day Rules
// Requires time update every 60 seconds
val String RFN = “time-of-day.rules”
rule “Get time period for right now”
when
System started
then
val now = new Date()
val dawn = new Date((DawnStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val day = new Date((DayStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val dusk = new Date((DuskStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val night = new Date((NightStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
// val sunset = new Date((SunsetStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
// val sunrise = new Date((SunriseStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val String initStr = "Initializing time period. The time of day is "
if(now.after(dawn) && now.before(day)) {
logInfo(RFN, initStr + "Dawn: " + now)
Dawn.sendCommand(ON)
Day.sendCommand(OFF)
Dusk.sendCommand(OFF)
Night.sendCommand(OFF)
TimePeriodOfDay.postUpdate("Dawn")
}
else if(now.after(day) && now.before(dusk)) {
logInfo(RFN, initStr + "Day: " + now)
Dawn.sendCommand(OFF)
Day.sendCommand(ON)
Dusk.sendCommand(OFF)
Night.sendCommand(OFF)
TimePeriodOfDay.postUpdate("Day")
}
else if(now.after(dusk) && now.before(night)) {
logInfo(RFN, initStr + "Dusk: " + now)
Dawn.sendCommand(OFF)
Day.sendCommand(OFF)
Dusk.sendCommand(ON)
Night.sendCommand(OFF)
TimePeriodOfDay.postUpdate("Dusk")
}
else {
logInfo(RFN, initStr + "Night: " + now)
Dawn.sendCommand(OFF)
Day.sendCommand(OFF)
Dusk.sendCommand(OFF)
Night.sendCommand(ON)
TimePeriodOfDay.postUpdate("Night")
}
end
rule “Generate Time of Day Events”
when
Item CurrentTime received update
then
val now = new Date()
val dawn = new Date((DawnStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val day = new Date((DayStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val dusk = new Date((DuskStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val night = new Date((NightStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val sunset = new Date((SunsetStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val sunrise = new Date((SunriseStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
if((now.getTime-(now.getTime%60000)) == (dawn.getTime-(dawn.getTime%60000))) {
logInfo(RFN, "Transitioning to Dawn!!!")
DawnStart_Event.postUpdate(ON)
}
else if((now.getTime-(now.getTime%60000)) == (day.getTime-(day.getTime%60000))) {
logInfo(RFN, "Transitioning to Day!!!")
DayStart_Event.postUpdate(ON)
}
else if((now.getTime-(now.getTime%60000)) == (dusk.getTime-(dusk.getTime%60000))) {
logInfo(RFN, "Transitioning to Dusk!!!")
DuskStart_Event.postUpdate(ON)
}
else if((now.getTime-(now.getTime%60000)) == (night.getTime-(night.getTime%60000))) {
logInfo(RFN, "Transitioning to Night!!!")
NightStart_Event.postUpdate(ON)
}
if((now.getTime-(now.getTime%60000)) == (sunrise.getTime-(sunrise.getTime%60000))) {
logInfo(RFN, "Start of Sunrise!")
SunriseStart_Event.postUpdate(ON)
}
else if((now.getTime-(now.getTime%60000)) == (sunset.getTime-(sunset.getTime%60000))) {
logInfo(RFN, "Start of Sunset!")
SunsetStart_Event.postUpdate(ON)
}
end
rule “Dawn Started”
when
Item DawnStart_Event received update ON
then
val now = new Date()
val dawn = new Date((DawnStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val day = new Date((DayStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
if(now.after(dawn) && now.before(day)) {
logInfo(RFN, "Its Dawn: " + now)
Dawn.sendCommand(ON)
Day.sendCommand(OFF)
Dusk.sendCommand(OFF)
Night.sendCommand(OFF)
TimePeriodOfDay.postUpdate("Dawn")
}
end
rule “Day Started”
when
Item DayStart_Event received update ON
then
val now = new Date()
val day = new Date((DayStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val dusk = new Date((DuskStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
if(now.after(day) && now.before(dusk)) {
logInfo(RFN, "Its Day: " + now)
Dawn.sendCommand(OFF)
Day.sendCommand(ON)
Dusk.sendCommand(OFF)
Night.sendCommand(OFF)
TimePeriodOfDay.postUpdate("Day")
}
end
rule “Dusk started”
when
Item DuskStart_Event received update ON
then
val now = new Date()
val dusk = new Date((DuskStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val night = new Date((NightStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
if(now.after(dusk) && now.before(night)) {
logInfo(RFN, "Its Dusk: " + now)
Dawn.sendCommand(OFF)
Day.sendCommand(OFF)
Dusk.sendCommand(ON)
Night.sendCommand(OFF)
TimePeriodOfDay.postUpdate("Dusk")
}
end
rule “Night started”
when
Item NightStart_Event received update ON
then
val now = new Date()
val morningNightStart = new Date((MorningNightStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val morningNightStop = new Date((MorningNightStop_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val eveningNightStart = new Date((EveningNightStart_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
val eveningNightStop = new Date((EveningNightStop_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
if((now.after(morningNightStart) && now.before(morningNightStop)) ||
(now.after(eveningNightStart) && now.before(eveningNightStop))) {
logInfo(RFN, "Its Night: " + now)
Dawn.sendCommand(OFF)
Day.sendCommand(OFF)
Dusk.sendCommand(OFF)
Night.sendCommand(ON)
TimePeriodOfDay.postUpdate("Night")
}
end
rule “Sunrise started”
when
Item SunriseStart_Event received update ON
then
val now = new Date()
logInfo(RFN, "Its Sunrise : " + now)
end
rule “Sunset started”
when
Item SunsetStart_Event received update ON
then
val now = new Date()
logInfo(RFN, "Its Sunset : " + now)
end