RF Relay rule OH2

Hi everyone.
I finally started build my own home automation system with what i 've got and as cheap as possible as i can. I know that for this i will need much more time but that 's the path i chose!!!
So i have installed on my shutters a 2ch rf relay which works as toggle switch. One relay for up, one for down. So i push button the relay locks , i push button the relay unlocks.
I am at the stage that i can control my relays from OH, but i don’t know how to send the second command so my relay unlocks ( yes ok if i push the down button on OH once more it will unlock, but i want somehow to automate this think…)
Is there a way to do it as a rule? My shutter to close fully needs 24 seconds, so i was thinking of a rule when my item receives close command, wait for 24 seconds and send close command again.
But it is my first time for rules and i don’t know how they have to be written.
My items

 Rollershutter	Shutter_GF_Living_Left	"Ρολλό Αριστερά"	(GF_Living,GF_Shutters,Shutters) {mqtt=">[localbroker:livingroom/shutters/left:command:DOWN:down],>[localbroker:livingroom/shutters/left:command:STOP:default],>[localbroker:livingroom/shutters/left:command:UP:up],<[localbroker:livingroom/shutters/left:state:default]"}
    Rollershutter	Shutter_GF_Living_Right	"Ρολλό Δεξιά"	(GF_Living,GF_Shutters,Shutters)		{mqtt=">[localbroker:livingroom/shutters/right:command:DOWN:down],>[localbroker:livingroom/shutters/right:command:STOP:default],>[localbroker:livingroom/shutters/right:command:UP:up],<[localbroker:livingroom/shutters/right:state:default]"}

Any help appreciated.

Option 1: Sleep in a rule

Shutter_GF_Living_Left.sendCommand(DOWN)
Thread::sleep(24000)
Shutter_GF_Living_Left.sendCommand(STOP)

Option 2: Use the Expire binding

Rollershutter	Shutter_GF_Living_Left	"Ρολλό Αριστερά"	(GF_Living,GF_Shutters,Shutters) {expire="24s,command=STOP", mqtt=">[localbroker:livingroom/shutters/left:command:DOWN:down],>[localbroker:livingroom/shutters/left:command:STOP:default],>[localbroker:livingroom/shutters/left:command:UP:up],<[localbroker:livingroom/shutters/left:state:default]"}

Option 3: Use a Timer

var Timer timer = null

rule "Left rollershutter"
when
    Item Shutter_GF_Living_Left received command
