Add reed switch to a Tasmota device's unused pin

Hello,

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}

did you get this to work? I am looking to do exactly the same thing?

Thanks,

Pete.

Replying to my own post. I have this working. Here are the steps:

  • Solder reed switch between GPIO1 and GND
  • Install Tasmota on ESP01
  • Set module type to “Generic (18)”
  • Set GPIO1 to “switch - 1”
  • configure the MQTT section as required.

In HA configuration.yaml
(note the ON/OFF are inverted)

mqtt:
 binary_sensor:
   unique_id: "sensor.garage_door"
   state_topic: "stat/tasmota_XXXXXX/POWER"
   name: "Garage Door"
   qos: 1
   payload_on: "OFF"
   payload_off: "ON"
   device_class: garage_door
  • add a card to your overview by entity (binary_sensor.garage_door)
type: entities
entities:
 - binary_sensor.garagedoor

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):

mosquitto_pub --url mqtt://USER:[email protected]:1883/cmnd/XXXXXX/POWER -n

but all I get back is:

{"Command":"Error"}

Tried entering this as console command with the same result. Anyone know how I can initiate a response for the

stat/XXXXXX/POWER

topic?

Thanks,

Pete.

1 Like

After a bit of tinkering I have what I am looking for:

mqtt:
  binary_sensor:
    - state_topic: "stat/tasmota_XXXXXX/POWER"
      unique_id: "sensor.garage_door"
      name: "Garage Door"
      qos: 1
      payload_on: "OFF"
      payload_off: "ON"
      device_class: garage_door

    - state_topic: "tele/tasmota_XXXXXX/SENSOR"
      unique_id: "sensor.garage_door1"
      name: "Garage Door1"
      qos: 1
      value_template: "{{ value_json.Switch1 }}"
      payload_on: "ON"
      payload_off: "OFF"
      device_class: garage_door

sensor:
  - platform: template
    sensors:
      door_state:
        friendly_name: "Garage Door State"
        unique_id: "sensor.garage_door_both"
        value_template: >-
          {% if is_state('binary_sensor.garagedoor', 'off') %} Closed
          {% elif is_state('binary_sensor.garagedoor', 'on') %} Open
          {% elif is_state('binary_sensor.garage_door1', 'off') %} Closed
          {% elif is_state('binary_sensor.garage_door1', 'on') %} Open
          {% else %} Unknown
          {% endif %}
        icon_template: >-
          {% if is_state('sensor.door_state', 'Open') %}
          mdi:garage-open
          {% else %}
          mdi:garage
          {% endif %}

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.

Pete.