Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPIO14 as door opening sensor #726

Closed
witek1308 opened this issue Aug 12, 2017 · 57 comments
Closed

GPIO14 as door opening sensor #726

witek1308 opened this issue Aug 12, 2017 · 57 comments

Comments

@witek1308
Copy link

Hi,
I can't find this anywhere on the internet whether Tasmota on Sonoff basic would support the a door opening sensor on GPIO14, but without impacting the state of relay (use GPIO14 just for reporting the state, ideally over MQTT).
I simply in my garage have one Sonoff Basic with Tasmota (5.5.2) which controls some other thing but is so close to the garage door that wiring will be piece of cake, it would be perfect to report open/close state. Garage door is controlled by "1 channel inching 5v" module running Tasmota too but as I understand this one doesn't have any GPIOs to do the work. Thanks in advance for all hints.

@witek1308
Copy link
Author

I used wrong filters for searching, I found similar question just before mine. I'll give it a try therefore I'm closing this subject.

@jtroberts1
Copy link

@witek1308 , can you tell me how you solved this issue? can you upload the link you referenced. I have switches on GPIO14 and 5 with relays on 4 and 12. every time I remove power from the Wemos it triggers the garage door. thanks in advance.

@witek1308
Copy link
Author

Will have a look when back at my pc. Please check issue #725 this is where I started.
When I am back I can check my config in details

@witek1308
Copy link
Author

ok the issue #438 is exactly what helped me (it's clear instruction what to do)

@sabs01
Copy link

sabs01 commented Sep 21, 2017

thanks is a good step in the right direction for me but cant seem to figure out how to allow home bridge to read the Mqtt message and change the status in home kit - Using sonoff basic as a garage door opener with a reed switch. (need to be able to detect when the manual RF opened is used rather than homekit)

@witek1308
Copy link
Author

you need to mount the opening sensor anyways (I did it). Reason: my garage door doesn't have just 2 states: opened and closed. If you press the button during opening you can stop it in between , same when closing. Therefore detecting the button was pressed will not tell you the state if this is what you need (especially if someone pressed the garage door RF or wall button - in my case you can control the door using 3 different ways independently - sonoff, RF remote, wall button)

@sabs01
Copy link

sabs01 commented Sep 21, 2017

thanks for your help -- I agree this seems to be the way to go.. do you have the code you have used for this to work with homebridge and sonoff ?

@witek1308
Copy link
Author

witek1308 commented Sep 21, 2017 via email

@sabs01
Copy link

sabs01 commented Sep 21, 2017

thanks I think I have figured it out - have changed my config.json file to the following :
"statusGet" : "cmnd/alarm/POWER1" (this is the MQTT message topic from GPIO14 GND switch)

instead of
"statusGet": "stat/sonoff/RESULT" (this is the MQTT message topic from the relay button)

this allows me to read 1 reed switch but need to figure out how to set up pins on the sonoff to read more than 1 switch, and code to read the MQTT topic for any other reed switches?? can anyone help thanks in advance.

@davidelang
Copy link
Collaborator

davidelang commented Sep 21, 2017 via email

@sabs01
Copy link

sabs01 commented Sep 21, 2017

thanks David I am a noob at this can you explain how - have tried to configure sonoff as a WEMOS mini and set GPIO3 as switch 2 but no joy?

@davidelang
Copy link
Collaborator

davidelang commented Sep 21, 2017 via email

@sabs01
Copy link

sabs01 commented Sep 21, 2017

Thanks David yes I can set GPIO3 to switch2 but cant get it to work in the same way GPIO14 does - you are correct GPIO3 is a serial port- perhaps I need to use a different GPIO to make things simple what do you think? any ideas on how to access other pins on the sonoff basic? or how do I disable serial logging - I am really clueless with this..

@sabs01
Copy link

sabs01 commented Sep 21, 2017

Mate you are a legend I have disabled serial logging and it works as an I/O pin - reading as cmnd/alarm/POWER2 = TOGGLE
now trying to change it to read ON and OFF any ideas?

@davidelang
Copy link
Collaborator

davidelang commented Sep 22, 2017 via email

