Timer within a rule

Hi Guys, I have been a member for a little while but haven’t posted for a bit. I have been busy working out the physical attributes of my next automation phase. Now that the weather has turned cold, I’m back trying to write some code.
My system is :
OH 2.5 running on a Razzberry Pi4B
Two slave Pi’s that are 3B that communicate over MQTT
rules are written with Jython/Python code, but I’m still a newbie at it.

Communication works fine and i can get the inputs and outputs to work, but I’m having difficulty getting a timer to run.
This is my rule.

def timer_light__on(log):

    log.info("The light timer is now running")

    sendCommand("house_garage_light_2", ON)

    log.info("Running the light timer")

    global timer_lights_on

    timer_lights_on = createTimer(DateTime.now().plusSeconds(45), lambda: timer_light_on(log))

        

@rule("Rule Garage Lights on 1", description="Turns the garage lights on wgen the roller RH door opens")

@when("Item house_rollerdoor_door1_up changed")

def Garage_lights_on(event):

    global timer_lights_on

    if items["house_rollerdoor_door1_up"] == ON:

        sendCommand("house_garage_light_2", ON)

        timer_light_on =  createTimer(DateTime.now().plusSeconds(45), lambda: timer_lights_on(rule_Garage_lights_on.log))

        log.warn("Garage roof lights on, running timer")

    else:

        sendCommand("house_garage_light_2", OFF)

@rule("Rule Garage Lights on 2", description="Turns the garage lights on wgen the roller LH door opens")

@when("Item house_rollerdoor_door2_up changed")

def Garage_lights_on2(event):

    global timer_lights_on

    if items["house_rollerdoor_door2_up"] == ON:

        sendCommand("house_garage_light_2", ON)

        timer_light_on =  createTimer(DateTime.now().plusSeconds(45), lambda: timer_lights_on(rule_Garage_lights_on.log))

        log.warn("Garage roof lights on, running timer")

    else:

        sendCommand("house_garage_light_2", OFF)

When the upper read switch turns on, the garage lights turn on but then turn off again once the door starts coming down and the switch turns off. I think I’ve missed something, but om not sure what it is.
Any help would be most appreciated.

your code goes here

If you are using the Helper Libraries, But How Do I…? — openHAB Helper Libraries documentation should always be the first place to look. There is a link to an Timer example there.

This link doesn’t work - Error 404.

It looks like bit rot is already setting in on the abandonded Helper Libraries repo. Use CrazyIvan359’s repo instead. Helper Libraries for openHAB Scripted Automation — openHAB Helper Libraries documentation

I ended up with a rule that looks like this

       
@rule("Rule Porch Lights on 1", description="Turns the front porch lights on when the roller RH door opens")
@when("Item house_rollerdoor_door1_up changed")
def rule_Porch_lights_on1(event):
    global timer_lights_on1
    if items["house_rollerdoor_door1_up"] == ON:
        rule_Porch_lights_on1.log.info("Turning on the porch lights on from RH door")
        sendCommand("house_light24", ON)
        sendCommand("house_garage_light_1", ON)
        timer_lights_on1 = createTimer(DateTime.now().plusSeconds(240), lambda: timer_porch_lights_are_off(rule_Porch_lights_on1.log))

    else:
        rule_Porch_lights_on1.log.info("Porch lights are now on and running timer for RH door")