SOLVED: Sonoff 10A, MQTT and openHAB

In case of the Sonoff itā€™s a good idea to go with the Tasmota firmware. There is a whole thread on the Sonoff+Tasmota here in the forum.

Youā€™ll also find a detailed description of how to connect modules to openHAB, with item examples and everything. Iā€™d advice to safe you the trouble and switch right now.

Regarding your problem: first there shouldnā€™t be a starting slash in an mqtt topic. Seems however to be consistent between your configs. Next issue Iā€™m seeing is that your broker is called ā€œbrokerā€ but you are trying to talk to ā€œmosquittoā€. One other problem Iā€™m seeing is, that you didnā€™t provide the login credentials in your mqtt.conf. Is the binding even connected?
Did you read the binding Readme carefully?

1 Like

Thanks for your Answer Thom! - its a lot to learn for me atm with openhab, i tried the whole day to get this thing to work :confused:

i dont know if the binding is connected - where can i check this ?
i also dont believe that i have read the same ā€œreadmeā€ that you are speaking about - could you pls share a link to it ?
this one ? http://docs.openhab.org/addons/bindings/mqtt1/readme.html

i tried to understand this, but its sometimes hard to follow, when you have never done this before :confused:
so how do i connect/check the mqtt-binding ?

thank you

ESP Easy is connected to the broker
14

Okay getting started is sometimes hard but the steps are actually straight forward. Letā€™s seeā€¦

  1. Install and set up a broker. Youā€™ve used the one provided through openHABian, perfect
  2. Connect with a desktop client to the broker to see whatā€™s going on. Seems like you are already doing so, perfect. (mqtt-spy is a better choice but mqtt.fx is okay)
  3. Now get the openHAB binding connected (then tested)
  • Install the binding through Paper UI

  • Configure it via $OPENHAB_CONF/services/mqtt.conf (youā€™ve already done that but I believe youā€™ve missed the auth credentials? Should look similar to:

    broker.url=tcp://localhost:1883
    broker.user=openhabian
    broker.pwd=abcdefg
    
  • Check the log to see if the broker connects successfully: http://openhabdevice-ip:9001
    You should be seeing something like

    2017-07-22 17:15:24.084 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed. 
    2017-07-22 17:15:24.089 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
    

Okay tell me when you are ready.

1 Like

I am ready :slight_smile: - thanks!!!

really looking forward to the solution of this problem of yours as i am facing the same problem. let me know

Well congrats :tada:

Now define a very simple testing item:

Switch MQTT_Test "Testing..." { mqtt="<[broker:testing/mqtt/topic:state:default]" }

With this one in place you should be able to do a first tst. Use your mqtt.fx to publish the Message ā€œONā€ to Topic ā€œtesting/mqtt/topicā€. Check the log once again!

How did we do this just now? See: http://docs.openhab.org/addons/bindings/mqtt1/readme.html#item-configuration-for-inbound-messages

If everything works as expected you can now start to define specific items for your Sonoff. Once again, donā€™t bother with Espeasy. Go Tasmota:

1 Like

MQTT-Test works!

2017-09-05 21:44:11.170 [ItemStateChangedEvent     ] - MQTT_Test changed from OFF to ON

There you go :wink: That should be it. Let me know when further issues arise. Good luck!

i still cant control my sonoff :smiley: thats my big issue :wink:

thats my MQTT Setting on the SONOFF
58

Thats the CONTROLLER-PUBLISH Field:

/%sysname%/%tskname%/%valname%

EDIT

I published on MQTT.fx
PUBLISH: ā€œ/Sonoff_1/GPIO/12ā€
MESSAGE: ā€œ0ā€
20

i can see the change on the ESPEasy
06

thats a little success, am i right ?

how do i make a working home.item out of it ?
thanks THOM!! <3

Hey @RiotMode,

you were honestly not the first one to have starting trouble with the MQTT Binding in the beginning of their openHAB adventure. Iā€™ve taken what Iā€™ve written above over into a Tutorial. Could you please check if anything is missing or not clear to a newcomer?

1 Like

for sure - i will do now :wink:

I just would add (e.g MQTT.fx or something similiar )

1. Connect with the standalone client to the broker. (e.g MQTT.fx or something similiar )
6. Use the standalone MQTT client from before (e.g MQTT.fx )
Hit Send/>Publish<

Thatā€™s something you should be able to find out easily by yourself, with the links Iā€™ve posted aboveā€¦ :-/

Probably something like

Switch LivingRoom_Light "Living Room Light" <light> (LR,gLight)
    { mqtt=">[broker:/Sonoff_1/GPIO/12:command:*:default],
            <[broker:/Sonoff_1/GPIO/12:state:default]" }

The first line defines the Item with all itā€™s details, the second defined the outbound MQTT topic, the third the inbound. Because you didnā€™t show all needed details Iā€™m not sure if the topic for the latter is correct.

Honest, I canā€™t stretch it enough :smiley:

1 Like

Man, i love you <3 - thanks for your help! really appreciate it.

i changed it that way:

Switch Sonoff6 "MQTT-Test" <light> (LR,gLight)
    { mqtt=">[broker:/Sonoff_1/GPIO/12:command:ON:1],
            >[broker:/Sonoff_1/GPIO/12:command:OFF:0],
            <[broker:/Sonoff_1/GPIO/12:state:ON:1],
            <[broker:/Sonoff_1/GPIO/12:state:OFF:0]" }

03

seems to work <3

ITS WORKING :blush: :blush: :blush:

2 Likes

Wonderful! :wink:

2 Likes

got stuck here!! site says refuse to connect

Then your mqtt.cfg is wrongā€¦ Compare with the settings used in the standalone client.

# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
broker.url=tcp://192.160.0.14:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
#broker.clientId=openhabian

# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.
#<broker>.allowLongerClientIds=false

# Optional. User id to authenticate with the broker.
broker.user=openhabian

# Optional. Password to authenticate with the broker.
broker.pwd=password

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
#<broker>.qos=<qos>

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
#<broker>.retain=<retain>

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
#<broker>.async=<async>

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>

what should i compare it with?

for me, the mqtt.cfg looks fine, but i am the noob in here :wink:
now:

can you send me a screenshot of the web page that you are looking at for this log. also tell me if i can see this log using ssh

for you i think its: http://192.160.0.14:9001
for me it was the ip of the raspberry ( 192.168.1.100:9001 )