Help with configuration of mqtt using Sonoff switch with ESP Easy


(Bert) #1

Hi all,
I try to get my Sonoff with the ESPEasy firmware working with OH2, and i am strugeling for several days with it. So i try te get some help.
I am rather new to OH started with 1.8.3, and switched over to OH2 Snapshot Release.
My configuration with Fibaro Wall Plugs is working nicely, including some cron rules.
So i thought i give the Sonoff device working with mqtt a try. Installed Mosquitto which is working. It tested OK with the two terminal window subscribe and publish methode. Also in PaperUI i installed the MQTT addon. But i am not able to get the configuration right.

This is my mqtt.conf:

mosquitto.url=tcp://192.168.178.54:1883
mosquitto.clientId=openhab

Everything else is commented out (#).

My mqtt-eventbus.cfg contains only:

broker=mosquitto

The Sonoff (ESP8266) is loaded with the ESP Easy firmware and configured as this:

For some reason the image is not showing, so i have it uploaded here:
https://deltabert.stackstorage.com/s/qU4Y19IfqdN6Bqn

When i look from the terminal to mosquitto with the command

mosquitto_sub -d -v -t \#

i get the following from my Sonoff device (there is only one Sonoff):

Client mosqsub/13252-openhab received PUBLISH (d0, q0, r1, m0, 'openhab/out/EE_3_SW_WCD_1/state', ... (3 bytes))
openhab/out/EE_3_SW_WCD_1/state OFF
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r1, m0, 'openhab/out/EE_3_SW_WCD_1_power/state', ... (1 bytes))
openhab/out/EE_3_SW_WCD_1_power/state 0
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r1, m0, 'openhab/out/EE_3_SW_WCD_1_meter_kwh/state', ... (3 bytes))
openhab/out/EE_3_SW_WCD_1_meter_kwh/state 0.4
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r1, m0, 'openhab/out/EE_3_SW_WCD_1_meter_watts/state', ... (1 bytes))
openhab/out/EE_3_SW_WCD_1_meter_watts/state 0
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r1, m0, 'openhab/out/sonoff_1/state', ... (3 bytes))
openhab/out/sonoff_1/state OFF
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r1, m0, '/openHAB/out/EE_3_SW_WCD_1/command', ... (3 bytes))
/openHAB/out/EE_3_SW_WCD_1/command OFF
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r1, m0, '/openHAB/out/sonoff_1/command', ... (3 bytes))
/openHAB/out/sonoff_1/command OFF
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/CurrDateTime/state', ... (19 bytes))
openhab/out/CurrDateTime/state 2017-02-25T21:47:21
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Date/state', ... (19 bytes))
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Season/state', ... (6 bytes))
openhab/out/Season/state WINTER
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SeasonName/state', ... (6 bytes))
openhab/out/SeasonName/state WINTER
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Uptime/Minutes', ... (5 bytes))
/Sonoff_1/Uptime/Minutes 54.70
Client mosqsub/13252-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -83
^C
openhab@openhab:~ $

(I am also confused that some entries start with a slash (Sonoff) and some are not.)
I have looked at numeral examples and the online OH manual but i can’t get the thing working.
I think am am stuck at the moment…
I configured this for the Sonoff in my items file:

Swith   sonoff_1    	"Sonoff Switch 1 [%s]" 	{mqtt=">[mosquitto:/Sonoff_1/gpio/0:command:ON:1],>[mosquitto:/Sonoff_1/gpio/0:command:OFF:0]"}
String  sonoffUptime 	"sonoffUptime [%s]"	{mqtt="<[mosquitto:/Sonoff_1/Uptime:state:default]"}

And put this in my sitemap:

Switch item=sonoff_1 			label="Sonoff-1 aan/uit"    icon="light"
Text item=sonoffUptime

I get these errors in openhab.log:

        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[83:org.eclipse.jetty.util:9.2.19.v20160908]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]
