[SHARE] MY RULE : The Goal is turn on my garage Lights ON when the garage door is open and it nite time for 10MIN

Only a week into this but have something working

The Goal is turn on my garage Lights ON when the garage door is open and it nite time for 10MIN

This is MARK 1

First i had to work out nite So i used the astro plug

// put this at top of page
var  Timer Timer_Bla=null   
rule "OpenHAB system started - astro"
    System started
    createTimer(now.plusSeconds(180)) [ |
        if (now.isAfter((Sunset_Time.state as DateTimeType).calendar.timeInMillis) ||
            now.isBefore((Sunrise_Time.state as DateTimeType).calendar.timeInMillis)
        ) {
            postUpdate(NightState, ON)
        } else {
            postUpdate(NightState, OFF)
rule "Update NightState"
    Item SunElevation changed
    if(SunElevation.state >  0){
        if(NightState.state != OFF) postUpdate(NightState, OFF)
    } else {
        if(NightState.state != ON) postUpdate(NightState, ON)

dont under stand it yet but getting there it WORKS :slight_smile:

next the rule for the Sensor_Garage

rule "Turn on garage Light when Night time"

when Item Sensor_Garage changed from CLOSED to OPEN 
	if (NightState.state == ON) {
		Timer_Bla = createTimer(now.plusMinutes(10), [|


i come from windows using VBscript for everything

the hard bit been dealing with the {} [] () and the case naming
me HAPPY CAMPER :blush:

1 Like

Your code will be easier to read if you use code fences. The five buttons to the right of the smilie face will insert code fences. Put your code in between and spacing and formatting and even some syntax highlighting will be applied.

If you have additional times of day you are interested in tracking you might be interested in the Time of Day Design Pattern.

Also, if your Garage_light only ever comes on for these ten minutes (which is probably not the case) you can eliminate the timer by using the Expire binding:

Garage_light ... {expire="10m,command=OFF", ...}

OK thanks Rich

Yeap that the Plan So far my think is I drive in the garage and it dark its turn it on
im looking into PIR next so if I stay long that will see me and do some thing

HMMM do like that New Command

Thanks again
look like more reading :frowning:

I’ve been down this rabbit hole coincidentally with my garage lights too. Next you’ll say “but if the garage lights are already on then I shouldn’t set an off timer (unless they are already on an off timer and my potential timer would turn them off at a later time)” and then “if someone turns off the garage lights before the timer has expired then you need to clear the timer because someone could come in and turn them on again manually and the timer would turn them off”. Then I threw in a motion detector to turn on the lights too because I’m a glutton for punishment.

Good luck.

Heap I’m working on that hole I’m taking little steps
Thanks for the comment