Wemos D1 Mini and HC SR501 PIR Motion Sensor - seurat-atreides/Sonoff-Tasmota GitHub Wiki

HC-SR501 PIR Motion Sensor (single pin)

PIR sensors allow you to sense motion, almost always used to detect whether a human has moved in or out of the sensors range. See PIR Motion Sensor for more information.

Connecting the PIR to a Wemos Mini D1

Wemos PIR
GND GND
5V POWER (VCC)
D5 (gpio14) OUTPUT

Tasmota Configuration

In the Configuration -> Configure Module page, select the following:

  1. Module Type : 18 Generic
  2. D5 GPIO14 Sensor : 09 Switch1
  3. D6 GPIO12 Relay1 : 17 Relay1

Tasmota Main

After reboot of the device the displays the status of relay1 aka switch1.

Alternative Tasmota Configuration with Rules (Recommended Method)

If you don't want to drive a relay attached to the Wemos directly and instead send MQTT messages if the PIR gets triggered, you can use a similar configuration as above plus Tasmota rules.

Configure the module as described above but omit the GPIO12 = Relay1 setting (leave at 'None').

Then go to console in the webinterface and add a rule that sends a MQTT message if the PIR is triggered:

Switchmode1 1
Switchtopic 0
Rule1 on switch1#state=1 do publish stat/sonoff/PIR1 ON endon on switch1#state=0 do publish stat/sonoff/PIR1 OFF endon
Rule1 1

Note: the webinterface (obviously) won't show the relay state as "ON" or "OFF" any more - you have to watch the MQTT messages on the console to see the PIR trigger.

If you want to attach a second PIR to another GPIO (e.g. D1 / GPIO5), configure it as Switch2 and add another rule via console:

Switchmode2 1
Switchtopic 0
Rule2 on switch2#state=1 do publish stat/sonoff/PIR2 ON endon on switch2#state=0 do publish stat/sonoff/PIR2 OFF endon
Rule2 1