How does mqtt binding read tasmota switch state?


sorry if this is a stupid one :wink:
My item binding works perfectly but I would love to understand the logic. Here an example:

sonoffswitch.items file
>[mosquitto:cmnd/SonoffS20-1/POWER:command:*:default]" }

The last part I get. Whenever the openHAB switch receives a command, it sends the switch state as payload to topic cmnd/SonoffS20-1/POWER (which is then processed by Tasmota).

But I wonder how does openHAB tell Tasmota to publish information for topic stat/SonoffS20-1/POWER? In other words, how does openHAB know about current switch state?

I noticed when sending an empty payload to the topic cmnd/SonoffS20-1/POWER, Tasmota will reply with the required stat topic. Is this what happens when openHAB initializes the binding?

Thanks in advance


Tasmota sends a stat when the statue has changed b/c the item is asking for the stat. Note the <, > direction.


Using the tele with tasmota will send the info every X minuets (adjust to suit need). An example of tele would be RSSI like this:

Number LivingRoom_Light_RSSI "Living Room Light: RSSI [%d %%]" 
{ mqtt="<[pibroker:tele/sonoff11/STATE:state:JSONPATH($.Wifi.RSSI)]" }

Thanks. Does this mean that openHAB doesn’t know anything about the real status as long as Tasmota hasn’t provided any information? Tasmota will only provide the information via stat topic if either someone presses the physical switch button or uses the openHAB switch item.

Btw: I double checked the tele information. Thanks for the hint.

The OH2 Item will subscribe to the MQTT topic and get the status message from the Broker (where the Sonoff publishes). The Broker keeps (retains) the (current) message and provides it to the subscribers.

OH2 will not “poll” the Sonoff. Since you have a Broker in the middle, all comms are via the Broker (no direct exchange of info between OH2 & Sonoff).

Well… of course yes… how else would OH2 know the status?

thanks, understood. now it makes sense.