Expire tags for Switch in sitemap

  • Platform information:
    • rPi3
    • OS:openhabian-pi-raspbian-201908050414
    • Java Runtime Environment: not sure which ever came with the above
    • openHAB version: openHAB 2.5.4-1 (Release Build)
  • Issue of the topic: cant get expire to work on switches.
  • Please post configurations (if applicable):
    • Items: I setup items in paperui and got them working
    • Sitemap: I put these lines in home.sitemap so i could use them on an iPhone
      Switch item=NodeMCU5_OpenGateRelay label=“GateOpen2”
      Switch item=NodeMCU5_CloseGateRelay label=“GateClose2”
      And they do work but I cant work out how to add the expire tag so it turns off after 30s
      I did try Switch item=NodeMCU5_CloseGateRelay label=“GateClose2” { expire=“30s,command=OFF” }
      but that was no good.
    • Rules: I havnt made any
    • Services: I did install the expire binding in paper ui
  • Logs: only that my expire syntax was incorrect.

Make yourself a test Item, in an Items file, not linked to any real device, to experiment with expire.

If your real Item is getting frequent updates from a device, it will reset the expire timer each time.

But …

Then you cannot use expire with those Items.
It’s an old version 1.x binding, it only works with 1.x .Items files.

What you cannot do is use the same Item name in a file and a PaperUI definition and expect parts of both to work. One will replace the other.

You can auto-timeout PaperUI based Items using rules and timers, it’s not too difficult.

Thank you Rossko

I made a rules file
import org.openhab.model.script.actions.*

import org.openhab.model.script.actions.*

var Timer timer = null

rule "Gate Timer"
when
	Item NodeMCU5_OpenGateRelay received command
then
	if(receivedCommand==ON) {
		if(timer===null) {
			sendCommand(NodeMCU5_OpenGateRelay, ON)
			
			timer = createTimer(now.plusSeconds(3)) [|
				sendCommand(NodeMCU5_OpenGateRelay, OFF)
			                         timer = null
			]
		} 
	}
end



rule "Gate Timer"
when
	Item NodeMCU5_CloseGateRelay received command
then
	if(receivedCommand==ON) {
		if(timer===null) {
			sendCommand(NodeMCU5_CloseGateRelay, ON)
			
			timer = createTimer(now.plusSeconds(3)) [|
				sendCommand(NodeMCU5_CloseGateRelay, OFF)
			                         timer = null
			]
		} 
	}
end

You don’t need this import in OH2. It can mess things up. Beware looking at old posts.

Why are you using the rule to send a command identical to the one that triggered the rule (and will make the rule trigger again)?

You seem to have copied your rule twice; if they are meant to be different, you must give them different names.

Apart from these issues, the idea looks fine :smiley: