I need help with making a rule using astro

i have outdoor lamp that i need to switch on all night using astro
from lets say "astro:sun:34b0b0b2:set#end"
unitl "astro:sun:34b0b0b2:nauticDawn#start"
how do i create it?

i have already did this :
items :

Switch Night_Start_Event {astro=“planet=sun, type=rise, property=end”}

Switch Night_End_Event {astro=“planet=sun, type=nauticDawn, property=start”}

rules:

rule "Night Started"
when
Item Night_Start_Event received update ON
then
home_garden_light.postUpdate(ON)
end

rule "Night Ended"
when
Item Night_End_Event received update ON
then
home_garden_light.postUpdate(OFF)
end

but what whill happen if the system startup in the middle of this hours?
does its still work?

and i dont know even the rules that i showed here are working i havn’t tested them yet…

Hello Idan

At first you have to install the astrology binding. It will create the things you need.

At second you should use `item.sendCommand’ instead of ‘item.postUpdate’.

When the system starts, the it calculates the positions. Maybe it needs one cycle to work properly this can be handled by extension of your rules, but see it as the next step.

Note that your rules are for the astro1 binding. If you are on openHAB2, you should use the astro2 binding.
The trigger is completely different in astro2, please have a look at the official docs:

http://docs.openhab.org/addons/bindings/astro/readme.html

rule "example trigger rule"
when
    Channel 'astro:sun:home:rise#event' triggered START 
then
    ...
end

If you want to use offsets or earliest/latest features, you need to use a recent snapshot binding.

1 Like

thanks,
this is my entire rules file:

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.java.math.*
import org.joda.time.*

rule “Night Started”

when
Channel ‘astro:sun:local:set#event’ triggered START

then
home_garden_name.sendCommand(ON)

end

rule “Night Ended”

when

Channel ‘astro:sun:local:nauticDawn#event’ triggered START

then
home_garden_name.sendCommand(OFF)

end

i beleive that i have imported more than i need which can i delete?

If that is your complete rule you don’t need any imports.
In general: you can delete every import starting with org.openhab.*

Because the channel triggers from the astro2 events are only a short trigger (ON, then immediately OFF again) I would recommend to use the design pattern for more flexibility:

1 Like