Astro events on sunrise/sunset

With openHAB2, how can I implement rules based on astro events such as sunrise/sunset e.g. to turn lights ON at sunset (also with offset)?

Hi Joacim,

in OH2 there are no longer Sunrise and other events. As far as i under stand it is planned that the rule engine will get sooner or later the possibility to trigger on specific times. If have solved the problem in the folowing way, based on some advices from the forum.

I Have created a String Item that hold the time of Day as a String. With a rule i check every minute for the events.

rule "Check every Minute"
when
Time cron "30 * * * * ?"
then

val myRange = 60

var DateTime mynow = now

// we try to build the event function of Astro Binding 1.x to determine the right day time
// to assure that we do not miss the right event, we check if the time value is within a range of one minute
logInfo(“rule.system”,“Again a minute is gone”)
if (mynow.plusSeconds(myRange).isAfter((OhVl_NightStart_Value.state as DateTimeType).calendar.timeInMillis) &&
mynow.minusSeconds(myRange).isBefore((OhVl_NightStart_Value.state as DateTimeType).calendar.timeInMillis) &&
(OhVl_TimeofDay.state.toString() !=“Nacht”))
{

  OhVl_TimeofDay.sendCommand("Nacht")
  logInfo("rule.system","Minute trigger sucsessfull triggered")

}
else if (mynow.plusSeconds(myRange).isAfter((OhVl_DawnStart_Value.state as DateTimeType).calendar.timeInMillis) &&
mynow.minusSeconds(myRange).isBefore((OhVl_DawnStart_Value.state as DateTimeType).calendar.timeInMillis) &&
(OhVl_TimeofDay.state.toString() !=“Morgendämmerung”))
{

  OhVl_TimeofDay.sendCommand("Morgendämmerung")
  logInfo("rule.system","Minute trigger sucsessfull triggered")

}
else if (mynow.plusSeconds(myRange).isAfter((OhVl_DaylightStart_Value.state as DateTimeType).calendar.timeInMillis) &&
mynow.minusSeconds(myRange).isBefore((OhVl_DaylightStart_Value.state as DateTimeType).calendar.timeInMillis) &&
(OhVl_TimeofDay.state.toString() !=“Tag”))
{

  OhVl_TimeofDay.sendCommand("Tag")
  logInfo("rule.system","Minute trigger sucsessfull triggered")

}
else if (mynow.plusSeconds(myRange).isAfter((OhVl_DuskStart_Value.state as DateTimeType).calendar.timeInMillis) &&
mynow.minusSeconds(myRange).isBefore((OhVl_DuskStart_Value.state as DateTimeType).calendar.timeInMillis) &&
(OhVl_TimeofDay.state.toString() !=“Abenddämmerung”))
{

  OhVl_TimeofDay.sendCommand("Abenddämmerung")
  logInfo("rule.system","Minute trigger sucsessfull triggered")

}

end

Thanks Thomas for your input.

I guessed it was like that but didn’t want to believe it :slight_smile: since I think it is a core feature to control based on sunset/sunrise and OH2 currently on Beta 3.

Any input from OH developers?

1 Like

You can simply use the OH1 binding, which has the feature you ask, under OH2. That works nice for me.

Right, this is the best advice!

For the rest, see https://github.com/openhab/openhab2-addons/issues/310.

For reference: The missing events are the only real downside of the new Astro binding.
There are a few workarounds, one given here: Sun (raised / set) indicator