MQTT Sonoff itead

mosquitto
mqtt
sonoff
Tags: #<Tag:0x00007fe05fd2d380> #<Tag:0x00007fe05fd2c958> #<Tag:0x00007fe05fd27ef8>

(Elias H.) #1

Hello Community I am trying to get my Sonoff itead Switch to work with openHAB.

I have done the Following.

  1. Flashed the Sonoff itead Switch
  2. Configured the Mosquitto broker
  3. Configured the mqtt.cfg for openhab

Now I checked if everything is working.
I can access the Sonoff Switch via. Firefox
I check and configure the MQTT for the Sonoff Switch.

Sonoff Console Log

00:00:00 APP: Project sonoff Sonoff (Topic cmnd/sonoff-977686, Fallback DVES_977686, GroupTopic sonoffs) Version 4.0.8
00:00:00 Wifi: Connecting to AP1 wonderland in mode 11N as cmnd/sonoff-977686-5766...
00:00:05 Wifi: Connected
00:00:05 mDNS: Initialized
00:00:05 HTTP: Webserver active on cmnd/sonoff-977686-5766.local with IP address ***.***.***.***
11:01:51 MQTT: Attempting connection...
11:01:53 mDNS: Query done with 0 mqtt services found
11:01:53 MQTT: Connected
11:01:53 MQTT: tele/cmnd/sonoff-977686/LWT = Online (retained)
11:01:53 MQTT: cmnd/cmnd/sonoff-977686/POWER = 
11:01:53 MQTT: tele/cmnd/sonoff-977686/INFO1 = {"Module":"Sonoff Basic", "Version":"4.0.8", "FallbackTopic":"DVES_977686", "GroupTopic":"sonoffs"}
11:01:53 MQTT: tele/cmnd/sonoff-977686/INFO2 = {"WebserverMode":"Admin", "Hostname":"cmnd/sonoff-977686-5766", "IPaddress":"***.***.***.***"}
11:01:53 MQTT: tele/cmnd/sonoff-977686/INFO3 = {"Started":"Software/System restart"}
11:01:54 MQTT: stat/cmnd/sonoff-977686/RESULT = {"POWER":"ON"}
11:01:54 MQTT: stat/cmnd/sonoff-977686/POWER = ON

Switching from On to Off Mosquitto Log

1492682688: Received PUBLISH from DVES_977686 (d0, q0, r0, m0, 'stat/cmnd/sonoff-977686/RESULT', ... (15 bytes))
1492682688: Received PUBLISH from DVES_977686 (d0, q0, r0, m0, 'stat/cmnd/sonoff-977686/POWER', ... (3 bytes))

Feels good.

Now I tested an simple MQTT openHAB item.

Switch LivingRoom_Light "Living Room Light" <light> (ALL, Office_Workstation, Office_First_Floor) { mqtt=">[mosquitto:cmnd/sonoff-977686/POWER:command:*:default], <[mosquitto:stat/cmnd/sonoff-977686/POWER:state:default]" }

Verbose Mosquitto Log when saving the openHAB item

1492682948: Received PINGREQ from DVES_977686
1492682948: Sending PINGRESP to DVES_977686
1492682948: Received UNSUBSCRIBE from openhabian.1492677563242
1492682948: 	stat/cmnd/sonoff-977686/POWER
1492682948: openhabian.1492677563242 stat/cmnd/sonoff-977686/POWER
1492682948: Received SUBSCRIBE from openhabian.1492677563242
1492682948: 	stat/cmnd/sonoff-977686/POWER (QoS 1)
1492682948: openhabian.1492677563242 1 stat/cmnd/sonoff-977686/POWER
1492682948: Sending SUBACK to openhabian.1492677563242

When I press the button on my sitemap Mosquitto Log

1492683090: Received PUBLISH from openhabian.1492677563242 (d0, q1, r1, m25, 'cmnd/sonoff-977686/POWER', ... (2 bytes))
1492683090: Sending PUBACK to openhabian.1492677563242 (Mid: 25)
1492683090: Sending PUBLISH to mosqsub/26728-openHABia (d0, q0, r0, m0, 'cmnd/sonoff-977686/POWER', ... (2 bytes))

This did not switch the Sonoff switch so I thought hm okay I should start with a MQTT state read item so I did.

Switch LivingRoom_Light_State "Give me this state" (All, Office_Workstation, Office_First_Floor) { mqtt="<[mosquitto:stat/cmnd/sonoff-977686/POWER:state:default]" }

Was really good the Item on the Sitemap displayed me if the Sonoff itead is on/off.

But how the DUCK can I switch the Sonoff Switch via openHAB?
My first Item should to that!

Switch LivingRoom_Light "Living Room Light" <light> (ALL, Office_Workstation, Office_First_Floor) { mqtt=">[mosquitto:cmnd/sonoff-977686/POWER:command:*:default], <[mosquitto:stat/cmnd/sonoff-977686/POWER:state:default]" }

Am I missing something?


(Andrew) #2

Please join us here