Help me - Turn off light after 5 or 10 minutes

i am using the raspberry pi on the GPIO and i need to manged the switches from timer and i need to show timer on the sitemap
how to add rule
please help
Best Regards
Saif Ghodayyah

I can think of possibly 2 different ways to do this.

The first is using the expire binding. I haven’t used that binding much but I believe it will turn a switch off after XX minutes, etc.

The second is with a rule. I created this simple test rule you can modify. I think its kind of self explanatory, but if need further help, just ask.

Note, i’m not sure if the import of the action.Timer is still needed or not anymore, but don’t think it hurts anything.

import org.openhab.model.script.actions.Timer

rule "Testing"

when
	Item TestSwitch received command
then     
	if (TestSwitch.state==ON) {
		//Do something immediatelly
		sendMail("myemailaddress", "Garage Door Opened", "The Garage Door was \n opened at " + Date.state.format("%tr") + " on "+ Date.state.format("%tD") + ".")
		
		//Do Something in 2 minutes
		createTimer(now.plusMinutes(2)) [|
        	if (TestSwitch.state==ON) {
				sendNotification("myemailaddress", "Test Switch was turned ON \n 2 minutes ago and is still on.")
			}
		]

		//Do Something in 4 minutes
		createTimer(now.plusMinutes(4)) [|
        	if (TestSwitch.state==ON) {
				sendNotification("myemailaddress", "Test Switch was turned ON \n 4 minutes ago and was turned off automatically.")
				sendCommand(TestSwitch, OFF)
			}
    	]
	}
end
1 Like

What do you mean?

The EXPIRE binding is a straightforward way to do this.

1 Like

If you REALLY need to see a countdown in the sitemap, see here