2017-02-25 21:17:13.075 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'sonoff_1' for widget org.eclipse.smarthome.model.sitemap.Switch
2017-02-25 21:17:13.077 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch
2017-02-25 21:17:13.079 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'sonoff_1' for widget org.eclipse.smarthome.model.sitemap.Switch
2017-02-25 21:17:13.081 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'sonoff_1' for widget org.eclipse.smarthome.model.sitemap.Switch
2017-02-25 21:17:13.083 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'sonoff_1' for widget org.eclipse.smarthome.model.sitemap.Switch
openhab@openhab:~ $

And these in mosquitto.log:

openhab@openhab:~ $ tail -100 /var/log/mosquitto/mosquitto.log
1488002021: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488003822: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488005623: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488007424: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488009225: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488011026: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488012827: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488014628: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488015061: Client ESPClient0 has exceeded timeout, disconnecting.
1488015061: Socket error on client ESPClient0, disconnecting.
1488015109: New connection from 192.168.178.211 on port 1883.
1488015109: New client connected from 192.168.178.211 as ESPClient0 (c1, k15).
1488016429: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488018230: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488020031: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488021832: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488023633: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488025434: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488027235: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488029036: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488030837: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488032638: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488034439: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488036240: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488038041: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488039842: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488041643: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488043444: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488045245: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488046193: New connection from ::1 on port 1883.
1488046193: New client connected from ::1 as mosqsub/2127-openhab (c1, k60).
1488046209: Socket error on client mosqsub/2127-openhab, disconnecting.
1488046213: New connection from ::1 on port 1883.
1488046213: New client connected from ::1 as mosqsub/2146-openhab (c1, k60).
1488046234: Socket error on client mosqsub/2146-openhab, disconnecting.
1488046318: New connection from 192.168.178.46 on port 1883.
1488046318: New client connected from 192.168.178.46 as MQTT_FX_Client (c1, k60).
1488047046: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488048518: New connection from ::1 on port 1883.
1488048518: New client connected from ::1 as mosqsub/4880-openhab (c1, k60).
1488048541: Socket error on client mosqsub/4880-openhab, disconnecting.
1488048563: New connection from ::1 on port 1883.
1488048563: New client connected from ::1 as mosqsub/4939-openhab (c1, k60).
1488048599: Socket error on client mosqsub/4939-openhab, disconnecting.
1488048636: New connection from ::1 on port 1883.
1488048636: New client connected from ::1 as mosqsub/5035-openhab (c1, k60).
1488048712: Socket error on client mosqsub/5035-openhab, disconnecting.
1488048717: New connection from ::1 on port 1883.
1488048717: New client connected from ::1 as mosqsub/5124-openhab (c1, k60).
1488048847: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488049067: Socket error on client mosqsub/5124-openhab, disconnecting.
1488049080: New connection from ::1 on port 1883.
1488049080: New client connected from ::1 as mosqsub/5541-openhab (c1, k60).
1488049262: Client ESPClient0 has exceeded timeout, disconnecting.
1488049262: Socket error on client ESPClient0, disconnecting.
1488049307: New connection from 192.168.178.211 on port 1883.
1488049307: New client connected from 192.168.178.211 as ESPClient0 (c1, k15).
1488049313: Client MQTT_FX_Client has exceeded timeout, disconnecting.
1488049313: Socket error on client MQTT_FX_Client, disconnecting.
1488049333: Client ESPClient0 has exceeded timeout, disconnecting.
1488049333: Socket error on client ESPClient0, disconnecting.
1488049373: New connection from 192.168.178.211 on port 1883.
1488049373: New client connected from 192.168.178.211 as ESPClient0 (c1, k15).
1488050230: Socket error on client mosqsub/5541-openhab, disconnecting.
1488050648: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488051983: New connection from 192.168.178.46 on port 1883.
1488051983: New client connected from 192.168.178.46 as MQTT_FX_Client (c1, k60).
1488052292: New connection from ::1 on port 1883.
1488052292: New client connected from ::1 as mosqsub/9303-openhab (c1, k60).
1488052449: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1488052459: Socket error on client mosqsub/9303-openhab, disconnecting.
1488052465: New connection from ::1 on port 1883.
1488052465: New client connected from ::1 as mosqsub/9509-openhab (c1, k60).
1488052509: Socket error on client mosqsub/9509-openhab, disconnecting.
1488054250: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
openhab@openhab:~ $ ^C

