I use a ESP-01s relay as switch in a place where it’d be interesting to add a “open/close” sensor (Right next to a door). I was wondering if I could use a spare GPIO pin with just a reed switch.
I’m not very knowledgeable on the matter, but it seems that GPIO2 could be used for this. According to this datasheet (?) GPIO0 is used to trigger the relay and I think (after reading this) that GPIO2 is unused. Also, after reading the comments here, I’d guess I’d have to solder a reed switch between GPIO2 and GND and then change the configuration on the device’s template to switch and lastly dettach this switch with the “SwitchMode2 15” command, right? Is that all that it’d take?
My module is running Tasmota 12.0.2 with this template: {"NAME":"ESP01s Relay","GPIO":[256,1,1,1,1,1,1,1,1,1,1,1,1,1],"FLAG":0,"BASE":18}
When the door is open the card shows the open icon and the word open, and the opposite when closed.
One thing I would like to do is get the state of the door when HA starts up (or poll is regularly). At the moment it will show as “unknown”. I have tried this using the following (from the Tasmota docs):
Tasmota sends out an MQTT message every 5 minutes with information on status (second binary sensor listening to “tele”). I use this to get the initial state (for when HA boots/starts up). Otherwise it listens for the POWER MQTT topic for a change of state. The template is used to show the state on my dashboard, the icon with change and the text will change indicating if the door is open or closed.
Hope others find this useful. Although I am sure there is a more elegant way to do this but I am new to both HA and Tasmota.