How to directly use astro computations

I have a tilt detector on my garage door that turns on two lights inside the house for a limited amount of time.
One of the light is in a corridor without a window, so I want to keep the rule independently of time of day.
The other, however, is in a corridor with a window and I would like the rule to check if it is day time before acting.
I know it is possible to set a switch representing whether I am between sunrise and sunset, but I wondered how I can call upon the astro bindings directly.

I found this old thread that seems to indicate that it is doable, but I am afraid that I am not sure how to do it completely.!topic/openhab/ewdZbOr7dSQ
Could somebody give a full example?

I would recommend using the Switch or some other Item type to represent when you are in a given state (e.g. Daytime) and the Astro binding sunrise and sunset events to update that state Item at the appropriate times. Then in your rules you check the state Item and act accordingly. With this approach you separate how you figure out what time of day you are in from the rest of your logic so as your system grows and you have more rules that need to behave differently based on time of day you don’t end up with duplicated logic all over the place. And you can modify how you do the calculation in one place.

I outline this design pattern here.

But if you want to ignore good advice :-)… If you are using the Astro binding you can create two DateTime Items, one for sunrise and one for sunset and configure Astro to populate these Items appropriately. In your rules you can then check if now is between sunrise and sunset.

If you are using the Astro action (NOTE: you must have both the Astro Binding and the separate Astro Action jar files installed) you can get sunrise start/end and sunset start/end with direct action calls as documented here.

You cannot make calls directly into the Astro (or any other) binding directly from rules or scripts.

1 Like

Yes I know that is doable. I can do that, but yes too, I want to ignore good advise :smile:. I am interested in general in being able to call astro computations.
On the other hand, in practice, I will probably use the sunset and sunrise times, as I’ve already introduced those items in my system.

Thank you however for the link you gave. That is what I was looking for and had been unable to find on my own.