As first step i would like to be able to switch the Sonoff from the commandline, and the second step from my sitemap.

I hope anyone can help me with the correct configuration for my Sonoff devices.


(SiHui) #2

First thing: fix your typo, then let’s see what else is wrong:

Swith sonoff_1 "Sonoff Switch 1 [%s]" {mqtt=">[mosquitto:/Sonoff_1/gpio/0:command:ON:1],>[mosquitto:/Sonoff_1/gpio/0:command:OFF:0]"}

should be Switch instead of Swith


(Bert) #3

Hi Sihui,
Thanks for looking through my configuration! I completely overlooked the typo :-(. Think i went multiple times through my cfg… Sorry for this. However i found one other thing which might have caused problems; in my ESPEasy config i named my Sonoff device Sonoff_1, while in my OH2 cfg files i used all lower case. Corrected the OH2 items and sitemap files si the name is everywhere Sonoff_1.
However it works rather intermittendly, it seems i have to press the button in the gui twice before the Sonoff switches on or off. I think it has to do with the configuration of my items file.
The switch line i use now, which switches gpio:0 on the ESP8266, corresponds with what is configured in ESPEasy: https://deltabert.stackstorage.com/s/qU4Y19IfqdN6Bqn
(sorry could not get a picture file in here…)

// **************** Test met mqtt ********* [OH2] Control ESP8266 Relay using MQTT Eventbus *********
//
// Switch	Sonoff-1	"Sonoff Switch 1"	<light>	(EE_Werk2)	{ mqtt=">[mosquitto:/Sonoff-1/gpio/12:command:ON:1],>[mosquitto:/Sonoff-1/gpio/12:command:OFF:0],<[mosquitto:/Sonoff-1/lightState/Switch:command:ON:1],<[mosquitto:/Sonoff-1/lightState/Switch:command:OFF:0]" }

Switch   Sonoff_1    	"Sonoff Switch 1 [%s]" 	{mqtt=">[mosquitto:/Sonoff_1/lightSwitch/gpio/0:command:ON:1],>[mosquitto:/Sonoff_1/gpio/0:command:OFF:0]"}

String  SonoffUptime 	"SonoffUptime [%s]"	{mqtt="<[mosquitto:/Sonoff_1/Uptime/Minutes:state:default]"}

String  SonoffWifi	"Sonoff WiFi Status"	{mqtt="[mosquitto:/Sonoff_1/Wifi/]" }
//

I hope you are familiar with these Sonoff devices, and can help me with the correct item cfg?

Further, i have a question about the use of slashes in the mqtt cfg. When i trace mqtt with

mosquitto_sub -d -v -t \#

i see some topics starting with a slash and some without. For my sonoff device i see normally the topic entries with the preceding slash, but there are entries without the preceding slash…Like f.i. my Fibaro Wall Plug. (EE_3_SW_WCD_1) and for Astro related topics which are without the preceding slash?!

Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Zodiac/state', ... (6 bytes))
openhab/out/Zodiac/state PISCES
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/MoonElevation/state', ... (5 bytes))
openhab/out/MoonElevation/state 25.14
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Season/state', ... (6 bytes))
openhab/out/Season/state WINTER
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SeasonName/state', ... (6 bytes))
openhab/out/SeasonName/state WINTER
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Total_Radiation/state', ... (6 bytes))
openhab/out/Total_Radiation/state 335.17
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -80
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -80
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -80
Client mosqsub/32723-openhab sending PINGREQ
Client mosqsub/32723-openhab received PINGRESP
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -85
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Date/state', ... (19 bytes))
openhab/out/Date/state 2017-02-27T11:20:36
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/CurrDateTime/state', ... (19 bytes))
openhab/out/CurrDateTime/state 2017-02-27T11:20:36
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -84
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Uptime/Minutes', ... (5 bytes))
/Sonoff_1/Uptime/Minutes 92.23
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SonoffUptime/state', ... (5 bytes))
openhab/out/SonoffUptime/state 92.23
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -83
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -81
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SunriseTime/state', ... (19 bytes))
openhab/out/SunriseTime/state 2017-02-27T07:31:00
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/MoonFull/state', ... (19 bytes))
openhab/out/MoonFull/state 2017-03-12T15:55:00
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/MoonNew/state', ... (19 bytes))
openhab/out/MoonNew/state 2017-03-28T04:58:00
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/NightStartTime/state', ... (19 bytes))
openhab/out/NightStartTime/state 2017-02-27T20:08:00
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SunsetTime/state', ... (19 bytes))
openhab/out/SunsetTime/state 2017-02-27T18:12:00
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/MoonPhase/state', ... (15 bytes))
openhab/out/MoonPhase/state WAXING_CRESCENT
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/MoonAzimuth/state', ... (6 bytes))
openhab/out/MoonAzimuth/state 143.21
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/NightEndTime/state', ... (19 bytes))
openhab/out/NightEndTime/state 2017-02-28T05:36:00
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/MoonElevation/state', ... (5 bytes))
openhab/out/MoonElevation/state 25.23
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SunAzimuth/state', ... (6 bytes))
openhab/out/SunAzimuth/state 154.54
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SunElevation/state', ... (5 bytes))
openhab/out/SunElevation/state 26.64
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Season/state', ... (6 bytes))
openhab/out/Season/state WINTER
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Total_Radiation/state', ... (6 bytes))
openhab/out/Total_Radiation/state 336.45
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Zodiac/state', ... (6 bytes))
openhab/out/Zodiac/state PISCES
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SeasonName/state', ... (6 bytes))
openhab/out/SeasonName/state WINTER
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/32723-openhab sending PINGREQ
Client mosqsub/32723-openhab received PINGRESP
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -81
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/lightSwitch/gpio/0', ... (1 bytes))
/Sonoff_1/lightSwitch/gpio/0 1
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/openHAB/out/Sonoff_1/command', ... (2 bytes))
/openHAB/out/Sonoff_1/command ON
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Sonoff_1/state', ... (2 bytes))
openhab/out/Sonoff_1/state ON
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/gpio/0', ... (1 bytes))
/Sonoff_1/gpio/0 0
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/openHAB/out/Sonoff_1/command', ... (3 bytes))
/openHAB/out/Sonoff_1/command OFF
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Sonoff_1/state', ... (3 bytes))
openhab/out/Sonoff_1/state OFF
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/lightSwitch/Switch', ... (1 bytes))
/Sonoff_1/lightSwitch/Switch 1
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/lightState/Switch', ... (1 bytes))
/Sonoff_1/lightState/Switch 0
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -80
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Date/state', ... (19 bytes))
openhab/out/Date/state 2017-02-27T11:21:36
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/CurrDateTime/state', ... (19 bytes))
openhab/out/CurrDateTime/state 2017-02-27T11:21:36
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -81
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Sonoff_1/state', ... (2 bytes))
openhab/out/Sonoff_1/state ON
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/openHAB/out/Sonoff_1/command', ... (2 bytes))
/openHAB/out/Sonoff_1/command ON
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/lightSwitch/gpio/0', ... (1 bytes))
/Sonoff_1/lightSwitch/gpio/0 1
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Sonoff_1/state', ... (3 bytes))
openhab/out/Sonoff_1/state OFF
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/openHAB/out/Sonoff_1/command', ... (3 bytes))
/openHAB/out/Sonoff_1/command OFF
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/gpio/0', ... (1 bytes))
/Sonoff_1/gpio/0 0
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/lightSwitch/Switch', ... (1 bytes))
/Sonoff_1/lightSwitch/Switch 0
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/lightState/Switch', ... (1 bytes))
/Sonoff_1/lightState/Switch 1
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -81
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Sonoff_1/state', ... (2 bytes))
openhab/out/Sonoff_1/state ON
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/lightSwitch/gpio/0', ... (1 bytes))
/Sonoff_1/lightSwitch/gpio/0 1
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/openHAB/out/Sonoff_1/command', ... (2 bytes))
/openHAB/out/Sonoff_1/command ON
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Sonoff_1/state', ... (3 bytes))
openhab/out/Sonoff_1/state OFF
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/gpio/0', ... (1 bytes))
/Sonoff_1/gpio/0 0
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/openHAB/out/Sonoff_1/command', ... (3 bytes))
/openHAB/out/Sonoff_1/command OFF
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/lightSwitch/Switch', ... (1 bytes))
/Sonoff_1/lightSwitch/Switch 1
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/lightState/Switch', ... (1 bytes))
/Sonoff_1/lightState/Switch 0
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Uptime/Minutes', ... (5 bytes))
/Sonoff_1/Uptime/Minutes 92.25
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SonoffUptime/state', ... (5 bytes))
openhab/out/SonoffUptime/state 92.25
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -82
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -86
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -79
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/MoonFull/state', ... (19 bytes))
openhab/out/MoonFull/state 2017-03-12T15:55:00
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SunriseTime/state', ... (19 bytes))
openhab/out/SunriseTime/state 2017-02-27T07:31:00
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/MoonNew/state', ... (19 bytes))
openhab/out/MoonNew/state 2017-03-28T04:58:00
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/MoonPhase/state', ... (15 bytes))
openhab/out/MoonPhase/state WAXING_CRESCENT
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/MoonAzimuth/state', ... (6 bytes))
openhab/out/MoonAzimuth/state 143.46
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/NightStartTime/state', ... (19 bytes))
openhab/out/NightStartTime/state 2017-02-27T20:08:00
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/NightEndTime/state', ... (19 bytes))
openhab/out/NightEndTime/state 2017-02-28T05:36:00
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SunsetTime/state', ... (19 bytes))
openhab/out/SunsetTime/state 2017-02-27T18:12:00
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/MoonElevation/state', ... (5 bytes))
openhab/out/MoonElevation/state 25.32
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SunAzimuth/state', ... (6 bytes))
openhab/out/SunAzimuth/state 154.81
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SunElevation/state', ... (5 bytes))
openhab/out/SunElevation/state 26.70
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Total_Radiation/state', ... (6 bytes))
openhab/out/Total_Radiation/state 337.73
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Zodiac/state', ... (6 bytes))
openhab/out/Zodiac/state PISCES
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/Season/state', ... (6 bytes))
openhab/out/Season/state WINTER
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/SeasonName/state', ... (6 bytes))
openhab/out/SeasonName/state WINTER
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -79
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/EE_3_SW_WCD_1/state', ... (2 bytes))
openhab/out/EE_3_SW_WCD_1/state ON
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/openHAB/out/EE_3_SW_WCD_1/command', ... (2 bytes))
/openHAB/out/EE_3_SW_WCD_1/command ON
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -79
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/EE_3_SW_WCD_1_power/state', ... (3 bytes))
openhab/out/EE_3_SW_WCD_1_power/state 4.4
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/EE_3_SW_WCD_1/state', ... (3 bytes))
openhab/out/EE_3_SW_WCD_1/state OFF
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/openHAB/out/EE_3_SW_WCD_1/command', ... (3 bytes))
/openHAB/out/EE_3_SW_WCD_1/command OFF
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, 'openhab/out/EE_3_SW_WCD_1_power/state', ... (1 bytes))
openhab/out/EE_3_SW_WCD_1_power/state 0
Client mosqsub/32723-openhab received PUBLISH (d0, q0, r0, m0, '/Sonoff_1/Wifi/', ... (3 bytes))
/Sonoff_1/Wifi/ -87
^C
openhab@openhab:~ $