@jannnfe
Copy link

jannnfe commented Oct 31, 2017

@witek1308 How do you get Tasmota on your 1 channel inching 5v. Can you please have a look at my issue?
#893
Thanks!

@bandric1
Copy link

bandric1 commented Nov 1, 2017

Can someone please help me im getting into my hairs and its killing me:

I changed topic for gpio14 to another one i see it in mqtt.fx it goes to on or to off. In openhab when i call it, it wont show "open" or "closed" state/change on gpio14.
I can switch the relay on or of via gpio5

this is my setup on openhab:

Mqtt.fx: shows this when state to gpio14 is changed:
cmnd/alarm-000B9593D/POWER2
ON

items:
Switch T_D_Garage1 "Garage Door 1"
[ "Switchable" ]
{ mqtt=">[broker:cmnd/WemosD1-000B9593D/POWER:command:*:default]" }

// WemosD1-000B9593D topic works fine i can use this to publish cmnd no problem. I have changed the topic for switch2 via console to alarm-000B9593D for the gpio14 swich2 (10)//

/* Items to represent the open/closed status of the opener */
Contact N_D_GarageDoor1 "Garage Door 1 [MAP(en.map):%s]" { mqtt="<[broker:cmnd/alarm-000B9593D/POWER2:state:default]" }

//In folder transform i have created en.map i put strings in there to define://
ON=closed
OFF=open
NULL=Alarm

Sitemap:
Switch item=T_D_Garage1 label="Garage Door 1" icon="garagedoor-closed" mappings=[ON=Open] visibility=[N_D_GarageDoor1!="OPEN"]
Switch item=T_D_Garage1 label="Garage Door 1" icon="garagedoor-open" mappings=[ON=Close] visibility=[N_D_GarageDoor1=="OPEN"]

//Please if someone can help me in any way or just point me.//

@davidelang
Copy link
Collaborator

davidelang commented Nov 1, 2017 via email

@bandric1
Copy link

bandric1 commented Nov 1, 2017

Thanks for a hint but it didnt work i tried your way. With state:MAP and no dice wont read. I just dont get it i can switch the items on/off but cant read current state dont get it i had to change topic due to unlinking the gpio14 from gpio5 so 14 dont turn 5 on when closed.

@davidelang
Copy link
Collaborator

davidelang commented Nov 1, 2017 via email

@bandric1
Copy link

bandric1 commented Nov 1, 2017

There is nothing in the logs i have allready checked it in openHABshare/openhab2-logs/

@davidelang
Copy link
Collaborator

davidelang commented Nov 2, 2017 via email

@Paulf007
Copy link

Paulf007 commented Nov 2, 2017

I am running a similar setup and it took a while for me to get this figured .
Here is a Pick of the SonOff Basic
2017-11-02_051819

I set the switchmode/switchtopic as per the wiki so that it works independently.
Then in Openhab.
ITEMS PAGE
Switch main_gate_gate "Main Gate" { mqtt=">[broker:nodered/main_gate/POWER2:command:*:default]", autoupdate="false" }
String main_gate_stat "Main Gate [%s]"{ mqtt="<[broker:cmnd/gate/POWER3:state:default]" }
String main_gate_stat1 "MainGate1 [%s]" { mqtt="<[broker:tele/main_gate/SENSOR:state:JSONPATH($.Switch3)]" }
String main_gate_stat2 "Main Gate2 [%s] " { mqtt="<[broker:nodered/main_gate/SENSOR:state:default]" }

SITEMAP
Switch item=main_gate_gate visibility=[main_gate_stat=="OFF",main_gate_stat2=="OFF"] mappings=["ON"="Open Gate"] icon="garagedoor"
Switch item=main_gate_gate visibility=[main_gate_stat=="ON",main_gate_stat2=="ON"] mappings=["ON"="Close Gate"] icon="garagedoor"

You will see in the command line of the switch that I send the value to node red as well as recieve from node red. The reason being that I have a function that switches POWER2 of about 500 ms after the on command was receive. Also use that state update to show or hide the switch on the site map.
Hope this helps.

@bandric1
Copy link

bandric1 commented Nov 2, 2017

Thanks a million "Paulf007" this one helped me finally im out off the loop. Now i see the state change but im having issue when sensor closes i get two states shown in classic-UI

this is sensor open:
screen shot 2017-11-02 at 23 22 52

this is the sensor closed
screen shot 2017-11-02 at 23 19 43

I had to change settings in my module it would not work like basic (with it GPIO rules) so i made them work like this:

screen shot 2017-11-02 at 23 27 14

This is my items code:
Switch main_gate_gate "MainGate" { mqtt=">[broker:cmnd/WemosD1-000B9593D/POWER1:command:*:default]", autoupdate="false" }
String main_gate_stat "MainGate [%s]" { mqtt="<[broker:cmnd/WemosD1-000B9593D/POWER1:state:default]" }
String main_gate_stat1 "MainGate [%s]" { mqtt="<[broker:tele/alarm2/POWER2:state:JSONPATH($.Switch2)]" }
String main_gate_stat2 "MainGate [%s]" { mqtt="<[broker:cmnd/alarm2/POWER2:state:default]" }

This is my sitemap code:
Switch item=main_gate_gate visibility=[main_gate_stat=="OFF",main_gate_stat2=="OFF"] mappings=["ON"="Open Gate"] icon="garagedoor"
Switch item=main_gate_gate visibility=[main_gate_stat=="ON",main_gate_stat2=="ON"] mappings=["ON"="Close Gate"] icon="garagedoor"

The sitemap is like it is yours "Paul007"

This is my console point out of WemosD1-mini

00:00:17 MQTT: stat/WemosD1-000B9593D/POWER1 = ON
00:00:18 MQTT: stat/WemosD1-000B9593D/RESULT = {"POWER1":"OFF"}
00:00:18 MQTT: stat/WemosD1-000B9593D/POWER1 = OFF
00:00:22 MQTT: cmnd/alarm2/POWER2 = ON
00:00:25 MQTT: cmnd/alarm2/POWER2 = OFF

@bandric1
Copy link

bandric1 commented Nov 2, 2017

I made a typo while edit now it works!!!

this is the correct sitemap:
Thanks again "Paul007"

Switch item=main_gate_gate visibility=[main_gate_stat1=="OFF",main_gate_stat2=="OFF"] mappings=["ON"="Open Gate"] icon="garagedoor"
Switch item=main_gate_gate visibility=[main_gate_stat1=="ON",main_gate_stat2=="ON"] mappings=["ON"="Close Gate"] icon="garagedoor"

If someone wants to build a GOPENER with arenst tasmota and Wemos D1-mini i can say that it works now i got some greyhairs and restless nights. But got out off it thanks to Paul007.

Upper response is full layout od settings after uploading the firmware you have to go to console:
1). Type in PULSETIME 15 (or any number your relay shield wild then be push button)
2). 2a. type: switchmode 2
2b. type: switchtopic alarm
#438

Then go and play with openhab....

@Paulf007
Copy link

Paulf007 commented Nov 3, 2017

Upper response is full layout od settings after uploading the firmware you have to go to console:
1). Type in PULSETIME 15 (or any number your relay shield wild then be push button)
2). 2a. type: switchmode 2
2b. type: switchtopic alarm

Thank you for that one as well. There is so many features in this firmware that it keeps on amazing me!!

@bandric1
Copy link

bandric1 commented Nov 6, 2017

has anyone encountered an issue when wenos is being trigrerred to open door by itself i checked logs once the wifi was lost onve it was a wemos reboot once it happened when mosquito reboot. Does anyone have an idea how to stop this from happening.

@smulle48
Copy link

smulle48 commented Nov 25, 2017

@bandric1 I have the exact same problem. When my wemos d1 mini is connected to my mqtt server, it all work as it supposed to, but if the wemos loose connection to the mqtt server, my reed switch, act like a real switch, switching the relay.

@smulle48
Copy link

@bandric1 I finally got it working. Switch1 will always act like a real switch for relay1 if no mqtt connection. I have made mine with a switch1 not connected to anything. I have then added a reed switch to switch2 and send the command: "switchmode2 2" and "switchtopic2 alarm". now the reed switch return "stat/sonoff/RESULT = {"POWER2":"OFF"}" and "stat/sonoff/RESULT = {"POWER2":"ON"}" without toggle the relay1 :-)

@bandric1
Copy link

Great please post screenshots from tasmota web interface and settings from things, items and sitemap. So everyone can benefit.

@smulle48
Copy link

I use the Wemos D1 mini with relay shield.

The relay is connected to D1 (GPIO5)

I have set it up to:
D1 (GPIO5) = Relay1
D6 (GPIO12) = Switch2 (Reed switch)
D8 (GPIO15) = Relay2

The I console I ran the command:
PulseTime 10
Switchmode2 2
SwitcoTopic2 alarm

Now Relay1 (relay shield) is independent from switch2 (reed switch) even if there is no mqtt connection. When you look at the main menu, there is actually 2 relay and the reed switch is controlling the relay2 which have no physical connection.

Now when firing the command cmd/sonoff/POWER1 ON the relay turn on for about 1 sec and the turn off again.

The status of POWER2 (reed switch) I am catching in node-red to fire a pushover message to my iPhone telling if the garage door is open or closed.

wemos

@bandric1
Copy link

I finally got some time tried it u used now latest tasmota firmware but here is something with this firmware that it doesnt like this wemos d1 mini after mosquito restart or device looses wifi or restarts after power loss garage door opens im loosing it i guess i will just give up on this and try other firmware since this is not working for me.

@bandric1
Copy link

all my other devices sonoff and esps dont supper from this only the wemos d1 mini does

@smulle48
Copy link

Have you set it to:

PowerOnState 0

If it’s set to on, it will toggle the relay on restart

@davidelang
Copy link
Collaborator

davidelang commented Dec 15, 2017 via email

@bandric1
Copy link

I changed the wemos d1 module with other one and now it works. Damn i used so much time on this.
But now when i put a pin D6 to GND the RELAY2 doesnt swicht/change from OFF to ON.

@bandric1
Copy link

bandric1 commented Dec 15, 2017

It works as meant thank you guys. Well it did until today now its back to start one after restart or power loss or wifi loss it clicks. I woke up today and garage was wide open. I guess i give up. Will try someone else firmware.

@JuliusLedoux
Copy link

Hi There I hope that someone can help me with this situation: I have setup a sonoff sv as my garage controller. My configuration is:
image
I have setup the reed switch on GPIO14 as switch2 and I also have GPIO5 being used for a DHT22 temperature sensor.
I have done the following configuration steps on the console:
pulsetime 10 (To Turn the relay off after one second),
switchmode1 0, then switchmode2 1 and then I have done swithctopic2 DoorStatus.
I am using Home Assistant as my HUB. In my subscription topic I am using the following:
cover:

  • platform: mqtt
    name: "Garage Door"
    state_topic: "cmnd/DoorStatus/POWER2"
    command_topic: "cmnd/garage/POWER"
    availability_topic: "tele/garage/LWT"
    payload_open: "ON"
    payload_close: "ON"
    payload_stop: "ON"
    payload_available: "Online"
    payload_not_available: "Offline"
    state_open: "ON"
    state_closed: "OFF"
    optimistic: false
    retain: false
    I also have an automation that alerts me when the door is open; everything seems to be working fine. I can open and close my garage from the Application and I can see the status changing accordingly, on the screen, but some reason that I do not understand my automation tells me that the door is open (again) when the door it is just closed. It seems to be generating 2 events on each situation.
    For what is worth this is my automation:
    alias: Play Media When Garage Opens
    trigger:
  • entity_id: cover.garage_door
    platform: state
    from: closed
    to: open
    condition:
  • condition: state
    entity_id: group.family
    state: home
    action:
  • data:
    message: Heads up! The Garage is Open
    entity_id:
    • media_player.living_room_speaker
      service: tts.google_say

When I look at the logs on Tasmota this is what I see:

