I have recently installed openhabian in RPi3 and I have flashed tasmota in the sonoff smart switches.
I do not know how to connect sonoff smart switches to openhab to meet my goal of turning the switch ON/OFF using openhab.
I have installed Mqtt-binding add-on. Can someone please provide a step-by-step how to connect sonoff switch to openhab using Mqtt (external MQTT broker such as HiveMQ) ?
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).
Why don’t you try reading the MQTT documentation and/or searching this forum for threads about mqtt2 and sonoff? This topic has been discussed several times.
BTW: The topic Tutorials & Examples is meant for posting such.
pretty much everything you need, adjust your setting for hivemq which I have no experience with
here is sonoff wallswitch config for your Thing file (make sure you have correct topic, mine is different from standard tasmota which has got cmnd and stat at the beginning)