Any idea how to correct this? Especially the need to press the Sonnoff button in the GUI twice (the cfg in the items file).
Thank you for your help so far.


(Bert) #4

@sihui, What the preceding slashes concerned in the mosquitto log, i just saw thw ESPEasy Template configuration in Tools::Advanced Settings. The variables used there have a preceding slash.
But then still the question, should not all OH2 cfs use preceding slashes in mqtt?


( ) #5

Hello,
this might not be the answer you are looking for, I just want to state it once.
While ESPEasy might be a nice toolbox for the ESP in general, for the Sonoff modules you could be better off using the specialized firmware “Sonoff-Tasmota” by arendst.

That’s not a question on openHAB but on the architecture of MQTT: http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices

Best practices

  • Don’t use a leading forward slash

(Bert) #6

OK Thom, thanks for pointing me on the TASMOTA solution. I will give it a try with one of the other Sonoff’s i have. Hopefully this resolves the need of pressing twice on the GUI button…
And thanks for the Best Practices regarding mqtt use of leading slashes. I will anyhow change the cfg from ESP Easy.

Update. I had seen the TASMOTA solution, but in order fo flash your ESP8266 you have to get one of the development environments on you (WIN10) PC; Arduino or PlatformIO. I have Arduino on my PC but then i needed Pyton and Git in order to get started. But i must say, i have no experience with Arduino. And with PlatformIO you need ATOM, which broke off installing with all sorts of installation errors.
ESPEasy on the other hand has a simple bin writer to write the firmware to the esp8266… So the choice was simple.
It is realy a pitty that Theo Arends could not provide us with a simple bin file with a flash tool to flash the esp8266; the solution as ESP Easy is using… This makes things unnessacary complicated for simple users like myself.
But i am trying to get the Tasmota firmware on my Sonoff’s. However, it’s a pitty it takes so much extra time…


