MQTT and Sonoff only partly working, need help

Hi,

i could need a helping hand regarding my Sonoff. I can subscrube to it, but i just dont get the hang of how to publish, i can not switch that switch :smiley:

I have flashed the Sonoff with espeasy (120), and i am able to subscribe to the uptime and make that visible in my sitemap. My problem is that i just cant figure out how to publish to it, i have never been able to trigger the relay.

My items:

Switch sonoff1 "Sonoff Switch 1 [%s]" {mqtt=">[mosquitto:sonoff1/lightSwitch/gpio/0:command:ON:1],>[mosquitto:sonoff1/lightSwitch/gpio/0:command:OFF:0]"}
String sonoffUptime "sonoffUptime [%s]"	{mqtt="<[mosquitto:sonoff1/uptime/Minutes:state:default]"}

Configuration of the Sonoff:

Config:
sonoff1 (Name), 1 (Unit Nr), openHAB MQTT (Protocoll), IP, Port and Credentials of my broker

Devices:
1: Switch Input, lightSwitch (name), 1 (idx), GPIO-0, Switch (Switch Type), Normal Switch (Switch Button Type), Switch (Variable Name).
2: System Info, uptime (name), 3 (idx), Minutes (Variable Name)

Tools -> Advanced:
%sysname%/# (Subscribe Template), %sysname%/%tskname%/%valname% (publish template)

I tried alot of things, like only using the name and gpio in the items, i tried to put in the variable name (Switch), i used different GPIOs, … i tried basicly everything i could find on the web, but i cant get that thing working besides getting the uptime. I tried to send commands with mosquitto_pub, but i cant get it working either (only uptime).

Any ideas?

Thank you in advance!!

Did you try

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

?

yup

Do i have to use gpio 0 or some other? I find examples on the web with differend numbers, which is something i dont understand. Ist it the same number for everyone there?

That depends on the device you are using and to what pin you have connected your relay.
For example a nodemcu board:
http://www.cnx-software.com/2015/10/29/getting-started-with-nodemcu-board-powered-by-esp8266-wisoc/

Its a Sonoff TH16, and most ppl seem to find the releay on gpio 0.

I got it now, but it was all trial&error, i dont know why this works … :wink:

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

Why does this work? Why cant i use “lightSwitch” in the topic? I must be missing something of the MQTT-Protocol here i guess.

Thanks for the replies thogh :slight_smile: