Openhab / Sonoff SV / GPIO14 Switch - reading MQTT cmnd

Hi all,
I’m trying to setup a Sonoff SV to open/close a garage door with the relay and use GPIO14 with a reed switch to sense door state (tasmota 6.5)

I’ve successfully bound an item to the relay and can switch it on/off from OpenHab.
I configured GPIO14 to Switch2. The Tasmota logs as follows when the reed switch open / closes - like this:

17:14:36 MQT: cmnd/garage/POWER2 = ON
17:14:36 MQT: stat/garage/RESULT = {"Command":"Unknown"}
17:14:39 MQT: cmnd/garage/POWER2 = OFF
17:14:39 MQT: stat/garage/RESULT = {"Command":"Unknown"}

The stat doesn’t contain any metadata on switch door status, but the cmnd does.
I thought I would configure openHab to get it’s status from the cmnd like this

Bridge mqtt:broker:PiMqttBroker [ host="", secure=false, username="openhabian", password="notmypassword"] {
    Thing topic garage "Garage" @ "Sonoff" { 
      Type switch : PowerSwitch "Button" [ stateTopic="stat/garage/POWER" , commandTopic="cmnd/garage/POWER", on="ON", off="OFF"]
      Type switch : Sensor "Sensor"      [ stateTopic="cmnd/garage/POWER2", on="ON", off="OFF"]


The problem is OpenHab doesn’t ‘read’ anything when the cmnd is broadcast.

Is this a limitation of OpenHab/MQTT - you can’t use a cmnd to read a state?
The alternative is to wait for a tele - the switch2 status is broadcast correctly

16:55:27 MQT: tele/garage/SENSOR = {"Time":"2019-06-15T16:55:27","Switch2":"OFF"}

but that is a polling mechanism and I was hoping it to be event driven.
An alternative is I have misconfigured Tasmota… I’m not sure.

Any suggestions?

cmnd is command, stat is state, tele is frequent information, this is Tasmota standard.
You can’t read from cmnd but only from stat. Of course you could use cmnd/garage/POWER2 without any payload to force a stat update, but openHAB does not support mqtt without payload (or it’s even more complex…)

Tasmota should send a state update whenever the reed switch changes its state, so the mqtt broker should immediately publish this state via stat/garage/POWER2 (not RESULT, this is for commands only).

1 Like

So have been thinking on this. Why can’t I read from a cmnd? I understand the differences between the intent of the two - but as far as I can tell cmnd, stat and tele are only tasmota standards - not anything specific to MQTT.

I can subscribe MQTTBox to the cmnd and it reads the topic fine. What is it about the cmnd message that makes it impossible for OpenHab to subscribe to it as a state topic? As far as I can tell HomeAssistant allows this - see configuration below the text

No right or wrong way IF IT WORKS.

in this blog

Do you mean, can I set a channel stateTopic as well as a commandTopic? Yes.

No, I meant having a thing defined like this - the state comes from a tasmota cmnd topic

Type contact : Sensor "Sensor" [ stateTopic="cmnd/garage/POWER2" , on="ON", off="OFF"]

I did get it to work - seems mqtt things are fickle and need openhab restarts to get them to work sometimes.

It turns out this isn’t going to work well though because the cmnd only gets broadcast on state change - when openhab starts up the state is NULL and it won’t update until the door physically changes state.

Thanks all.

Well, yes. Listening to the cmnd topic tells you what instructions are being directed to the Sonoff. In most cases, openHAB would get an echo of its own commands back from the broker.
There might be uses for that if you needed to track what other systems are directing the Sonoff to do.
It won’t tell you if the Sonoff is alive or dead or has actually carried out the directive.

Yes, no cmnds have been sent out by openHAB yet.