Opening:
16:09:59 RSL: Received Topic cmnd/garage/POWER, Data Size 2, Data ON
16:09:59 RSL: Group 0, Index 1, Command POWER, Data ON
16:09:59 MQT: stat/garage/RESULT = {"POWER":"ON"}
16:09:59 MQT: stat/garage/POWER = ON
16:10:00 MQT: cmnd/DoorStatus/POWER2 = ON
16:10:00 MQT: cmnd/DoorStatus/POWER2 = OFF
16:10:00 MQT: cmnd/DoorStatus/POWER2 = ON

16:10:00 MQT: stat/garage/RESULT = {"POWER":"OFF"}
16:10:00 MQT: stat/garage/POWER = OFF

Closing:

16:12:25 RSL: Received Topic cmnd/garage/POWER, Data Size 2, Data ON
16:12:25 RSL: Group 0, Index 1, Command POWER, Data ON
16:12:25 MQT: stat/garage/RESULT = {"POWER":"ON"}
16:12:25 MQT: stat/garage/POWER = ON
16:12:26 MQT: stat/garage/RESULT = {"POWER":"OFF"}
16:12:26 MQT: stat/garage/POWER = OFF
16:12:33 WIF: Checking connection...
16:12:33 WIF: Connected
16:12:35 MQT: cmnd/DoorStatus/POWER2 = OFF
16:12:35 MQT: cmnd/DoorStatus/POWER2 = ON
16:12:35 MQT: cmnd/DoorStatus/POWER2 = OFF

Any help on this is highly appreciated!

@dastrix80
Copy link

@JuliusLedoux
Copy link

I believe it will work. Just verify if it is Normally open or Normally close.

@dastrix80
Copy link

I shall do. I will need a Normally Closed sensor.

I also have a seperate relay free on my Sonoff 4CH WIFI Pro R2, I'm assuming I can use this and not GPIO14 on the Sonoff Basics as per this thread. I have tasmota on there. Do you know whats requird Julius to have it function?

@JuliusLedoux
Copy link

I do not have a Sonoff 4CH. But based on the specs it should work in a similar way that it does on the basic one. Take a look at https://youtu.be/uwFmfC0iJiY

@dastrix80
Copy link

Yes, I have this unit.

@i3laze
Copy link

i3laze commented Jul 10, 2018

Here's how I just did without MQTT (Sonoff Basic, Reed sensor on Gpio 14 + Gnd):

Module Configuration:

  • still Sonoff Basic
  • GPIO4: relay2 - a virtual relay which will hold the state of the reed. Like "On = door is open".
  • GPIO14: switch2 - a connected NO reed sensor triggers relay2 state on change

Finally, relay2 status can be queried by Power2 command.

Switchmode2 2 (for NO reed, 1 for NC reed) - this way Relay2 status will follow the state of the reed correctly, if by mistake it was software-triggered to an opposite state.
Pulsetime1 0.5 - in my case I use pulse for controlling garage door unit circuit.

Now it's time to write a HomeBridge plugin, which will control the whole logic.

@jcconnell
Copy link

@i3laze can you explain the virtual relay concept a bit more? I've configured two Sonoff basics for use as garage door openers, with a reed switch on GPIO14. I have them setup in Home Assistant, but when Home Assistant is rebooted, the state of the garage door is not shown.

I could set the powerrtain on but then relay1 is cycled on each reboot. I'm wondering if having the virtual relay to store the state could nullify this shortcoming, so that I can still track the state of the garage across reboots.

@ascillato
Copy link
Contributor

Hi @jcconnell

To make home assistant read the status of Tasmota when home assistant restarts, it is explained at the wiki in the home assistant part . It is just adding an automation to make all sonoffs inform its status when home assistant starts.

@ascillato
Copy link
Contributor

At Tasmota wiki I meant

@jcconnell
Copy link

It looks like that is sending a command to the sonoff. How do I read the state of the sensor?

The statetopic for the garage door reed sensor is "cmnd/garage_door_status/POWER2"

@ascillato
Copy link
Contributor

ascillato commented Jul 11, 2018

If you want Home Assistant to know the state of all your Tasmota devices when Home Assistant starts, just copy and paste (without modifying anything) to your automation.yaml the configuration explained in the wiki at:

