Astro binding not working


I’m running openhab 1.7.1 on a raspberry 2 installed from packages. I have added astro binding, but it seems that is not run.

My config is:

    # items/casa.items
    DateTime Sunrise_Time  "Sunrise [%1$tH:%1$tM]"  <sun> {astro="planet=sun, type=rise, property=start"}
    // shows the sunset
    DateTime Sunset_Time   "Sunset [%1$tH:%1$tM]"   <moon> {astro="planet=sun, type=set, property=end"}
    // schedules a event which starts 30 minutes BEFORE sunset:
    Switch Sunset_Event   <moon> {astro="planet=sun, type=set, property=end, offset=-720"}

    # sitemaps/casa.sitemap
    Frame label="Fecha y Hora" {
            Text item=Sunrise_Time label="Amanecer"
            Text item=Sunset_Time label="Anochecer"
            Switch  item=Sunset_Event

but text items are shown as empty and the switch one off (always off).

In the log file, the only message is:

2015-10-05 19:45:15.707 [INFO ] [.b.a.internal.bus.AstroBinding] - AstroConfig[latitude=XXX,longitude=-YYY,interval=3600,systemTimezone=Europe/Madrid (CET +0200),daylightSavings=true]
2015-10-05 19:45:18.734 [INFO ] [.b.a.internal.job.JobScheduler] - Scheduled a daily job at midnight for astro calculation

The Astro binding documentation suggests to put the binding in debug mode, but, how do I do it?

Any help?

[quote=“angelluis_mateo, post:1, topic:3105, full:true”]
The Astro binding documentation suggests to put the binding in debug mode, but, how do I do it?[/quote]


<logger name="org.openhab.binding.astro" level="DEBUG" />

to your logback.xml.

I’m assuming that in the log file you replaced your actual latitude with “XXX” and longitude with “YYY” to avoid revealing too much personal info online. However, if you didn’t do that and just pasted the logs as they appear, the first thing you need to do is add your actual latitude and longitude to openhab.cfg in the Astro Binding section.

Secondly there is an error on your sitemap. When you define the label for an item the label is made up of two parts: left part and right part. The left part is everything in the quotes except for the stuff in “[ ]” and will appear on the left hand side on the sitemap. The part in “[ ]” ends up on the right hand side and it usually contains some formatted version of the state of the Item.

In the definition for Sunset_Time you will notice the label is "Sunset [%1tH:%1$tM]". So the left part of the label as it appears on your sitemap will be “Sunset” and the right hand side will be the time in the format “HH:MM” (e.g. 18:22) making the entire line read "Sunset 18:22". The %1$tH:%1$tM is a way to tell the sitemap how to format the datetime. Often you will just see" [%s]" which just prints the state without extra formatting. The full documentation for how to format things like dates and times is here.

It is possible to define a label in two places, when you define an Item or on the sitemap. When it is defined in both places the sitemap label takes precedence.

Given this, when you assign the label “Amanecer” without brackets on the sitemap you are overriding the label on the Item and because you don’t have any square brackets the state of the Item doesn’t get printed in the sitemap. So to fix the Text items you need to add “[%1$tH:%1$tM]” to the labels (e.g. label=“Amanecer [%1$tH:%1$tM]”).

Thirdly, in regards to the switch, an Astro switch only stays on for an instant. It quickly cycles from OFF to ON at the given time then OFF again within milliseconds. I think it does so even faster than the sitemap refreshes so it is unlikely you would ever see it change on your sitemap. So, while the switch is great for triggering rules it isn’t useful to put on your sitemap, unless you want to test those rules by manually triggering it.

Finally, why do you have a -12 hour (-720 minutes) offset for the sunset event? This will cause the Sunset event to occur in the morning. Based on your comment the offset should be -30.

I hope this helps.


I replaced latitude and longitude to not show everybody where is my house :relaxed:, but in the config there are the actual values.

This was the problem. I was overriding the value. I just put the item in the sitemap without any label and now is shown correctly.

Ah… I thought that the swith would be on all night. I’m going to try it associated with a rule.

And the -12hour offset was for tests I made, so I didn’t have to wait until actual night.

It was really helpfull. Thank you very much