How to set up a controlled garage door?

Just to show a way of doing this

My items

Switch GarageDoorSwitch		 [ "Switchable" ] 									{ mqtt=">[broker:cmnd/GarageDoorSonoff/POWER:command:*:default]" }
Rollershutter GarageDoor		 
String GarageDoorState 			          	
Switch GarageDoorClosed															{ mqtt="<[broker:cmnd/GarageDoorSensors/POWER1:state:default]" }
Switch GarageDoorOpened															{ mqtt="<[broker:cmnd/GarageDoorSensors/POWER2:state:default]" }
Number Garage_RSSI 	"Garage: RSSI [%d %%]"  									{ mqtt="<[broker:tele/GarageDoorSonoff/STATE:state:JSONPATH($.Wifi.RSSI)]" }
String Garage_IP 	"Get Info"  												{ mqtt=">[broker:cmnd/GarageDoorSonoff/IPAddress1:command:*:*]" }
String Garage_IP_String "Info [%s]"	 											{ mqtt="<[broker:stat/GarageDoorSonoff/RESULT:state:default]" }
Switch GarageDoorAuto "Garage Door auto close 9PM-5AM" 
Switch GarageDoorStateUpdate 													{ mqtt=">[broker:cmnd/GarageDoorSonoff/STATUS:command:*:10]" } //hidden button to get update of garage door status. Runs every minute
String GarageDoorStateString													{ mqtt="<[broker:tele/GarageDoorSonoff/SENSOR:state:default]" } //hidden string to be updated depending on status 

sitemap

Text label="Garage" icon="garage"
	{
		Frame label="Control"
		{
		
		Switch item=GarageDoor label="Garage Door" icon="garagedoor"
		}
		
		Frame label="Status"
		{
		Text item=GarageDoorState label="[%s]" icon="garagedoor" valuecolor=[GarageDoorState=="Closed"="green",GarageDoorState=="Open"="red",GarageDoorState=="Ajar"="orange"] 
		}
		Text label="Settings" icon="settings"
		{
		Switch item=GarageDoorAuto icon="time"
		}
	}

rules

var Timer garageDoorTimer 
var Timer garageDoorOpenTimer

//*************************************************************************** Garage Door Rules Below********************************************************************


rule "Garage Door Open"
when
	Item GarageDoor received command UP
then

if (garageDoorTimer !== null)
	{
	garageDoorTimer.cancel
	garageDoorTimer = null
	}
	
	if (GarageDoorOpened.state != ON)
		{
		
		GarageDoorSwitch.sendCommand(ON)
			garageDoorTimer = createTimer(now.plusSeconds(25)) [|
			if (GarageDoorOpened.state != ON && GarageDoorClosed.state == ON)
				{
				GarageDoorSwitch.sendCommand(ON)
			    }
			]
		}
end
//********************************************************************



rule "Garage Door Close"
when
	Item GarageDoor received command DOWN
then

if (garageDoorOpenTimer !== null)
	{
	garageDoorOpenTimer.cancel
	garageDoorOpenTimer = null
	}
	
if (garageDoorTimer !== null)
	{
	garageDoorTimer.cancel
	garageDoorTimer = null
	}

	
	if (GarageDoorClosed.state != ON)
		{
			
			
		GarageDoorSwitch.sendCommand(ON)
			garageDoorTimer = createTimer(now.plusSeconds(25)) [|
			if (GarageDoorClosed.state != ON && GarageDoorOpened.state == ON)
				{
				GarageDoorSwitch.sendCommand(ON)
			    }
			]
		}
end
//********************************************************************




rule "Garage Door Stop"
when
	Item GarageDoor received command STOP
then

if (garageDoorTimer !== null)
	{
	garageDoorTimer.cancel
	garageDoorTimer = null
	}

	if (GarageDoorClosed.state != ON && GarageDoorOpened.state != ON)
		{
		GarageDoorSwitch.sendCommand(ON)
		}
		
end
//********************************************************************




rule "Garage Door State"
when 
	Item GarageDoorClosed received update	or
	Item GarageDoorOpened received update
then
Thread.sleep(500)
	if (GarageDoorClosed.state == ON && GarageDoorOpened.state == OFF)
		{
		GarageDoor.postUpdate(DOWN)
		GarageDoorState.postUpdate("Closed")
		if (garageDoorOpenTimer !== null)
	        	{
      			garageDoorOpenTimer.cancel
        		garageDoorOpenTimer = null
        		}

		}
	if (GarageDoorOpened.state == ON && GarageDoorClosed.state == OFF)
		{
		GarageDoor.postUpdate(UP)
		GarageDoorState.postUpdate("Open")
		}
	if (GarageDoorClosed.state == OFF && GarageDoorOpened.state == OFF)
		{
		GarageDoor.postUpdate(50)
		GarageDoorState.postUpdate("Ajar")
		}
		
end
//********************************************************************




rule "Garage Door Button Timer"
when
	Item GarageDoorSwitch received command ON
then
	createTimer(now.plusSeconds(1)) [|
	GarageDoorSwitch.sendCommand(OFF)
	]
end


//********************************************************************
	
rule "Garage Door Auto Close"
when 
	Time cron "0 0/6 21-5 1/1 * ? *"
then



if (GarageDoorAuto.state == ON)
	{
	if (GarageDoorClosed.state != ON)
		{
		sendBroadcastNotification("Garage door will shut in 5 minutes")
		garageDoorOpenTimer=createTimer(now.plusMinutes(5)) [|
		sendBroadcastNotification("Garage door has closed automatically")
		GarageDoor.sendCommand(DOWN)
		]
		}
	}
end


//********************************************************************
	
rule "Garage Door Auto Close Switch "
when 
	Item GarageDoorAuto received command OFF
then
	if (garageDoorOpenTimer !== null)
	{
	garageDoorOpenTimer.cancel
	garageDoorOpenTimer = null
	}
end



//********************************************************************




rule "Garage Door Opening"
when 
	Item GarageDoorClosed changed from ON to OFF
then
	sendBroadcastNotification("Garage Door has opened!")
end

//********************************************************************

rule "Garage Door Closing"
when 
	Item GarageDoorOpened changed from ON to OFF
then
Thread::sleep(500)
	if (GarageDoorOpened.state != ON)
	{
	sendBroadcastNotification("Garage Door is Closing!")
	}	
end

Basically. I have a switch which literally sends the MQTT command,

I use a ruller shutter item to have UP X DOWN as commands.
I then run rules to check if the garage is down, and i press down, nothing happens, If the garage is up and i press up, nothing happens. And the X button only works if the garage is neither opened of closed.

I also have 2 reed switches, one for open, one for close.

I have another rule. which when i press either up or down, it sends the command to activate the garage. if after 25 seconds, it hasn’t activated the reed switch i wanted, (either opened or closed depending what i pressed), it will press the garage button one time. If for instance, there is something blocking the door from moving, it wont run the rule again, as I pressed the garage button, not pressed up/down again.

I also have timers, and auto closing after certain times. as you can see in my rules

2 Likes