https://github.com/arendst/Sonoff-Tasmota/wiki/Home-Assistant#power-state-on-start-up-without-retain-option

No need to modify anything neither use retain values in Home asistant nor in the MQTT broker. The internal state of the Tasmota need to be just in Tasmota.

The topic sonoffs is a group topic. All Tasmotas have that as default. No matter that you have changed your device topic to garage_door_status. That's why, just copy and paste and should work. I use exactly that and works amaizing.

@jcconnell
Copy link

Awesome, that works well for my other sonoffs. Thank you. I have a unique use case for the two I'm using as garage door openers though. I need to keep track of the status of a reed sensor connected to GPIO14 on these two Sonoffs. The reed sensor indicates the position of the garage door: Normally closed so 1=open, 0=closed. The relay controls the actuation of the door: 1 sec pulse = pressing the wall mounted button.

@jcconnell
Copy link

I noticed that the telemetry reports the state of the reed switch on GPIO14. I wonder if it's possible to use that instead?

@ascillato
Copy link
Contributor

Yes, the telemetry is intended for that. You can use that of course.

You should have a telemetry like:

tele/sonoff/SENSOR = {"Time":"2018-07-12T12:00:05","Switch1":"ON"}

So, put in your configuration.yaml

sensor:
  - platform: mqtt
    name: "Humedad Ambiente"
    state_topic: "tele/sonoff/SENSOR"
    value_template: "{{ value_json['Switch1'] }}"

@i3laze
Copy link

i3laze commented Jul 12, 2018

tele/sonoff/SENSOR = {"Time":"2018-07-12T12:00:05","Switch1":"ON"}

Any (web-) command to query switch state without MQTT?

UPD: Found. Status 8! Can build on that. No need for relay2 now :)

17:12:48 CMD: status 8
17:12:48 RSL: STATUS8 = {"StatusSNS":{"Time":"2018-07-12T17:12:48","Switch2":"ON"}}
17:13:20 CMD: status 10
17:13:20 RSL: STATUS10 = {"StatusSNS":{"Time":"2018-07-12T17:13:20","Switch2":"ON"}}

http://sonoff/cm?cmnd=status%208

@jcconnell
Copy link

jcconnell commented Jul 12, 2018

Here is what I have currently:

      cover:
        - platform: mqtt  
           name: "Garage Door Sonoff" 
           state_topic: "cmnd/garage_door_status/POWER2"
           command_topic: "cmnd/garage_door/POWER"
           availability_topic: "tele/garage_door/LWT"
           payload_open: "ON"
           payload_close: "ON"
           payload_stop: "ON"
           payload_available: "Online"
           payload_not_available: "Offline"
           state_open: "ON"
           state_closed: "OFF"
           optimistic: false
           retain: false

Would this be the correct implementation to use telemetry as state?

      cover:
        - platform: mqtt  
           name: "Garage Door Sonoff" 
           state_topic: "tele/garage_door_status/SENSOR"
           value_template: "{{ value_json['Switch2'] }}"
           command_topic: "cmnd/garage_door/POWER"
           availability_topic: "tele/garage_door/LWT"
           payload_open: "ON"
           payload_close: "ON"
           payload_stop: "ON"
           payload_available: "Online"
           payload_not_available: "Offline"
           state_open: "ON"
           state_closed: "OFF"
           optimistic: false
           retain: false

Finally, I've noticed that if I reboot a Sonoff, the item becomes unavailable in HA, but it never becomes available again once the reboot finishes. Any idea why?

@ascillato
Copy link
Contributor

In your last config you are mixing controlling with sensing.

Those need to be separated.

@n00bster-za
Copy link

has been a while since someone posted here. I need assistance on getting the GPIO14 to read more than just on or off. I have a gate motor with a dedicated Gate status output. The gate status can be open,close,opening,closing,collision. How do I configure the GPIO to read all those different states and add it to HA.

@ascillato2
Copy link
Collaborator

Hi, this issue is very old and your question is not directly related to this. Please, open a new discussion posting all the information you have (hardware type, tasmota version, what have you tried, etc), or ask in the support chat. Thanks.

Repository owner locked as resolved and limited conversation to collaborators May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests