[SOLVED] AstroBinding - If night then do stuff

Hey there,

i have some problems configuring a rule.

this is my rule:

my Problem is the , see below.

what i want to achieve:
when phone2 is not at home, but phone1 arrives home (works already) then should group Lights turned on.

so far so good.

//rules file
rule "Comming Home"
when 
    Item Phone1 changed from "OFF" to "ON"
then 
    if( Phone2 == "OFF" ) AND ( Phone1 == "ON" ) AND (<missingCondition>)){
        Lights.sendCommand(ON)
    }
end

But this should only happen if it is dark outside.

DateTime Sunset_Time “Sonnenuntergang [%1$tH:%1$tM]” { channel=“astro:sun:home:set#start” }

Maybe it works when something like Now is after Sunset_Time, but could not find useful information for datetime conversion.

Maybe there are more Openhab2 Ways to achieve my goal.

Another question:
are AstroBindings values triggered for refresh automatically?

thanks for any hints

Your missingCondition could be solved by implementing the Time of Day design pattern.

I’m not sure what you mean with your second question:

If you’re wondering if the astro:sun:home:set#start event is triggered each day (without needing to reset something) then yes this is the case.

If you just want day and night, use:

rule elevation
when Item Sun_Elevation changed
then
if(Sun_Elevation.state > 0){
if(Daylight.state!=ON){
//logInfo(“houseControl”, “Sun is crossing the horizon, switching to daylight mode”)
Daylight.sendCommand(ON)
//turn off lights if on
sendCommand(porchLight, OFF)
sendCommand(Sw1, OFF)
}
} else {
if(Daylight.state!=OFF) {
//logInfo(“houseControl”, “Sun is crossing the horizon, switching to night mode”)
Daylight.sendCommand(OFF)
}
}
end

You will also need this to initialize it on startup:

rule “Initialize on startup”
when
System started
then
if(Sun_Elevation.state > 0)
Daylight.sendCommand(ON)
else
Daylight.sendCommand(OFF)
end

You will need this item from the astro binding:

Number Sun_Elevation “Sun Elevation” (Weather) { channel=“astro:sun:home:position#elevation” }

thank you both, all my questions are answered. This was the missing hint for me.

1 Like