mirror of https://github.com/arendst/Tasmota.git
Updated Understanding SwitchMode and SwitchTopic (markdown)
parent
471d7dae15
commit
6cfdab27d2
|
@ -1,10 +1,24 @@
|
|||
The standard Sonoff device has a relay to turn on/off an external device and a button to toggle the state of the relay. Additionally a "Switch" can be configured using the [[Gpio Command|Commands#management]]. (See [[GPIO-Locations]] for how to connect to these GPIO's.)
|
||||
# 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.
|
||||
|
||||
[Tasmota SwitchMode Explained Video](https://www.youtube.com/watch?v=kiXAGkyqFeU) by Dr Zzs
|
||||
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.)
|
||||
|
||||
SwitchMode and SwitchTopic are for Switchs only. Not for Buttons!
|
||||
# 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)
|
||||
- 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
|
||||
- Suitable for [mechanical push-button] https://en.wikipedia.org/wiki/Push-button, [touch button](https://en.wikipedia.org/wiki/Touch_switch) and [mechanical toggle switch](https://en.wikipedia.org/wiki/Switch#Toggle_switch)
|
||||
|
||||
By default the configuration for the button looks like this:
|
||||
# Button configuration
|
||||
< under construction >
|
||||
|
||||
# Switch configuration
|
||||
Video tutorial: [Tasmota SwitchMode Explained Video](https://www.youtube.com/watch?v=kiXAGkyqFeU) by Dr Zzs
|
||||
|
||||
By default the configuration for a "switch" is like this:
|
||||
|
||||
```
|
||||
SwitchMode=0 (Set switch mode to TOGGLE)
|
||||
|
@ -22,11 +36,11 @@ 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
|
||||
|
||||
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 and 2
|
||||
|
||||
**SwitchMode 1**
|
||||
|
||||
|
@ -41,12 +55,12 @@ While pressing the button/switch (closing the circuit) the button will send `ON`
|
|||
|
||||
The opposite of Mode 1.
|
||||
|
||||
### Conclusion
|
||||
#### Conclusion
|
||||
|
||||
You properly want to use `SwitchMode=1` when connecting a [toggle switch](https://en.wikipedia.org/wiki/Switch#Toggle_switch) to your Sonoff device. This way the 'software switch' will have the same state as the 'hardware switch'.
|
||||
If the real switch is in the "on" position, the state of the software switch is `ON` as well.
|
||||
|
||||
## SwitchMode 3 and 4
|
||||
### SwitchMode 3 and 4
|
||||
|
||||
**SwitchMode 3**
|
||||
|
||||
|
@ -61,21 +75,21 @@ The switch will send a command (directly or via MQTT) when the switch opens the
|
|||
The switch will send a command when changing to `ON`. Nothing happens when changing to `OFF`.
|
||||
|
||||
|
||||
### Conclusion
|
||||
#### 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`.
|
||||
`SwitchMode=4` is the same as the default behavior (`SwitchMode=0`) for Sonoff devices.
|
||||
|
||||
# SwitchTopic
|
||||
## 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
|
||||
|
||||
|
@ -85,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)
|
||||
|
||||
|
@ -93,7 +107,7 @@ This will send a MQTT message with a user-defined topic.
|
|||
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
|
||||
### Use case
|
||||
To trigger something within your smart home setup (e.g. [openHAB]) you can define the SwitchTopic to `sonoff01-switch1` (for example).
|
||||
|
||||
This will send a message like this: `cmnd/sonoff01-switch1/POWER ON`
|
||||
|
@ -104,7 +118,7 @@ In openHAB you define an item that subscribes to this topic and sets its state a
|
|||
Switch Sonoff01_Switch1 "Sonoff01 Switch1 [%s]" <switch> { mqtt="<[mosquitto:cmnd/sonoff01-switch1/POWER1:state:default]" }
|
||||
```
|
||||
|
||||
## Conclusion
|
||||
### Conclusion
|
||||
|
||||
`SwitchTopic=0` controls the relay directly.
|
||||
`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.
|
Loading…
Reference in New Issue