(SiHui) #7

Take a look here:

That depends on the configuration of the device/firmware: the template in ESPEasy is using a leading slash, other firmware versions maybe don’t.

Actually that is the key: whatever you see in the output (folder structure, slash or no slash), has to be used in your items definition.

That has nothing to do with MQTT, you have a wrong item definition in your sitemap, maybe a typo.

There is also another, maybe userfriendly firmware:


( ) #8

There are binaries available. Maybe you could try them? I never thought about that because both arduino and PlatformIO are already on my PC. If you are able to flash these with the ESPEasy bin writer (can’t see why not), please let us know! https://github.com/arendst/Sonoff-Tasmota/releases

Also check: http://www.espressif.com/en/support/download/other-tools

mosquitto_sub is a nice tool but nobody is stopping you from using a gui client: http://www.hivemq.com/blog/mqtt-toolbox-mqtt-spy

Homie is great and I’ve used it in a bigger project of mine. It’s however not quite comparable to ESPEasy. Homie is a framework to develop your own firmware. If that’s indeed your goal at some point, I can fully recommended it. You will need to code and test and the documentation is far from perfect, making starting out quite complicated.


(SiHui) #9

Thx for taking a deeper look, I didn’t :sunglasses:


(Bert) #10

Thank you Sihui and ThomDietrich, for you help so far. I have my sonoff working as intended (functions like the origional firmware with the web portal).
Bu i read disturbing messages about the status of ESP Easy, so i would like to switch over to Tasmota solution. @ThomDietrich, i have send you a pm about an issue with the preparation of Arduino IDE.


