Astro binding issue?


I seem to have a possible issue with the Astro binding.
In the classic ui there is no sun set or rise time being displayed. Azimuth and Elevation do work!
I also notice in the log that sometimes the wrong times are channeled to the items.

Please see below configuration.
astro:sun:home [ geolocation=“51.3650513,4.5563699”, interval=60 ]
DateTime Zon_Op_Tijd “Zon op [%1$tH:%1$tM]” { channel=“astro:sun:home:rise#start” }
DateTime Zon_Onder_Tijd “Zon onder [%1$tH:%1$tM]” { channel=“astro:sun:home:set#start” }
Switch Zon_Op_Event { channel=“astro:sun:home:rise#start” }
Switch Zon_Onder_Event { channel=“astro:sun:home:set#start” }
Text item=Zon_Onder_Tijd
Text item=Zon_Op_Tijd
2015-08-24 03:32:09 - Zon_Op_Tijd updated to 2015-08-24T06:43:00
2015-08-24 03:32:09 - Zon_Op_Event updated to 2015-08-24T06:43:00
2015-08-24 03:32:09 - Zon_Onder_Tijd updated to 2015-08-24T20:45:00
2015-08-24 03:32:09 - Zon_Onder_Event updated to 2015-08-24T06:43:00
2015-08-24 03:33:09 - Zon_Op_Tijd updated to 2015-08-24T06:43:00
2015-08-24 03:33:09 - Zon_Op_Event updated to 2015-08-24T06:43:00
2015-08-24 03:33:09 - Zon_Onder_Tijd updated to 2015-08-24T20:45:00
2015-08-24 03:33:09 - Zon_Onder_Event updated to 2015-08-24T20:45:00

What am I doing wrong?


I’m still not a pro but try something like

Switch item=“at sunrise” { astro=“planet=sun, type=rise, property=start” }
Switch item=“at sunset” { astro=“planet=sun, type=rise, property=end” }



mhofer your suggestions are samples for OpenHAB 1.x binding. Klex is using Astro 2.x binding for OpenHAB 2.x and this is actually something which I wanted also to ask. I have lights at front of my house which are turned on and off with sunset and sunrise events and from time when I moved to Astro 2.x and OpenHAB 2.x this has stopped working.


Hi Grzegorz,

you are correct. I have the same experience as you. Hopefully there is a solution for it.
Would the 1.x binding work in the 2.0 environment?



The Astro binding for OH2 currently does NOT support events! It’s only for calculating the values.

We talked some months ago, that the framework itself should support events for every DateTime channel. Is there any progress or should i implement the events in the binding?


The new rule engine is heavily worked on at the moment and I expect to see a working version within a few weeks from now. With this, it should be possible to have new rule trigger types, which react on DateTime items, so that there would be no need for dedicated Switch items anymore (if I remember the context correctly, this is what the question is about, right?).
So if this isn’t too pressing, I would suggest to wait a little bit longer to come to a nice solution with the new rule mechanism.

1 Like

Has anything happened with the rule engine to support this?

I have the same question as above, I cannot get the calculated times displayed in my site maps with an item such as this:

DateTime Sunrise_Time  "Sunrise [%1$tH:%1$tM]"  (Astronomy)	{ channel="astro:sun:home:rise#start" }

I’m also trying to get around the missing switch issue by setting up a rule such as this:

rule calculate_sunrise
	Time cron "0 0 03 * * ?"
	if(sunriseTimer!=null) {
		logInfo("houseControl", " We already have a sunrise timer ")
	logInfo("houseControl", "Calculating sunrise time ")
	sunriseTimer = createTimer(Sunrise_Time.minusMinutes(15))[|
	logInfo("houseControl", "Executing sunrise time event")

But as far as I can see it does not seem to work. I think the values are in the items as specified, I see this in the log:

2015-11-09 11:59:23 [DEBUG] [a.internal.job.AbstractBaseJob:32   ] - Starting astro PositionalJob for thing astro:sun:home
2015-11-09 11:59:23 [DEBUG] [.b.a.handler.AstroThingHandler:134  ] - Publishing planet Sun for thing astro:sun:home
2015-11-09 11:59:23 [INFO ] [smarthome.event.ItemStateEvent:43   ] - Sunrise_Time updated to 2015-11-09T08:00:00
2015-11-09 11:59:23 [INFO ] [smarthome.event.ItemStateEvent:43   ] - Sunset_Time updated to 2015-11-09T15:55:00
2015-11-09 11:59:23 [INFO ] [smarthome.event.ItemStateEvent:43   ] - Sun_Elevation updated to 12.90

So there are two issues, has the rule engine been updated with additional triggers, and why can we not see the updated date and time values in the items?

If anyone is interested I created a simple rule to approximate sunrise sunset:

rule elevation
when Item Sun_Elevation changed
	if(Sun_Elevation.state >  0){
			logInfo("houseControl", "Sun is crossing the horizon, switching to daylight mode")
	} else {
		if(Daylight.state!=OFF) {
			logInfo("houseControl", "Sun is crossing the horizon, switching to night mode")

Hi, I’m just looking to understand the above. Is it an accurate summary that astro cannot be used in rules? (and if so, doesn’t that make it of little use at present?)

I’ve got motion sensors to trigger lights between Sunset and Sunrise (working in OH1), but I can’t seem to get an actual time from the astro items.

I have the addon jar installed and I’ve defined a Sun and Moon ‘thing’ in paperUI. On startup they’re assigned times (dozens of permutations - interested to know how to access these). Anyhow, I can’t see that my own items are ever properly initialised. Items are:

DateTime    Sunrise "Sunrise [%1$tH:%1$tM]"  { channel="astro:sun:home:rise#start" }
DateTime    Sunset   "Sunset [%1$tH:%1$tM]"  { channel="astro:sun:home:set#start" }`

However, when I try to access them in my (severly dumbed down for troubleshooting) rule:

rule "Landing Motion Detected"
        Item Landing_Ceiling_Motion changed
        logInfo("astro", "sunrise = " + Sunrise.toString)
        val boolean isdark = (now < Sunrise) || (now > Sunset)
            if (isDark) {

The output is:

2015-11-10 21:49:43 [INFO ] [e.smarthome.model.script.astro:48   ] - sunrise = Sunrise (Type=DateTimeItem,State=NULL, Label=Sunrise, Category=null)

If I uncomment the test I get:

2015-11-10 21:28:46 [ERROR] [.s.m.s.e.ScriptExecutionThread:48   ] - Error during the execution of rule 'Landing Motion Detected': org.eclipse.smarthome.core.library.items.DateTimeItem cannot be cast to org.joda.time.ReadableInstant

So how do I access the ‘Sunset’ properties? Or am I coming at this from an OH1 perspective? I don’t have the designer for OH2 (meaning no autocompletion) as the link that Kai gives in this thread (!topic/openhab2/pW2i3Y64PEs) gets a 404, and I can’t find the designer on the ESH site - only the full-on IDE.

Someone tell me if I’m just doing this wrong, or if the astro binding is yet to allow what I’m trying, in which case I’d (respectfully) ask what the binding is currently useful for.

I’ve had a flick through the source code for the binding but can’t see an obvious ‘getTime’ method - and I don’t even know if that would work in the rule editor.


Okay I noticed my first error; my item definition:

DateTime    Sunrise "Sunrise [%1$tH:%1$tM]"  { channel="astro:sun:home:rise#start" }

should have been:

DateTime    Sunrise "Sunrise [%1$tH:%1$tM]"  { channel="astro:sun:1c76b180:rise#start" }

as my ‘sun’ has a unique hash, rather than the name (that I blindly copied from the net).

So my rule is now closer to the OH1 version:

var DateTime daystart = new DateTime((Sunrise.state as DateTimeType).calendar.timeInMillis)
var DateTime dayend = new DateTime((Sunset.state as DateTimeType).calendar.timeInMillis)
val boolean isdark = now.isBefore(daystart) || now.isAfter(dayend)
if (isdark) {

But this is landing me a null pointer:

2015-11-10 22:16:22 [ERROR] [.s.m.s.e.ScriptExecutionThread:46   ] - Error during the execution of rule 'Landing Motion Detected'java.lang.NullPointerException: null
    at org.eclipse.xtext.common.types.util.JavaReflectAccess.getRawType(

I’m obviously accessing the property wrongly, but I’m not sure why. Any help would be appreciated.

I initially thought that the variables were not updated correctly, even though the log said they were. However, after checking paperUI (putting the datatime variables in a group that has [“home-group”] tag), it is apparent that the variables actually have the values since the values appear in the correct group here (although without the fancy formatting defined in the string for the datetime item).

I guess the lack of formatting is a symptom of something, but I have no idea of what.

ping Just wondering if there was any direction decided on the forward progress of the Astro binding and events?


It seems around this binding there is still a lot missing.
I am unable to make the 1.8 (Astro1) version running under openHAB2 (Beta 1) and the new version does not support events and also seems not to have offsets.

Is there any news?

I can confirm that displaying astro dates in a sitemap is apparently not working with the astro 2.0 binding. Checking the logs, I see that my date items are apparently correctly set but I have no display in the UI.

Here is how are defined my items (they are respectively linked to rise#start and set#end):
DateTime Debut_Jour “Lever de soleil [%1$tH:%1$tM]” (GMeteo)
DateTime Fin_Jour “Coucher de soleil [%1$tH:%1$tM]” (GMeteo)

The same items defined like that are correctly displayed in the astro binding 1.x in OH1.x:
DateTime Debut_Jour “Lever de soleil [%1$tH:%1$tM]” (GMeteo) {astro=“planet=sun, type=rise, property=start”}
DateTime Fin_Jour “Coucher de soleil [%1$tH:%1$tM]” (GMeteo) {astro=“planet=sun, type=set, property=end”}

Are issues déclared in Gît ?
If not, I can declare the one relative to display of date times.

Are there any updates on this yet (being as OH2 is already at beta2)?

Hi Trevor!
Maybe @Kai can shed some light on this?

Note that the openHAB distro comes with both, the astro1 and the astro2 binding, so you can pick the one you prefer.
Regarding missing features in astro2, this is tracked here:
If you think there are any bugs int he current astro2 binding, simply report them here as well.

I cant decide from reading this if there Astro2 binding is missing stuff e.g. events, or if we are still waiting on the new rule trigger types to be implemented.

From my use thus far, it appears that events aren’t implemented. That said there are ways to work around that.