Well, today I finally finished something that’s been bugging me for quite a while. I had long ago added a sonoff SV to open and close my Garage door. It even had a security code on it that I had to tell the Google when I wanted to open it. I was proud of it until one day I told the closed garage door to close by mistake. It opened and I didn’t need the code. You see all you have to do is activate the relay to open the door, close the door, or stop the doors travel using the HA Cover integration. When there is only 1 relay, all three commands enable the same relay in the same way. They all control your garage door.
One day about a month ago, I was looking thru the Tasmota Commands Documentation and found an example https://github.com/arendst/Tasmota/issues/3942 there to actually fix that problem. Awesome, right? Well that person used some kind of hardware switches on 2 of the GPIO’s on their SV to accomplish the door position sensing. The problem there was I’m already using this SV in the garage to run my Outdoor PIR. https://whatarewefixing.today/69/episode-3-outdoor-pir-on-home-assistant-for-less-than-10-replace-ring-motion-sensor/ Plus I didn’t want to buy anything else. I already had a RF433 2 code sensor (GS-WDS07 https://www.gearbest.com/access-control/pp_593451.html) on the door, so I wanted to use that.
After some thought, I decided in order to make it work like the sample code, I would need to grab another of those door sensors from my parts bin. I mounted that switch such that the magnet that was traveling on the door would activate the sensor on the door frame when the door is closed, and the sensor by the garage opener motor when it is open. I determined the codes for these switches with my RFBridge https://www.youtube.com/watch?v=OfSbIFIJPuc and them spooled up a couple of rules to let my SV know the door status.
Rules on RFBridge:
(rule 1)
on RFReceived#data=2B2A0E do publish2 garage_door/cmnd/EVENT CLOSED endon
on RFReceived#data=2B2A0A do publish2 garage_door/cmnd/EVENT OPENING endon
on RFReceived#data=2D750E do publish2 garage_door/cmnd/EVENT OPENED endon
on RFReceived#data=2D750A do publish2 garage_door/cmnd/EVENT CLOSING endon
COPY:
backlog rule1 on RFReceived#data=2B2A0E do publish2 garage_door/cmnd/EVENT CLOSED endon on RFReceived#data=2B2A0A do publish2 garage_door/cmnd/EVENT OPENING endon on RFReceived#data=2D750E do publish2 garage_door/cmnd/EVENT OPENED endon on RFReceived#data=2D750A do publish2 garage_door/cmnd/EVENT CLOSING endon;rule1 1
The RFBridge will look for a code (IE 2B2A0E) and when it sees it will publish2 (publish with retain) a message to the sonoff SV that this switch event happened. The first 2 are for the open and close code at the door frame (closed door), and the other 2 are for when the door is open. The retain is important, as when the SV reboots, it will get the switch position from the broker when it connects to the broker. Without this, it would get out of sync every time the SV boots.
Rules on Sonoff SV:
(Rule 1)
on EVENT#OPEN do power1 %var2% endon
on EVENT#CLOSE do power1 %var1% endon
on EVENT#STOPPED do backlog power1 %var3%; power1 %var4%; event PState=STOPPED endon
(Rule 2)
on event#OPENED do backlog var1 1; var2 0; var3 0; var4 0; ruletimer1 0; event PState=OPEN endon
on event#CLOSED do backlog var1 0; var2 1; var3 0; var4 0; ruletimer1 0; event PState=CLOSE endon
on event#OPENING do backlog var1 0; var2 0; var3 1; var4 0; ruletimer1 15; event PState=OPENING endon
on event#CLOSING do backlog var1 0; var2 0; var3 0; var4 1; ruletimer1 15; event PState=CLOSING endon
on rules#timer=1 do event PState=STOPPED endon
on event#PState do publish2 garage_door/stat/STATE %value% endon
COPY:
rule1 on EVENT#OPEN do power1 %var2% endon on EVENT#CLOSE do power1 %var1% endon on EVENT#STOPPED do backlog power1 %var3%; power1 %var4%; event PState=STOPPED endon
COPY:
rule2 on event#OPENED do backlog var1 1; var2 0; var3 0; var4 0; ruletimer1 0; event PState=OPEN endon on event#CLOSED do backlog var1 0; var2 1; var3 0; var4 0; ruletimer1 0; event PState=CLOSE endon on event#OPENING do backlog var1 0; var2 0; var3 1; var4 0; ruletimer1 15; event PState=OPENING endon on event#CLOSING do backlog var1 0; var2 0; var3 0; var4 1; ruletimer1 15; event PState=CLOSING endon on rules#timer=1 do event PState=STOPPED endon on event#PState do publish2 garage_door/stat/STATE %value% endon
To explain these rules, here goes. Rule 1 is the command responses from HA. The 3 commands from HA are OPEN, CLOSE, and STOPPED. Each are a variation of a power command for the relay and a variable. The 4 variables function as the position action table for the door status as such:
So the door doesn’t close if you send it an Open when it’s already Opened, etc.
- var1=1 Only When OPEN
- var2=1 Only When CLOSED
- var3=1 Only When OPENING
- var4=1 Only When CLOSING
Rule 2 here takes the input from the switches and sets the variables to the correct configuration based on their requirements. It basically allows the power calls to the variables from rule 1 to either fire the door or not, depending on the switch position.
Also in Rule 2 is the stop action from the rule timer should the door not complete in the normal time. My door takes a little over 13 seconds to traverse, so if it takes longer than 15 seconds to traverse, a stopped code is issued via the ruletimer1 command.
Finally Rule 2 sends the status back to HA that is generated thru the PState event so that HA can display the correct icon and know when to enable the OPEN and CLOSE button. It is also important to use the publish2 command here because then when HA reboots, it will remember (from the broker) the state of the door and display correctly in HA on boot.
Once that is done, you need to set up the switches and rules on your SV to function as expected. These were taken from the GIT repository suggestions, not sure that mine was set up exactly this way but I do have PulseTime1 52 on mine to hold the button on for ~5 seconds.
PulseTime1 7
SwitchMode1 1
SetOption0 0
PoweronState 0
Rule1 4
Rule2 4
Rule1 1
Rule2 1
COPY:
Backlog PulseTime1 7; SwitchMode1 1; SetOption0 0; PoweronState 0; Rule1 4; Rule2 4; Rule1 1; Rule2 1
Cover YAML:
cover:
- platform: mqtt
name: "Garage Door"
unique_id: b79e4687-6790-486a-90e9-ccdc574cdc1d
device_class: garage
optimistic: false
state_topic: garage_door/stat/STATE
state_open: 'OPEN'
state_closed: 'CLOSE'
state_opening: 'OPENING'
state_closing: 'CLOSING'
command_topic: garage_door/cmnd/EVENT
payload_open: 'OPEN'
payload_close: 'CLOSE'
payload_stop: 'STOPPED'
availability_topic: garage_door/tele/LWT
payload_available: 'Online'
payload_not_available: 'Offline'
tilt_opened_value: 100
That is pretty straight forward. The unique id is just a randomly generated UUID that you can generate with a click from the VSCode addin, but any unique string will do there. You will notice that I have all my topics flipped from the standard Tasmota way. This way makes more sense to me in my CDO mind, but you may want to have yours flipped around to standard. To each their own…
If you want more information on the setup using optical switches tied to the SV’s GPIO pins, please see the original article. https://github.com/arendst/Tasmota/issues/3942
Link to TDM Tasmota Device Manager: https://github.com/jziolkowski/tdm Link to some switches: https://www.aliexpress.us/item/3256802918457592.html?spm=a2g0s.9042311.0.0.40694c4db8oCxz
Revision 05-13-2021 Change STOP codes to STOPPED to remove HA Warning in the logs.
Episode: E042
Contact Links:
What are we Fixing Today Homepage / Website:
https://www.WhatAreWeFixing.Today/
Channel Link URL: (WhatAreWeFixingToday)
https://bit.ly/WhatAreWeFixingTodaysYT
What are we Fixing Today Facebook page (Sir GoodEnough):
https://bit.ly/WhatAreWeFixingTodaybFB
What are we Fixing Today Twitter Account (Sir GoodEnough):
https://bit.ly/WhatAreWeFixingTodayTW
Discord Account: (Sir_Goodenough#9683)
https://discord.gg/Uhmhu3B
Please help support the channel:
Buy me Coffee: https://www.buymeacoffee.com/SirGoodenough
PayPal one-off donation link: https://www.paypal.me/SirGoodenough
Cash App $CASHTAG: https://cash.me/$SirGoodenough
Venmo cash link: https://venmo.com/SirGoodenough
If you would like to donate anything to this channel, please use this address:
C/O: Sirius GoodEnough
322 Buena Vista Ave.
Department: DYT
Waukesha, Wisconsin, 53188-3602
YouTube Video is located at this URL: https://youtu.be/JZlg_6b__j8