(Bert) #11

Update.
I managed to get TASMOTA firmware on the Sonoff ! I used the NodeMCU Flasher (ESP2866Flasher.exe) to flash the firmware.bin from Tasmota. This is comparable with the way ESPEasy works.
But i had some difficulties to get the ssid en password configured. Used the Android ESP8266 SmartConfig app and the Button usage from the Tasmota wiki. But every time i started the app and pressed three times the button from the Sonoff it showed failed! I was almost giving up on this when i looked with the Fing app and saw a new IP@ in my network!! Then i got the web config.
Tomorrow i will continue…


(Blair Thompson) #12

There is no problem getting espeasy working, I use it and it is very reliable. Something that I found made a big difference to reliability.

On both openhab and the espeasy device make sure that retain is enabled

mqtt:.retain=true

And do this also in ESPEasy.

Then if for any reason the Sonoff is disconnected from the broker it will pick up the message upon reconnection.


(Bert) #13

I did got ESP Easy working. The sonoff has now the same functionality as the origional Itead fw. In my GUI i can (single) click on the button to toggle the light on/off, and also the button on the sonoff is functoining.
I have now two sonoffs and the second one i loaded with Tasmota fw using a bin loader, not Arduino or an other IDE. Did it just to see how this is functioning, and moreover how i can deal with that. I see that i can configure things in user_config.h file, but i am afraid i need the Arduino or PlatformIO for that.
Now i have things working, I will be ordering a number of the sonoff power sockets because they are way cheaper that the Fibaro Wall Plug (zwave) i had bought before!


