Lights ON at sunset / Arriving home @ Night lights on

I am a new Openhab user. Sorry for this question.

I checked the forum all over. i found quite a lot of topics regarding the issue I am experiencing but no topic has the exact same question. I fiddled around but the rule keeps comming back with errors. I am no programmer, that is for sure.

I have a group call G_Presence, it functions as a ON / OFF switch, Multiple phones in the group and 1 phone at home triggers it in a ON state.

I use the astro binding.

What I want is that when astro:sun:local:civilDawn start, and G_presence has a status of ON it will turn on my livingroom lights.

The second thing I want is the other way around, when G_Presence changes to ON AND it is night, then switch on my lights.

Now reading the different topics this should’t be that hard to do. And I just cannot get it to work.

For my first question I created this rule:

rule “WK_LightsOnAfterDark”

when
if(Channel “astro:sun:local:civilDusk#event” triggered START && G_Presence = ON) {
then sendCommand(WK_Plafondlamp1, ON),sendCommand(WK_Plafondlamp2, ON)

}
end

That does not work. The second question I did not even start on since I could not get this really simple thing to work. Any help is really appreciated.

Hi

I think your rule should look like this:

rule “WK_LightsOnAfterDark”
when
    Channel “astro:sun:local:civilDusk#event” triggered START
then 
    if (G_Presence.state == ON) {
        WK_Plafondlamp1.sendCommand(ON)
        WK_Plafondlamp2.sendCommand(ON)
    }
end
1 Like

That solves the first case
For the second case, you should set a proxy String item to “DARK” at dusk and create a new rule with the trigger presence changed to ON and check for DARK

And for this you could make a rule like:

rule "WK_LightsOnWhenHome"
when
    Item G_Presence changed from OFF to ON
then
    if(now.isAfter((astro_sun_local_civilDusk_start.state as DateTimeType).getZonedDateTime.toInstant.toEpochMilli)){
        WK_Plafondlamp1.sendCommand(ON)
        WK_Plafondlamp2.sendCommand(ON)
    }
end
2 Likes

ah ok, so now.isafter that makes sense since it is s date and time value. I used homeseer and made a virtual device there that switched on at sunset and used that as a trigger. So i was thinking about the openhab solution the same way. This is way better.

Thanks for this, it helps me enough to get me in the right direction. I will have to start reading, at least my lights are on now :wink:

I recommend that you have a look at: