Updated Buttons and Switches (markdown)

Michael Ingraham 2019-02-24 10:54:35 -05:00
parent 895db84839
commit 380f4cc7c4
1 changed files with 17 additions and 17 deletions

@ -1,12 +1,12 @@
# Introduction
Tasmota supports connecting push-buttons and switches. In addition to the push-button available on some modules, additional push-buttons and switches can be connected to GPIO pins.
As an example, the standard Sonoff device has a relay to turn on/off an external device and a button to toggle the state of the relay. Additional "Buttons" or "Switches" can be configured using the [[Gpio Command|Commands#management]]. (See [[GPIO-Locations]] for how to connect to these GPIO's.)
As an example, the standard Sonoff device has a relay to turn on/off an external device and a button to toggle the state of the relay. Additional "Buttons" or "Switches" can be configured using the [[Gpio Command|Commands#gpio]]. (See [[GPIO-Locations]] for how to connect to these GPIO's.)
# Button or Switch
The Tasmota software distinguishes between "Button" and "Switch" in the following manner:
- Button
- Suitable for mechanical push-button (suitable for touch button when `SetOption13` is set to 1)
- Suitable for mechanical push-button (suitable for touch button when [`SetOption13`](Commands#setoption13) is set to 1)
- Supports single-click, double-click and long press actions
- Supports special action, e.g. factory reset, WIFI setup etc if the button is pressed repeatedly or held for a long time
- Switch
@ -16,7 +16,7 @@ The Tasmota software distinguishes between "Button" and "Switch" in the followin
< under construction >
# Switch configuration
Video tutorial: [Tasmota SwitchMode Explained Video](https://www.youtube.com/watch?v=kiXAGkyqFeU) by Dr Zzs
Video tutorial: [Tasmota SwitchMode Explained](https://www.youtube.com/watch?v=kiXAGkyqFeU) by Dr Zzs
By default the configuration for a "switch" is like this:
@ -36,20 +36,20 @@ The Sonoff-Tasmota firmware does not publish the state of the switch in any way!
It only send commands (directly to the corresponding relay or via MQTT to a topic).
## SwitchMode
## [SwitchMode](Commands#switchmode)
You can change the mode for a switch by executing a [command](Commands) in the web console, via HTTP, via MQTT or via serial.
### SwitchMode 1 and 2
**SwitchMode 1**
**`SwitchMode 1`**
> Set switch mode to FOLLOW (0 = Off, 1 = On)
While pressing the button/switch (closing the circuit) the button will send `ON` (directly or via MQTT depending on SwitchTopic) and `OFF` when released (open circuit).
While pressing the button/switch (closing the circuit) the button will send `ON` (directly or via MQTT depending on [SwitchTopic](Commands#switchmode)) and `OFF` when released (open circuit).
**SwitchMode 2**
**`SwitchMode 2`**
> Set switch mode to inverted FOLLOW (0 = On, 1 = Off)
@ -62,13 +62,13 @@ If the real switch is in the "on" position, the state of the software switch is
### SwitchMode 3 and 4
**SwitchMode 3**
**`SwitchMode 3`**
> Set switch mode to PUSHBUTTON (Normally 1, 0 = toggle)
The switch will send a command (directly or via MQTT) when the switch opens the circuit (`OFF`). When closing the circuit (`ON`), nothing will happen.
**SwitchMode 4**
**`SwitchMode 4`**
> Set switch mode to inverted PUSHBUTTON (Normally 0, 1 = toggle)
@ -77,19 +77,19 @@ The switch will send a command when changing to `ON`. Nothing happens when chang
#### Conclusion
When connecting a [momentary switch](https://en.wikipedia.org/wiki/Switch#Biased_switches) (a push button) you want to use `SwitchMode=3` or `4`.
When connecting a [momentary switch](https://en.wikipedia.org/wiki/Switch#Biased_switches) (a push button) you want to use `SwitchMode=3` or `SwitchMode=4`.
`SwitchMode=4` is the same as the default behavior (`SwitchMode=0`) for Sonoff devices.
## SwitchTopic
## [`SwitchTopic`](Commands#switchtopic)
### SwitchTopic 0
### `SwitchTopic 0`
> Disable use of MQTT switch topic
No MQTT message will be published on account of the new switch state. The message you see in MQTT is the new state of the relay that gets changed, like explained above.
e.g.: `stat/sonoff01/POWER ON`
### SwitchTopic 1
### `SwitchTopic 1`
> Set MQTT switch topic to Topic
@ -99,7 +99,7 @@ e.g.: `cmnd/sonoff01/POWER ON` (Notice the `cmnd` instead of the `stat` at the b
This command will be received by the device itself and the relay will be set to the defined state.
Just like receiving the same command from any other MQTT source.
### SwitchTopic 2
### `SwitchTopic 2`
> Set MQTT switch topic (32 chars max)
@ -108,11 +108,11 @@ Whether this message will trigger anything depends on the setup of the user.
For example, when setting the topic to `sonoff2` this could trigger the relay on the Sonoff device that listens to messages with this specific topic.
### Use case
To trigger something within your smart home setup (e.g. [openHAB]) you can define the SwitchTopic to `sonoff01-switch1` (for example).
To trigger something within your smart home automation hub you can define the `SwitchTopic` to `sonoff01-switch1` (for example).
This will send a message like this: `cmnd/sonoff01-switch1/POWER ON`
In openHAB you define an item that subscribes to this topic and sets its state according to the message content.
In [openHAB](openhab) you define an item that subscribes to this topic and sets its state according to the message content.
```java
Switch Sonoff01_Switch1 "Sonoff01 Switch1 [%s]" <switch> { mqtt="<[mosquitto:cmnd/sonoff01-switch1/POWER1:state:default]" }
@ -124,7 +124,7 @@ Switch Sonoff01_Switch1 "Sonoff01 Switch1 [%s]" <switch> { mqtt="<[mosquitto:cmn
`SwitchTopic=1` sends a message with the default topic to MQTT. This message will get picked up by the device itself and sets the state of the relay accordingly.
While `SwitchTopic=2` sends a command with a custom topic via MQTT. This will not get picked up unless you configure any device to subscribe to this topic.
[Examples with Rules](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#16-using-an-external-button-with-single-press---double-press-and-hold)
[Examples with Rules](Rules#16-using-an-external-button-with-single-press---double-press-and-hold)
### MQTT broker not available