SOLVED: Sonoff 10A, MQTT and openHAB

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 )

okay!!
i found some problems with my cfg file. like my if is 192.168.0.14 and not 192.160.0.14. i fixed it
now it looks something like this

#
# 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.168.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

also please send a screenshot of your current working mqtt.cfg file

check your LOG! and REBOOT the device!

i tried to write i little tutorial for myself, so its partly in german, but maybe you can use it too :wink:
OpenHAB - Sonoff10A - Installation.pdf (847.3 KB)

Did you read my posting about the Tutorial? You’ll find all details, including how to view the log via SSH there:

Btw. viewing the log is a very fundamental thing when using openHAB. If you do not know how to do so, you should spend a few minutes in the documentation to learn about the basics of openHAB! http://docs.openhab.org

Good luck!

Heyho,

one little thing is not like it should - the SWITCH is sometimes on OFF - but the lamp is ON
The STATE is always correct ( Switch is on OFF, but STATE is on “1” )
Thats how i know about the Status of the Lamp.

How to make this work correctly ? - Any Ideas ?

THANKS

@ThomDietrich I really don’t know what you will do with all your free time, when we made the MQTT experience hassle free and self explaining at some point :smiley:

Cheers, David

2 Likes

Hehe @David_Graeff I’m having high hopes for the MQTT binding :wink:

@RiotMode you lost me. Why are there two Items, how are they configured?

Hey Thom, this is my .item:

Switch Sonoff_1 "Stehlampe Büro" <light> [ "Lighting" ]
    { 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]" }

Number Sonoff_1_uptime    "Sonoff-Uptime [%.0f Minuten]"        <clock>           {mqtt="<[broker:/Sonoff_1/uptime/Minutes:state:default]"}
Number Sonoff_1_wifi      "WiFi-Signalstärke [%.2f dB]"         <network>         {mqtt="<[broker:/Sonoff_1/WI-FI/:state:default]"}
Number Sonoff_1_state     "Sonoff-Status [MAP(de.map):%s]"      <wallswitch-on>   {mqtt="<[broker:/Sonoff_1/lightState/Switch:state:default]"}

The Sonoff_1_STATE seems to be always correct.
The Sonoff_1 is not always correct, sometimes ,the lamp is ON, but the switch shows the lamp as OFF…

Thats a little beauty mistake i would like to solve, hope you got it now :wink:
thanks

Okay… so why not reduce it to a single item?

Switch Sonoff_1 "Stehlampe Büro" <light> [ "Lighting" ]
    { mqtt=">[broker:/Sonoff_1/GPIO/12:command:ON:1],
            >[broker:/Sonoff_1/GPIO/12:command:OFF:0],
            <[broker:/Sonoff_1/lightState/Switch:state:default]" }

If it still doesn’t work, install Tasmota :stuck_out_tongue:

1 Like

Heyho

yesterday i restarted my router and now i cant switch the sonoff anymore :frowning:

With MQTT.app i can change the status (On/Off), and subscribe to the uptime, without any problems …

But with openhab, i cant change the lamp-status :frowning: WHY !?
i didnt change any settings :frowning:

THANKS

Switch Sonoff_1 "Stehlampe Büro" <light> [ "Lighting" ]
    { mqtt=">[broker:/Sonoff_1/GPIO/12:command:ON:1],
            >[broker:/Sonoff_1/GPIO/12:command:OFF:0],
            <[broker:/Sonoff_1/lightState/Switch:state:default]" }

32

Not much to work with here. I’d restart mosquitto openHAB and Sonoff to rule out any volatile situation.

1 Like

Okay - a restart of my Raspb. did the trick :wink: - Thanks Thom!

any ideas why my Sonoff turns OFF randomly after 4-5000 minutes !?

Uff, no idea. That NEVER happened to me… would be awful. Thank god I’m using Sonoff-Tasmota :smile:

hmm, my next sonoff gets a Tasmota for sure :wink: i will order one today and test :wink:

should i change something in my mqtt.cfg here ?

# 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>

Thanks!

no. :slight_smile: