Help with turning lights on when garage door opens

I have a rule to turn my garage lights on when the garage door opens, and is working good, but the light come on every time the door opens, i would like to have is so the lights will only come on when it is dusk.

I tried a bunch of different rules but could not get it to work, the first rule is the one that i have been using, the second one is the one that is not working.

Anyone have input how to set the rule?

Thanks

rule “Shop Light On”
when
Item contact_GarageDoor1 changed from 0 to 1
then
sendCommand(“ShopLight_Switch” , “ON”)
end

rule “Shop Light On”
when
Item contact_GarageDoor1 changed from 0 to 1
then
if(civilDusk#event.state == START) {
sendCommand(“ShopLight_Switch” , “ON”)
}
end

Create an Item and link it to the civilDusk Channel. Then you can do something like…

rule “Shop Light On”
when
    Item contact_GarageDoor1 changed from 0 to 1
then
    if (now > new DateTime(civilDuskStart.state.toString) or now < new DateTime(civilDawnStart.state.toString)) {
        sendCommand(“ShopLight_Switch” , “ON”)
    }
end

You may also want to look into using something like the TimeOfDay DP, so you could just be comparing to the TimeOfDay Item.

And please use code fences.

Edit: I should have mentioned that this will not work if the garage door is opened after midnight, when the Astro binding will update the time of civil dusk. I’ve update the rule example I gave to tak ethis into consideration, but you’d need to also add an Item for civil dawn.

1 Like

I use this rule…


rule "Turn on Carport Lights when the Rear Gate opens and we arent home"
when
        Item Gate_status changed
then
        if (Gate_status.state == OPEN && Kris_Mobile.state == OFF && CarportLux.state < 50 ) {
         logInfo ("Rear Gate", "Rear Gate is Open and Kris isnt home so turning on the Light")
          CarportDim1.sendCommand("100")
        } else {
          CarportSw1.sendCommand("OFF")
}
end

In my case, I’m doing following:

  • using status ‘Daylight’, based on astro things to define day or night.
    I use this for a lot of other things as well. Fe lights outside on/off, counter for PV profit…
  • I also have a kind of parking time (ParkingMode). This way, the lights will go out automaticly if you leave (=close port) in 10 minutes. Else (if you don’t close the port in 10 minutes), the lights stay on…

Used items

Number  Elevation                "Elevation [%.2f]" { channel="astro:sun:home:position#elevation" }
Switch  Daylight                 "Daglicht"     
Contact Poort_Atelier            "Poort [%s]"       { channel="zwave:device:2f4ef5d0:node32:sensor_door" }
Switch  Light_AT_PolyvalentSfeer "Atelier"          { channel="knx:device:c9a47269:Light_AT_PolyvalentSfeer" }
String  ParkeerMode              "Parkeren [%s]"

Daylight

rule "Daglicht bepalen"
when
        Item Elevation received update
then
        if(Elevation.state > 0) {
                if(Daylight.state != ON) postUpdate(Daylight, ON)
        } else {
                if(Daylight.state != OFF) postUpdate(Daylight, OFF)
        }
end

Port open or close

rule "Lichten Polyvalent aan bij parkeren"
when
        Item Poort_Atelier changed from CLOSED to OPEN
then
        if (Daylight.state == OFF) {   //Het is donker
                if ( Light_AT_PolyvalentSfeer.state == OFF ) {
                        logInfo("Parkeren", "Lichten aan in atelier na openen poort")
                        sendCommand( Light_AT_Polyvalent, ON )
                        ParkeerMode.sendCommand("ON")
                        createTimer(now.plusSeconds(600),  [ |
                                ParkeerMode.sendCommand("OFF")
                                ])
                        }
                }
end

rule "Lichten Polyvalent uit na parkeren"
when
        Item Poort_Atelier changed from OPEN to CLOSED
then
        if (ParkeerMode.state == "ON") {
                logInfo("Parkeren", "Lichten uit in atelier na sluiten poort")
                sendCommand( Light_AT_Polyvalent, OFF )
                ParkeerMode.sendCommand("OFF")
                }
end