Connect Sonoff Switches to OpenHAB through MQTT

There’s a detailed tutorial using the new mqtt binding Sonoff Tasmota with MQTT Binding 2.4 (using config files)
Have a search through the forums - you should find other similar tutorials. I’d encourage you to do that. Openhab does have bit of a steep learning curve (well it did for me…) but there’s plenty help out there and quite a few pointers for you to make progress.

Here’s a quick pointer to what I have set up, which may be of some help:
Firstly, you’d need to check that the sonoff is connecting to mqtt OK. I’m assuming that you’ve got that working OK and that you can see the sonoff reporting its status ok via mqtt? On my pi I’d use a command like

mosquitto_sub -h -v -t #

which would show all often messages published to mosquito - replace the # with the specific topic if you wish.
I’ve still not updated my system to the mqtt v2 binding - I’m still using v1. So in my case, in the .items file ($CONF/items/.items) I have lines like the following:

Switch SF_S61 “SF S20-61 [%s]” (gSf,gSfSocket) {mqtt=">[mqtt:cmnd/sonoff/S20-61/power:command:*:default],
<[mqtt:stat/sonoff/S20-61/POWER:state:default],
<[mqtt:tele/sonoff/S20-61/STATE:state:JSONPATH($.POWER)],
<[mqtt:stat/sonoff/S20-61/RESULT:state:JSONPATH($.POWER)]"}

this sends the ON/OFF command to the switch via mqtt, and also updates the switch value if the switch is changed elsewhere (e.g. via the intranet page).

Hope that gives you some pointers.

1 Like