then
    if(receivedCommand != STOP){
        timer?.cancel // cancel the existing timer
        timer = createTimer(now.plusSeconds(24), [| Shutter_GF_Living_Left.sendCommand(STOP) ]
    }
end

Thanks for the reply. I will try them and come back for the results!!!

Would this one work?

var Timer timer = null

rule "Right Rollershutter"
when
    Item Shutter_GF_Living_Left received command
then
    if(receivedCommand != DOWN){
        timer?.cancel // cancel the existing timer
        timer = createTimer(now.plusSeconds(24), publish("localbroker","livingroom/shutters/right","4567832")
        	)}
        	
    else if(receivedCommand != UP){
        timer?.cancel // cancel the existing timer
        timer = createTimer(now.plusSeconds(24), publish("localbroker","livingroom/shutters/right","4567833")
    )}
end

And i thought about it this way, because i don’t actually have a stop function in my control.
I only use 2 buttons, UP-Down. When i press the button for the relay i have assigned as down i have to press it once to lock the relay, the shutters going down and once more to unlock it so the shutters stop.
Does this rule seem correct, as the one you gave me it works but because it sees the down command continuously it goes to an infinite loop.
The way i composed the rule, if i understand correctly, when i press down on the openhab interface, it locks my relay and after 24 seconds it will publish the rf command to unlock it so it will stop. The numbers in the publish command are the rf codes i use for up and down.

That is why there is a STOP command in the first place. To avoid this sorry if loop. It will be very challenging to avoid such a loop with only two commands.

The coffee you have posted looks syntactically correct but the infinite loop will remain. I’m not sure how to avoid it off the top of my head.

Maybe if you implement a STOP to send the same MQTT message as what you send to send with the second button press to lock it.

That’s why i thought of publish and not of sendcommand you suggested.
Sendcommand i suppose goes to openhab interface but
publishing goes straight to the mqtt i think i will overcome the problem.

Can someone help with this error

03:33.672 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Left rollershutter': An error occured during the script execution: The name 'publish(<XStringLiteralImpl>,<XStringLiteralImpl>,<XStringLiteralImpl>)' cannot be resolved to an item or type.

My rule is

var Timer timer = null

    rule "Left rollershutter"
    when
        Item Shutter_GF_Living_Left received command
    then
        if(receivedCommand !== DOWN){
            timer?.cancel // cancel the existing timer
            timer = createTimer(now.plusSeconds(24), publish("localbroker", "livingroom/shutters/test1", "DOWN")
        )}
    end

Any help appreciated

I install mqtt action and i override the above problem but now i get

15:31:05.831 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Left rollershutter': An error occured during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.ScriptExecution.createTimer(org.joda.time.base.AbstractInstant,org.eclipse.xtext.xbase.lib.Procedures$Procedure0) on instance: null

At last!!! Finally i got it working for anyone interested for a cheap solution for their rollershutters.

The rule tha work and is based on timing is below.

var Timer timer = null

rule "Right rollershutter"
 when
    Item Shutter_GF_Living_Right received command DOWN
then
   timer = createTimer(now.plusSeconds(24),
  [| timer = null publish("localbroker", "livingroom/shutters/right", "DOWN")
  ])
end

For anyone that wants more info how to do the connection with a simple double rf relay which only costs 6euros!!! just pm me :slight_smile:

The same goes for the up command and i am working on a rule for stop command.

I know it is a bit old, but i finally have my shutters working with up/down/stop commands as expected with only an rf relay which actually costs 6euros.
What i did was to create a dummy item and used the rules below for both up an down.
If anyone wants any clarifications just let me know.

var Timer timerLeftUp = null
var Timer timerLeftDown = null
var Timer timeRightUp = null
var Timer timeRightDown = null

rule "Right rollershutter DOWN"
 when
    Item Shutter_GF_Living_Right received command DOWN
then
   timeRightDown = createTimer(now.plusSeconds(24),
  [| timeRightDown = null STOPDOWN_Shutter_GF_Living_Right.sendCommand(STOP)
  ])
end
rule "Cancel Timer Right Down"
when
    Item Shutter_GF_Living_Right received command STOP
then
    if (timeRightDown !== null) {
        timeRightDown.cancel
        timeRightDown = null STOPDOWN_Shutter_GF_Living_Right.sendCommand(STOP)
    } else 
    	{
    }
end

rule "Right rollershutter UP"
 when
    Item Shutter_GF_Living_Right received command UP
then
   timeRightUp = createTimer(now.plusSeconds(24),
  [| timeRightUp = null STOPUP_Shutter_GF_Living_Right.sendCommand(STOP)
  ])
end
 rule "Cancel Timer Right UP"
when
    Item Shutter_GF_Living_Right received command STOP
then
    if (timeRightUp !== null) {
        timeRightUp.cancel
        timeRightUp = null STOPUP_Shutter_GF_Living_Right.sendCommand(STOP)
    } else 
    	{
    }
end


rule "Left rollershutter DOWN"
 when
    Item Shutter_GF_Living_Left received command DOWN
then
   timerLeftDown = createTimer(now.plusSeconds(24),
  [| timerLeftDown = null STOPDOWN_Shutter_GF_Living_Left.sendCommand(STOP)
  ])
end
rule "Cancel Timer Left Down"
when
    Item Shutter_GF_Living_Left received command STOP
then
    if (timerLeftDown !== null) {
        timerLeftDown.cancel
        timerLeftDown = null STOPDOWN_Shutter_GF_Living_Left.sendCommand(STOP)
    } else 
    	{
    }
end

rule "Left rollershutter UP"
 when
    Item Shutter_GF_Living_Left received command UP
then
   timerLeftUp = createTimer(now.plusSeconds(24),
  [| timerLeftUp = null STOPUP_Shutter_GF_Living_Left.sendCommand(STOP)
  ])
end
 rule "Cancel Timer Left UP"
when
    Item Shutter_GF_Living_Left received command STOP
then
    if (timerLeftUp !== null) {
        timerLeftUp.cancel
        timerLeftUp = null STOPUP_Shutter_GF_Living_Left.sendCommand(STOP)
    }else 
    	{
    }
end