PIR changes

blakadder 2019-10-30 20:19:47 +01:00
parent 8aa2741571
commit 142b301922
13 changed files with 282 additions and 92 deletions

@ -1,4 +1,4 @@
Buttons and switches are primarily used to toggle (turn ON or OFF) device relays. A typical device usually has at least one button (exception being bulbs and some lights) to control the relay(s). Additional buttons and switches can be [wired](Expanding-Sonoffs#connect-switch) to a free GPIO and configured in Module or Template settings. Buttons and switches are primarily used to toggle (turn ON or OFF) device relays. A typical device usually has at least one button (exception being bulbs and some lights) to control the relay(s). Additional buttons and switches can be [wired](Expanding-Tasmota#connect-switch) to a free GPIO and configured in Module or Template settings.
> Other than relays, Tasmota does not publish the state of components (switches, buttons, sensors, etc.) in real-time. Only messages corresponding to relays are transmitted in real-time. The state of components is transmitted automatically each [TelePeriod](Commands#teleperiod) via the `SENSORS` message. > Other than relays, Tasmota does not publish the state of components (switches, buttons, sensors, etc.) in real-time. Only messages corresponding to relays are transmitted in real-time. The state of components is transmitted automatically each [TelePeriod](Commands#teleperiod) via the `SENSORS` message.

@ -13,7 +13,7 @@ If you wish to expand a device with your own component, after properly wiring ev
![GPIO assign](https://user-images.githubusercontent.com/5904370/58193269-e771b800-7cc2-11e9-9bb6-8d425a1fa3b2.png) ![GPIO assign](https://user-images.githubusercontent.com/5904370/58193269-e771b800-7cc2-11e9-9bb6-8d425a1fa3b2.png)
Read more about adding specific [sensors](supported-sensors) or [adding peripherals to a device](Expanding-Sonoffs). Read more about adding specific [sensors](supported-sensors) or [adding peripherals to a device](Expanding-Tasmota).
### Components List ### Components List
|#|Name|Description |#|Name|Description

138
Expanding-Tasmota.md Normal file

@ -0,0 +1,138 @@
One capability of Tasmota is that you can connect additional things to available pins on the [ESP8266](https://en.wikipedia.org/wiki/ESP8266) that controls these devices.
If a pin is defined as GPIO_USER in the module template, you can assign a function to it. (Complete [list](https://github.com/arendst/Sonoff-Tasmota/wiki/Components#components-list)) of functions.
To make a link between the different naming schemes of pins, connectors and logical functions, the [Pin Definition overview](https://github.com/esp8266/esp8266-wiki/wiki/Pin-definition) in the esp8266 wiki is quite helpful.
## Restrictions 🚨
Don't use GPIO: 0, 1, 2, 6-11, 15, 16 if you can avoid it. 3 is RX, so best to avoid also (PWM not working here). That leaves 4, 5, 12, 13, 14 that don't have any constraints. The others can be used, but you have to mind the constraints outlined in [this document](https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html).
## Examples
### Connect switch
If you take a Sonoff Basic and connect a switch between pin4 (GND) and pin5 (GPIO14) of the 5 pin programming header you now have a second switch connected to the device. You can set this through the module config page as option ``09 Switch1`` or from the command line with ``gpio14 9``.
If you have fewer than two relays on the module, the additional switch(es) will not show up in the web UI and will control the single relay unless you set switchtopic to something other than 0 (either 1 or a custom topic). Once this is done the built-in switch will produce ``stat/<topic>/POWER1`` while the new switch will produce ``cmnd/<switchtopic>/POWER1``
With more relays on the modules, the additional switch will create additional POWER\<n> events without the need to set switchtopic.
You can set the mode of each switch individually with ``switchmode1`` or ``switchmode2``
See [Buttons-and-Switches](Buttons-and-Switches) for more information.
## Connect jack
Instead of connecting a switch, you could connect a 4-pin 2.5mm jack, with the pins wired:
* tip pin5 (GPIO14)
* r1 no connection
* r2 pin1 (ground)
* r3 pin4 (3.3V)
You can then plug a sensor into the jack like you would to a Sonoff TH10/TH16 and define what sensor you have connected to GPIO14
## Electrical considerations
When you switch a GPIO pin to an input and hang a long wire off of it, that wire can pick up stray signals and cause the voltage on the GPIO pin to vary. This can cause the system to think the switch has changed.
To fix this, there are several things you can do.
1. add a pull-up resistor
2. add a bypass capacitor
3. shielding on the wire
4. use twisted pair wiring
A pull-up resistor is a resistor connected between the GPIO pin and 3.3v. The exact value of this is not critical, 4.7k is a common value to use, as is 10k. This ensures that when the switch it open, the GPIO pin will go high.
A bypass capacitor is a small (pF range) capacitor that is connected between the GPIO and ground. This provides a path for any radio signals that are picked up by the wire to go to ground and not confuse the system.
Shielding or using twisted pair wiring are other ways to reduce the effect of radio signals on the system.
Example for 10K Resistor:
![](https://user-images.githubusercontent.com/35574450/39960640-8b2735ca-5626-11e8-8128-461b6d9976ad.png)
Read here:
[#2708](https://github.com/arendst/Sonoff-Tasmota/issues/2708#issuecomment-388574891)
If the Sensor is connected, go on here: [Sensor Configuration](https://github.com/arendst/Sonoff-Tasmota/wiki/Sensor-Configuration)
# The ESP8266 - [Hardware](https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html)
## Digital I/O
Just like a normal Arduino, the ESP8266 has digital input/output pins (I/O or GPIO, General Purpose Input/Output pins). As the name implies, they can be used as digital inputs to read a digital voltage, or as digital outputs to output either 0V (sink current) or 3.3V (source current).
## Voltage and current restrictions
The ESP8266 is a 3.3V microcontroller, so its I/O operates at 3.3V as well. The pins are not 5V tolerant, applying more than 3.6V on any pin will kill the chip.
The maximum current that can be drawn from a single GPIO pin is 12mA.
The [power supplied to the device](https://www.letscontrolit.com/wiki/index.php?title=Power) is **one of the most important elements** for stable device operation. Voltage regulation issues typically result in fatal exception [fault code](https://github.com/esp8266/Arduino/blob/master/doc/exception_causes.rst) `1`. You must ensure that the device receives sufficient power (current AND appropriate voltage level). You must take into account the current that each sensor powered from the device itself will draw. Connected sensors may strain the ability of the power supply on the device to deliver appropriate power to all the components, both on-board as well as externally connected.
## Usable pins
The ESP8266 and ESP8255 have 17 GPIO pins (0-16) but several are [reserved or have constraints](https://i.imgur.com/IH1fYqF.jpg). Do not use any of the _**reserved**_ pins. If you do, you might crash your program. On the ESP8266, six pins (GPIO 6 - 11) are used to interface the flash memory (the small 8-legged chip usually right next to the ESP8266). The ESP8255 has its flash memory integrated into the chip which frees up GPIO 9 and 10.
GPIO 1 and 3 are used as TX and RX of the hardware Serial port (UART), so in most cases, you cant use them as normal I/O while sending/receiving serial data.
### Boot modes
Some I/O pins have a special function during boot: They select 1 of 3 boot modes:
GPIO15 | GPIO0 | GPIO2 | Mode
---------------|-----------|------------|------------------------------------------------------------------
0V | 0V | 3.3V | Uart Bootloader
0V | 3.3V | 3.3V | Boot sketch (SPI flash)
3.3V | x| x | SDIO mode (not used for Arduino)
Note: you dont have to add an external pull-up resistor to GPIO2, the internal one is enabled at boot.
We have to be sure that these conditions are met by adding external resistors, or the board manufacturer of your board has added them for you. This has some implications, however:
GPIO15 is always pulled low, so you cant use the internal pull-up resistor. You have to keep this in mind when using GPIO15 as an input to read a switch or connect it to a device with an open-collector (or open-drain) output, like I²C.
GPIO0 is pulled high during normal operation, so you cant use it as a Hi-Z input.
GPIO2 cant be low at boot, so you cant connect a switch to it.
Internal pull-up/-down resistors
GPIO 0-15 all have a built-in pull-up resistor, just like in an Arduino. GPIO16 has a built-in pull-down resistor.
### PWM
Unlike most Atmel chips (Arduino), the ESP8266 doesnt support hardware PWM, however, software PWM is supported on all digital pins. The default PWM range is 10-bits @ 1kHz, but this can be changed (up to >14-bit@1kHz). Check [Restrictions](https://github.com/arendst/Sonoff-Tasmota/wiki/Expanding-Tasmota#restrictions).
### Analog input
The ESP8266 has a single analog input, with an input range of 0 - 1.0V. If you supply 3.3V, for example, you will damage the chip. Some boards like the NodeMCU have an on-board resistive voltage divider, to get an easier 0 - 3.3V range. You could also just use a trimpot as a voltage divider.
The ADC (analog to digital converter) has a resolution of 10 bits.
### Communication
### Serial
The ESP8266 has two hardware UARTS (Serial ports):
UART0 on pins 1 and 3 (TX0 and RX0 resp.), and UART1 on pins 2 and 8 (TX1 and RX1 resp.), however, GPIO8 is used to connect the flash chip. This means that UART1 can only transmit data.
UART0 also has hardware flow control on pins 15 and 13 (RTS0 and CTS0 resp.). These two pins can also be used as alternative TX0 and RX0 pins.
### I²C
The ESP doesnt have a hardware TWI (Two Wire Interface), but it is implemented in software. This means that you can use pretty much any two digital pins. By default, the I²C library uses pin 4 as SDA and pin 5 as SCL. (The data sheet specifies GPIO2 as SDA and GPIO14 as SCL.) The maximum speed is approximately 450kHz.
### SPI
The ESP8266 has one SPI connection available to the user, referred to as HSPI. It uses GPIO14 as CLK, 12 as MISO, 13 as MOSI and 15 as Slave Select (SS). It can be used in both Slave and Master mode (in software).
### GPIO overview
[NodeMCU Labelled Pin](https://techtutorialsx.com/2017/04/02/esp8266-nodemcu-pin-mappings/) | GPIO | Function | State | Restrictions
-|-|-|-|-
D3 | 0 | Boot mode select | 3.3V | No Hi-Z
D10 | 1 | TX0 | - | Not usable during Serial transmission
D4 | 2 | Boot mode select TX1 | 3.3V (boot only) | Dont connect to ground at boot time Sends debug data at boot time
D9 | 3 | RX0 | - | Not usable during Serial transmission
D2 | 4 | SDA (I²C) | - | -
D1 | 5 | SCL (I²C) | - | -
x | 6 - 8 | Flash connection | x | Not usable, and not broken out
x | 9, 10 | Flash connection * | | * Only available on the ESP8285
x | 11 | Flash connection | x | Not usable, and not broken out
D6 | 12 | MISO (SPI) | - | -
D7 | 13 | MOSI (SPI) | - | -
D5 | 14 | SCK (SPI) | - | -
D8 | 15 | SS (SPI) | 0V | Pull-up resistor not usable (extern pull down resistor)
D0 | 16 | Wake up from sleep | - | No pull-up resistor, but pull-down instead Should be connected to RST to wake up

2
FAQ.md

@ -217,7 +217,7 @@ In some cases, adding a switch to a device causes ghost switching. In this case,
This short [10 minute video by TheHookUp](https://www.youtube.com/watch?v=31IyfM1gygo&t=15s) nicely explains what it is and how to prevent it. This short [10 minute video by TheHookUp](https://www.youtube.com/watch?v=31IyfM1gygo&t=15s) nicely explains what it is and how to prevent it.
Other cause can be of electrical nature. Ff you have connected an external switch using long wires they can pick up stray signals and cause the voltage on the GPIO to vary. [Solution here](Expanding-Sonoffs#electrical-considerations) Other cause can be of electrical nature. Ff you have connected an external switch using long wires they can pick up stray signals and cause the voltage on the GPIO to vary. [Solution here](Expanding-Tasmota#electrical-considerations)
### Device resets to defaults every minute or so ### Device resets to defaults every minute or so
Your device may be in a boot loop - a restart caused by any exception or watchdog timer within less than `BOOT_LOOP_TIME` (_default 10 seconds_). The number of boot loops allowed before beginning to reset settings is determined by [`SetOption36`](Commands#setoption36). When Tasmota reaches this situation, it will begin restoring default settings as follows: Your device may be in a boot loop - a restart caused by any exception or watchdog timer within less than `BOOT_LOOP_TIME` (_default 10 seconds_). The number of boot loops allowed before beginning to reset settings is determined by [`SetOption36`](Commands#setoption36). When Tasmota reaches this situation, it will begin restoring default settings as follows:

44
PIR-Motion-Sensors.md Normal file

@ -0,0 +1,44 @@
PIR motion sensors, albeit called sensors, are configured as switches in Tasmota since they basically report _motion_ (`1`) or _no motion_ (`0`) to the device.
Most PIR's are single wire and they require connecting to VCC, GND and one GPIO. In this guide we will use `GPIO15` as the pin that the PIR output is connected to.
### Tasmota Configuration
In _Configuration -> Configure Module_ menu change `GPIO15` to `Switch1`:
![Step 1](https://user-images.githubusercontent.com/5904370/67887920-7e814c80-fb4c-11e9-863d-7219894be506.png)
>If there already is a `Switch1` simply choose the next in line. This way you can even have more than 1 PIR on a single device.
A configured PIR will not appear in the web UI in any form. To make it report like a sensor we need a rule that will send movement triggers to an MQTT topic.
```
Switchmode1 1
Switchtopic 0
Rule1 on switch1#state=1 do publish stat/%topic%/PIR1 ON endon on switch1#state=0 do publish stat/%topic%/PIR1 OFF endon
Rule1 1
```
You can change the topic (`PIR1`) and the message (`ON`/`OFF`) to whatever suits your needs.
optional:
>Before using rules configure any GPIO that doesn't have anything connected to it as `Relay1`.
>This creates a dummy relay which is triggered by the PIR so you can see the changes in the web UI. This method is not recommended for daily use and should only be used for testing.
A more [advanced example](Rule-Cookbook#Auto-off-Motion-Sense-Switch) of rules with PIRs.
## AM312
[AM312](http://www.image.micros.com.pl/_dane_techniczne_auto/cz%20am312.pdf) works even on 3.3v instead of 5v (like HC-SR501) which makes it perfect for ESP8266 devices without a 5V line (like Sonoff Basic). It is also less prone to false triggers due to Wi-Fi interference.
<img src="https://user-images.githubusercontent.com/5904370/67888232-0cf5ce00-fb4d-11e9-85da-379fe70f987a.png?v=4&s=50" width=200></img>
### Pinout
![AM312 Pinout](https://user-images.githubusercontent.com/5904370/67886972-b7b8bd00-fb4a-11e9-90ea-93fd7f5ec972.png)
Pin marked VOUT is connected to a free GPIO pin on the device.
## HC-SR501
<img src="https://user-images.githubusercontent.com/5904370/67890781-a32bf300-fb51-11e9-8f84-1413fccc4e78.png" width=200>
### Pinout
<img src="https://user-images.githubusercontent.com/5904370/67890814-b212a580-fb51-11e9-9e7e-35ff669b4d7b.png" width=300>

85
Peripherals.md Normal file

@ -0,0 +1,85 @@
You can connect peripherals (sensors, displays, switches, LED lights, ...) to available pins of the device. [Read here](Expanding-Tasmota) for a more technical explanation.
### Sensors
More about [sensor configuration.](https://github.com/arendst/Sonoff-Tasmota/wiki/Sensor-Configuration)
*Some of the articles were written originally for D1 mini but the information still applies except the wiring instructions*
- **ADS1x15** A/D Converter (I<sup>2</sup>C)
- [**AM312**](PIR-Motions-Sensors#AM312) PIR Motion Sensor
- [**APDS-9960**](APDS-9960) Ambient Light, RGB Color and Proximity Sensor with Gesture Detection
- [**AZ-7798**](Wemos-D1-Mini-and-AZ-Instrument-7798-CO2-Meter-Datalogger) CO<sub>2</sub> Meter Datalogger
- [**BH1750**](Wemos-D1-Mini-and-BH1750-Luminosity-Sensor) Luminosity Sensor
- [**BME280 (BMP085, BMP180, BMP280, BME280)**](Wemos-D1-Mini-and-BME280-Temperature,-Humidity-and-Pressure-Sensor) Temperature, Humidity and Pressure Sensor
- [Sonoff Basic Wiring](BME280-Temperature,-Humidity-and-Pressure-Sensor-and-Sonoff-Basic-with-Tasmota)
- [**BME680**](Wemos-D1-Mini-and-BME680-Temperature,-Humidity,-Pressure-and-Gas-Sensor) Temperature, Humidity, Pressure and Gas Sensor
- [**CC2530**](Zigbee) Zigbee Adapter (Serial)
- **CCS811** Gas and Air Quality sensor (I<sup>2</sup>C)
- [**DHT11**](Wemos-D1-Mini-and-DHT11-Shield-Humidity-&-Temperature) Humidity & Temperature Sensor
- [Sonoff Basic wiring](DHT11-Wiring---Sonoff-Basic)
- [**DHT22 (DHT21, AM2301, AM2302, AM2321)**](Wemos-D1-Mini-and-DHT22-(DHT21,-AM2301,-AM2302,-AM2321)-Shield-Humidity-&-Temperature) Humidity & Temperature Sensor<img src="https://user-images.githubusercontent.com/5904370/53279561-cfb18480-3711-11e9-9889-76ab1d6eafcb.png" width="250" align="right" />
- **DS18x20** Temperature sensor (GPIO)
- [**DS3231**](DS3231---External-RTC) Real-Time-Clock (I<sup>2</sup>C)
- [**HM16/HM17**](iBeacon-driver) Bluetooth iBeacon reader (Serial)
- **HR-E** Water Meter Encoder interface (Serial)
- [**HC-SR04 (SR04+, SR04T)**](Wemos-D1-Mini-and-HC-SR04-Ultrasonic-Sensor) Ultrasonic Sensor
- [**HC-SR501**](PIR-Motions-Sensors#HC-SR501) PIR Motion Sensor<img src="https://user-images.githubusercontent.com/5904370/53279530-8c571600-3711-11e9-85c0-27d35be2df48.png" width="250" align="right" />
- **HTU21** Temperature and Humidity sensor (I<sup>2</sup>C)
- **HX711** Load Cell sensor (GPIO)
- **INA219** High-Side DC Current and Voltage sensor (I<sup>2</sup>C)
- [**IR Remote Control**](https://github.com/altelch/SonoffIR) DIY
- **K30, K70, S8** CO<sub>2</sub> sensor (I<sup>2</sup>C)
- [**LM75AD**](LM75AD) Temperature Sensor (I<sup>2</sup>C)
- **MAX31855** Thermocouple Sensor (SPI)
- **MAX31865** RTD Temperature Sensor Amplifier (SPI)
- **MAX44009** Ambient Light Sensor (I<sup>2</sup>C)
- [**MCP23008 / MCP23017**](MCP23008-MCP23017) I/O Expander (I<sup>2</sup>C)
- [**MGC3130**](MGC3130) 3D Tracking and Gesture Controller
- [**MH-Z19B**](MH-Z19B) CO<sub>2</sub> Sensor<img src="https://user-images.githubusercontent.com/5904370/53279635-54040780-3712-11e9-8c83-970280003b6d.png" width="250" align="right" />
- **MLX90614** MLX IR Temperature sensor (I<sup>2</sup>C)
- [**MPR121**](MPR121) Proximity Capacitive Touch Sensor Controller (I<sup>2</sup>C)
- **MPU6050** 3-Axis Gyroscope and 3-Axis Accelerometer sensor (I<sup>2</sup>C)
- [**P1 Energy Meter**](https://github.com/arendst/Sonoff-Tasmota/wiki/Wemos-D1-Mini-and-P1-Energy-Meter)
- [**PAJ7620**](PAJ7620) Gesture & Proximity Detection Sensor
- [**PCA9685**](PCA9685) 16-channel, 12-bit PWM LED controller (I<sup>2</sup>C)
- **PCF8574** 8-port I\/O Expander (I<sup>2</sup>C)
- **PMS3003-5003-7003** Particle Concentration sensor (Serial)
- [**PN532**](PN532) NFC/RFID controller
- [**PZEM-0XX**](PZEM-Energy-Monitoring-Custom-Devices) Energy Monitor (Serial)<img src="https://user-images.githubusercontent.com/5904370/53279642-7433c680-3712-11e9-9aa2-7fd1adce3def.png" width="250" align="right" />
- [**RCWL 0516**](Wemos-D1-Mini-and-RCWL-0516-Microwave-Radar-Sensor) Microwave Radar Presence detection
- [**RDM6300**](Wemos-D1-Mini-and-RDM6300) 125Khz RFID Module
- **RX-4M50RR30SF / RX-AM8SF** RF Sensor receiver (GPIO)
- **SCD30** CO<sub>2</sub> sensor (I<sup>2</sup>C)
- **SDM120** Modbus Energy Meter (Serial)
- **SDM630** Modbus Energy Meter (Serial)
- [**SDS011 (SDS021)**](Wemos-D1-Mini-and-Nova-Fitness-SDS011-Laser-Dust-Sensor) Laser Dust Sensor
- **SGP30** Gas and Air Quality sensor (I<sup>2</sup>C)
- **SHT1x** Temperature and Humidity sensor (I<sup>2</sup>C)
- [**SHT30**](Wemos-D1-Mini-and-SHT30-Shield-High-Precision-Humidity-&-Temperature) Humidity & Temperature Sensor
- **SI114x** UV Index, IR and Visible Light sensor (I<sup>2</sup>C)
- [**Smart Meter Interface**](smart-meter-interface) (Serial)
- [**Soil Moisture Sensor**](Moisture-Sensor-and-Chirp!-Sensor) (I<sup>2</sup>C)
- **SolaX X1** SolaX X1 inverter (Serial)
- **SPS30** Particulate Matter (PM) sensor (I<sup>2</sup>C)
- [**Stepper Motor Controller**](A4988-Stepper-Motor-Controller)
- **TM1638** 8 Switch, LED and 7 Segment Unit sensor (GPIO)
- [**TSL2561**](Wemos-D1-Mini-and-TSL2561-Luminosity-Sensor) Luminosity Sensor
- **TX20** La Crosse Wind (Anemometer) sensor (GPIO)
- [**VEML6070**](Wemos-D1-Mini-and-VEML6070-UV-Sensor) UV Sensor
- **VL53L0x** Time of flight sensor (I<sup>2</sup>C)
- [**WS2812B**](Wemos-D1-Mini-and-WS2812B-RGB-Shield) RGB Shield
- [**WS2812B/WS2813B**](Wemos-D1-Mini-and-WS2812B---WS2813B-Ledstrip) LED Strip
- **Xadow, Grove** Multi-channel Gas sensor (I<sup>2</sup>C)
[Complete list of supported sensors](https://docs.google.com/spreadsheets/d/e/2PACX-1vRBFqaP5QAFmT8iIYBxrn-EQp7-SrkxL6tb0OjpqtBxDEsmkiWCFei3sFyA_UXoqlbs3CqtEdOfC6Pa/pubhtml?gid=1029939700&single=true)
[Sensor API Documentation](Sensor-API)
## Expanding specific devices
- [LEGO nightstand switch using Sonoff SV](https://jeff.noxon.cc/2018/11/21/lego-nightstand-light-switch/)
- [Add a physical button to Sonoff Basic](https://translate.google.com/translate?hl=en&sl=auto&tl=en&u=https%3A%2F%2Fwww.domo-blog.fr%2Fajouter-un-bouton-physique-au-sonoff-basic%2F)
- [Remote button for Sonoff](Control-a-Sonoff-using-a-remote-button)
- [Expand Sonoff S20 with a jack plug](https://github.com/arendst/Sonoff-Tasmota/issues/670)
- [Expand Sonoff 4CH with a jack plug](Expanding-4CH)
- [Modify KaKu to WKaKu Power Socket](Modify-KaKu-to-WKaKu-Power-Socket)
- [GPIO Locations](GPIO-Locations)

@ -19,7 +19,7 @@
- [Make sure light is on at night](#make-sure-light-is-on-at-night) - [Make sure light is on at night](#make-sure-light-is-on-at-night)
- [Turn On Light Before Dawn and At Dusk](#Turn-On-Light-Before-Dawn-and-At-Dusk) - [Turn On Light Before Dawn and At Dusk](#Turn-On-Light-Before-Dawn-and-At-Dusk)
- [Enable a PIR Switch only at night](#enable-a-pir-switch-only-at-night) - [Enable a PIR Switch only at night](#enable-a-pir-switch-only-at-night)
- [PIR Configuration](Wemos-D1-Mini-and-HC-SR501-PIR-Motion-Sensor#alternative-tasmota-configuration-with-rules-recommended-method) - [PIR Configuration](PIR-Motions-Sensors#HC-SR501#alternative-tasmota-configuration-with-rules-recommended-method)
- [Using clock timer to control a luminance-triggered switch only in mornings](#using-clock-timer-to-control-a-luminance-triggered-switch-only-in-mornings) - [Using clock timer to control a luminance-triggered switch only in mornings](#using-clock-timer-to-control-a-luminance-triggered-switch-only-in-mornings)
- [Button with single press, double press, and hold](#button-with-single-press-double-press-and-hold) - [Button with single press, double press, and hold](#button-with-single-press-double-press-and-hold)
- [Perform any action on single/double press (for switches AND buttons)](#perform-any-action-on-singledouble-press-for-switches-and-buttons) - [Perform any action on single/double press (for switches AND buttons)](#perform-any-action-on-singledouble-press-for-switches-and-buttons)

@ -1,6 +1,6 @@
Pre-work: Pre-work:
* [Device Configuration](https://github.com/arendst/Sonoff-Tasmota/wiki/Initial-Configuration) * [Device Configuration](https://github.com/arendst/Sonoff-Tasmota/wiki/Initial-Configuration)
* [How To Connect a Sensor](https://github.com/arendst/Sonoff-Tasmota/wiki/Expanding-Sonoffs) * [How To Connect a Sensor](https://github.com/arendst/Sonoff-Tasmota/wiki/Expanding-Tasmota)
The software allows for easy configuration of sensors and devices to selected GPIO pins. Depending on the type of Template/Module, certain GPIO pins are user configurable. Sensor configuration is possible by either the WebUI or using the commands [`Template`](Commands#template), [`Module`](Commands#module) or [`GPIO`](Commands#gpio). The software allows for easy configuration of sensors and devices to selected GPIO pins. Depending on the type of Template/Module, certain GPIO pins are user configurable. Sensor configuration is possible by either the WebUI or using the commands [`Template`](Commands#template), [`Module`](Commands#module) or [`GPIO`](Commands#gpio).

@ -59,6 +59,6 @@ Most ESP82xx based devices are able to run Tasmota. The devices listed below com
- [**Wemos D1 Mini**](Wemos-D1-Mini) - [**Wemos D1 Mini**](Wemos-D1-Mini)
- [**Flashing**](Wemos-D1-Mini#flashing-wemos-with-tasmota) - [**Flashing**](Wemos-D1-Mini#flashing-wemos-with-tasmota)
- [**Configuration**](Wemos-D1-Mini#generic-module) - [**Configuration**](Wemos-D1-Mini#generic-module)
- [**Usable Pins**](Expanding-Sonoffs#usable-pins) - [**Usable Pins**](Expanding-Tasmota#usable-pins)
See "[Other Devices](Other-Devices)" for a list of flashing guides for other miscellaneous ESP82xx devices. See "[Other Devices](Other-Devices)" for a list of flashing guides for other miscellaneous ESP82xx devices.

@ -1,7 +1,7 @@
### [List of supported sensors](https://docs.google.com/spreadsheets/d/e/2PACX-1vRBFqaP5QAFmT8iIYBxrn-EQp7-SrkxL6tb0OjpqtBxDEsmkiWCFei3sFyA_UXoqlbs3CqtEdOfC6Pa/pubhtml?gid=1029939700&single=true) ### [List of supported sensors](https://docs.google.com/spreadsheets/d/e/2PACX-1vRBFqaP5QAFmT8iIYBxrn-EQp7-SrkxL6tb0OjpqtBxDEsmkiWCFei3sFyA_UXoqlbs3CqtEdOfC6Pa/pubhtml?gid=1029939700&single=true)
- **ADS1x15** A/D Converter (I<sup>2</sup>C) - **ADS1x15** A/D Converter (I<sup>2</sup>C)
- [**AM312**](Wemos-D1-Mini-and-AM312-PIR-Motion-Sensor) PIR Motion Sensor - [**AM312**](PIR-Motions-Sensors#AM312) PIR Motion Sensor
- [**APDS-9960**](APDS-9960) Ambient Light, RGB Color and Proximity Sensor with Gesture Detection - [**APDS-9960**](APDS-9960) Ambient Light, RGB Color and Proximity Sensor with Gesture Detection
- [**AZ-7798**](Wemos-D1-Mini-and-AZ-Instrument-7798-CO2-Meter-Datalogger) CO<sub>2</sub> Meter Datalogger - [**AZ-7798**](Wemos-D1-Mini-and-AZ-Instrument-7798-CO2-Meter-Datalogger) CO<sub>2</sub> Meter Datalogger
- [**BH1750**](Wemos-D1-Mini-and-BH1750-Luminosity-Sensor) Luminosity Sensor - [**BH1750**](Wemos-D1-Mini-and-BH1750-Luminosity-Sensor) Luminosity Sensor
@ -18,7 +18,7 @@
- [**HM16/HM17**](iBeacon-driver) Bluetooth iBeacon reader (Serial) - [**HM16/HM17**](iBeacon-driver) Bluetooth iBeacon reader (Serial)
- **HR-E** Water Meter Encoder interface (Serial) - **HR-E** Water Meter Encoder interface (Serial)
- [**HC-SR04 (SR04+, SR04T)**](Wemos-D1-Mini-and-HC-SR04-Ultrasonic-Sensor) Ultrasonic Sensor - [**HC-SR04 (SR04+, SR04T)**](Wemos-D1-Mini-and-HC-SR04-Ultrasonic-Sensor) Ultrasonic Sensor
- [**HC-SR501**](Wemos-D1-Mini-and-HC-SR501-PIR-Motion-Sensor) PIR Motion Sensor<img src="https://user-images.githubusercontent.com/5904370/53279530-8c571600-3711-11e9-85c0-27d35be2df48.png" width="250" align="right" /> - [**HC-SR501**](PIR-Motions-Sensors#HC-SR501) PIR Motion Sensor<img src="https://user-images.githubusercontent.com/5904370/53279530-8c571600-3711-11e9-85c0-27d35be2df48.png" width="250" align="right" />
- **HTU21** Temperature and Humidity sensor (I<sup>2</sup>C) - **HTU21** Temperature and Humidity sensor (I<sup>2</sup>C)
- **HX711** Load Cell sensor (GPIO) - **HX711** Load Cell sensor (GPIO)
- **INA219** High-Side DC Current and Voltage sensor (I<sup>2</sup>C) - **INA219** High-Side DC Current and Voltage sensor (I<sup>2</sup>C)
@ -69,8 +69,8 @@
## Expanding your devices ## Expanding your devices
*(written originally for D1 mini but the majority of the information applies to other peripherals)* *(written originally for D1 mini but the majority of the information applies to other peripherals)*
- [Sensor Configuration](https://github.com/arendst/Sonoff-Tasmota/wiki/Sensor-Configuration) - [Sensor Configuration](https://github.com/arendst/Sonoff-Tasmota/wiki/Sensor-Configuration)
- [Wiring additional things to a module](Expanding-Sonoffs)<img src="https://user-images.githubusercontent.com/5904370/53279684-f8864980-3712-11e9-9451-da6259bae2ea.png" width="250" align="right" /> - [Wiring additional things to a module](Expanding-Tasmota)<img src="https://user-images.githubusercontent.com/5904370/53279684-f8864980-3712-11e9-9451-da6259bae2ea.png" width="250" align="right" />
- [Connecting a Switch](Expanding-Sonoffs#connect-switch) - [Connecting a Switch](Expanding-Tasmota#connect-switch)
- [LEGO nightstand switch using Sonoff SV](https://jeff.noxon.cc/2018/11/21/lego-nightstand-light-switch/) - [LEGO nightstand switch using Sonoff SV](https://jeff.noxon.cc/2018/11/21/lego-nightstand-light-switch/)
- [Add a physical button to Sonoff Basic](https://translate.google.com/translate?hl=en&sl=auto&tl=en&u=https%3A%2F%2Fwww.domo-blog.fr%2Fajouter-un-bouton-physique-au-sonoff-basic%2F) - [Add a physical button to Sonoff Basic](https://translate.google.com/translate?hl=en&sl=auto&tl=en&u=https%3A%2F%2Fwww.domo-blog.fr%2Fajouter-un-bouton-physique-au-sonoff-basic%2F)
- [Push Button Wiring and Control](Control-a-Sonoff-using-a-remote-button) - [Push Button Wiring and Control](Control-a-Sonoff-using-a-remote-button)
@ -79,5 +79,5 @@
- [Modify KaKu to WKaKu Power Socket](Modify-KaKu-to-WKaKu-Power-Socket) - [Modify KaKu to WKaKu Power Socket](Modify-KaKu-to-WKaKu-Power-Socket)
- [Defining new module types](Adding-new-Module-types) - [Defining new module types](Adding-new-Module-types)
- [GPIO Locations](GPIO-Locations) - [GPIO Locations](GPIO-Locations)
- [Usable Pins](Expanding-Sonoffs#usable-pins) - [Usable Pins](Expanding-Tasmota#usable-pins)
- [Sensor API Documentation](Sensor-API) - [Sensor API Documentation](Sensor-API)

@ -1,29 +1 @@
## AM312 PIR Motion Sensor (single pin) [Moved](PIR-Motion-Sensors#AM312)
PIR sensors allow you to sense motion, almost always used to detect whether a human has moved in or out of the sensors range.
> Learn more about [PIR Motion Sensors](https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/overview).
The [AM312](https://www.aliexpress.com/item/GREATZT-Mini-IR-Pyroelectric-Infrared-PIR-Motion-Human-Sensor-Automatic-Detector-Module-AM312-Sensor-DC-2/32924338791.html) is pretty much the same as HC-SR505 but works on 3.3v instead of 5v.
<img src="https://github.com/arendst/arendst.github.io/blob/master/media/wemos/pir-am312-motion-front.png" width=300>
### Connecting the PIR to a Wemos Mini D1
| Wemos |PIR |
|---|---|
|GND |GND |
|3.3V |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**
<img src="https://github.com/arendst/arendst.github.io/blob/master/media/wemos/wemos_pir_hc-sr501_config_marked.png" width=350>
### Tasmota Main
After reboot of the device the displays the status of relay1 aka switch1.
<img src="https://github.com/arendst/arendst.github.io/blob/master/media/wemos/wemos_pir_hc-sr501_main_marked.png" width=350>

@ -1,50 +1 @@
## HC-SR501 PIR Motion Sensor (single pin) [Moved](PIR-Motion-Sensors#HC-SR501)
<img src="https://github.com/arendst/arendst.github.io/blob/master/media/wemos/pir-hc-sr501-motion-front.jpg" align=right width=200>
<img src="https://github.com/arendst/arendst.github.io/blob/master/media/wemos/pir-hc-sr501-motion-back.jpg" align=right width=300>
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](https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/overview) 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**
<img src="https://github.com/arendst/arendst.github.io/blob/master/media/wemos/wemos_pir_hc-sr501_config_marked.png" width=350>
### Tasmota Main
After reboot of the device the displays the status of relay1 aka switch1.
<img src="https://github.com/arendst/arendst.github.io/blob/master/media/wemos/wemos_pir_hc-sr501_main_marked.png" width=350>
### 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

@ -16,9 +16,9 @@
[**Scripting**](Scripting-Language) [**Scripting**](Scripting-Language)
[**Timers**](Timers) [**Timers**](Timers)
[**Buttons & Switches**](Buttons-and-Switches) [**Buttons & Switches**](Buttons-and-Switches)
[**Sensors & Controllers**](Supported-Sensors) [**Peripherals**](Peripherals)
[**Status LEDs**](Status-LED)
[**Lights**](Lights) [**Lights**](Lights)
[**Status LEDs**](Status-LED)
[**TuyaMCU**](TuyaMCU) [**TuyaMCU**](TuyaMCU)
[**Displays**](Displays) [**Displays**](Displays)
[**Blinds & Shutters**](blinds-and-roller-shades) [**Blinds & Shutters**](blinds-and-roller-shades)