How to directly use astro computations

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