(SiHui) #14

Where do you do that on the ESPEasy? I have firmware version 108 …


(Bert) #15

@ThomDietrich, I see there is a difference in specifying the mqtt strings between ESP Easy and Tasmota.
Looking with mqtt.fx, i see with Tasmota: cmnd/Sonoff_2/power
and for the same solution with ESP easy: Sonoff_1/lightSwitch/Switch
I must say the latter seems more conform the mqtt standaard; a more top-down approch: %sysname%/%tskname%/%valname%

Tracing with f.i. mqtt.fx, its for me easier to select the device, and see every message from it. Now you must specify cmnd/device/# and you see only cmds from that device. (Hope i made myself clear…)

Is there a way i could change this with Tasmota fw in the web configuration?
It results in completely different config in my items file:

Switch   Sonoff_1    	"Sonoff Switch 1 [%s]" 	<light>	(EE_Werk2)	{ mqtt=">[mosquitto:Sonoff_1/lightSwitch/gpio/12:command:ON:1],>[mosquitto:Sonoff_1/gpio/12:command:OFF:0]"}

vs

Switch 	Sonoff_2 	"Sonoff Switch 2 [%s]" 	<light> (EE_Werl2)      { mqtt=">[mosquitto:cmnd/Sonoff_2/power:command:*:default],<[mosquitto:stat/Sonoff_2/POWER:state:default]" }

(SiHui) #16

Subscribe to topic # and you will see every device message coming in …


( ) #17

As @sihui said. You can also subscribe to e.g. +/Sonoff_2/# to see everything related to this one device.

I know what you mean. I also think the MQTT message topology chosen with Tasmota is not the best, but hey, does it really make a difference? There is some strategy and that’s fine. You’ll copy&paste these topics to the items definition and never bother to look at them again. You’ll find dozens of MQTT topic approaches, non like the others.

No there is not.

Btw. did you see the ready to use examples we’ve collected over in the wiki? https://github.com/arendst/Sonoff-Tasmota/wiki/openHAB

Ah one more thing @deltabert and @sihui I’ve used mqtt.fx for a longer time and I really don’t like it :smile: If you feel the same way, check out mqtt spy.


(Bert) #18

Thanks sihui, but i alraedy did that; in fact i started with #. But then you get a lot of other mqtt msgs and i just want to search for specific messages, like all my sonnofs ( Sonoff_*/# ), or better still specify one specific sonoff ( Sonoff_2 )
(I beleave ’ * ’ is a placeholder for part of the variable name?)

Besides, my question was more to be able to get a universal naming convention in the items files.

Update:
Ok thanks ThomDietrich, i can live with the fact that the naming can not be changed :wink:
The specification +/Sonoff_2/# , i had not yet discovered (the + ) And yes, i found your examples on the Tasmota wiki, and i am using them :wink: thank you for these. I will take a look aat mqtt spy too.

Must say, i am learning a lot about mqtt. Its my first encountering with it :slight_smile:


( ) #19

This is a must read for everyone starting out with mqtt: http://www.hivemq.com/blog/mqtt-essentials


(SiHui) #20

Looks promising and worked right out of the box. Will take a deeper look, thx …

Hmm, weird, not in my case. Do you have the mqtt-eventbus configured? If you have a usecase for that, fine, but it is not needed for connections to an ESPEasy driven device.