Sonoff dual wifi switch


(michael w) #1

Hello I’m new to this so was wondering anyone can advise on the setup of this switch through smarthings hub with a mod to the firmware


(Paul) #2

I’m not sure if anyone has written a DTH for the dual switch yet.

I’ll tag @erocm1231, if anyone knows he will.


(michael w) #3

Ok many thanks for that


(Eric M) #4

I have been wanting to get the Dual switch working but have been so busy that I haven’t had the time. I have 4 new devices coming from itead that I want to work on as well.


(michael w) #5

Thank you for your reply, would it be true in saying that there are plans for intergration with the sonoff/itead and echo coming soon or is this just a rumor ?


(Eric M) #6

I haven’t heard of any official integration, but I wouldn’t be surprised given the traction that Alexa has.


(michael w) #7

Ok I’ll still be flashing my sonoff to keep it local and using my smarthings hub, but I’ve ordered 10 dual units as it was a size issue so ill change them to single for now ,thanks again keep up the excellent work


(Vineet) #8

@erocm1231

I’m more keen with the Sonoff 4ch wifi switch, i can just put it inside the wall plate. Would love to see it working. Are you getting one of that to tinker as well ?

https://www.itead.cc/sonoff-4ch.html

  • thanks.

(michael w) #9

Hello could someone tell me where I am going wrong please .I have the sonoff TH 10 device and have flashed it with ESP easy and put the firmware in sonoff TH image to it also Is this the right image or do o have to install the sonoff .ono image as well? on connected to smarthings hub and it will work like a switch but will not detect temperature I know the sensor works as I have installed it into an un flashed device and connected it to ewelink and the temperature reads (it is the waterproof sensor for temp that I have) can someone please detect me to where I am going wrong…thanks


(michael w) #10

Also when I try to discover the device I have to use the ip and put the sonoff sw title as it will not install when I put in the Th switch title the Th is running as a sonoff switch but not Th switch . I have downloaded Eric’s firmware for it and installed it as he said? esptool.exe -vv -cd nodemcu -cb 115200 -cp COM%comport% -ca 0x00000 -cf Sonoff.ino.generic.bin Putting my Coms port in and also changing the sonoff file to TH Can anyone give me a clue please as being a novice doesn’t help thanks


(Paulo Santos) #11

Hi, any luck with adding sonoff dual to ST? Have a few and wanted to link them to ST.
Would it be very diferent from sonoff single switch?
Thanks
For anyone that understands a bit more of programming would this code need a few tweeks!?

http://support.iteadstudio.com/support/discussions/topics/11000006870

// derived from the Basic MQTT example https://github.com/knolleary/pubsubclient/blob/master/examples/mqtt_basic/mqtt_basic.ino

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

// Update these with values suitable for your network.
String MQTT_SUBSCRIPTION = “sonoff/2/#”;
String MQTT_PUBLISH = “sonoff/2”;

const char* ssid = “xxx”;
const char* password = “yyy”;
const char* mqtt_server = “zzz”;

boolean relay1 = false;
boolean relay2 = false;
int incomingByte = 0;
int iStep = 0;
int iNewState = 0;

WiFiClient espClient;
PubSubClient client(espClient);

void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
//Serial.println();
//Serial.print("Connecting to ");
//Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
//Serial.print(".");
}

randomSeed(micros());

//Serial.println("");
//Serial.println(“WiFi connected”);
//Serial.println("IP address: ");
//Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length) {
boolean bset = false;
payload[length] = ‘\0’;
String sPayload = String((char *)payload);
String sTopic = String(topic);
if (sTopic == MQTT_PUBLISH + “/relay1/set”) {
if (sPayload == “1”) {
if (relay1 == false) bset = true;
relay1 = true;
} else {
if (relay1) bset = true;
relay1 = false;
}
}
if (sTopic == MQTT_PUBLISH + “/relay2/set”) {
if (sPayload == “1”) {
if (relay2 == false) bset = true;
relay2 = true;
} else {
if (relay2) bset = true;
relay2 = false;
}
}
if (bset) setrelays();
}

void reconnect() {
// Loop until we’re reconnected
while (!client.connected()) {
//Serial.print(“Attempting MQTT connection…”);
// Create a random client ID
String clientId = “sonoff-”;
clientId += String(random(0xffff), HEX);
// Attempt to connect
if (client.connect(clientId.c_str())) {
// Once connected, publish an announcement…
client.publish(MQTT_PUBLISH.c_str() , “connected”);
setrelays();
// … and resubscribe
client.subscribe(MQTT_SUBSCRIPTION.c_str());
} else {
// Wait 5 seconds before retrying
delay(5000);
}
}
}

void setup() {
Serial.begin(19200);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
client.loop();
}

void loop() {

if (!client.connected()) {
reconnect();
}
client.loop();
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

if (incomingByte == 0xA0) {
  iStep = 1;
}
else if ((iStep == 1) && (incomingByte == 0x04)) {
  iStep = 2;
}
else if ((iStep == 2) && (incomingByte >= 0) && (incomingByte <= 3)) {
  iStep = 3;
  iNewState = incomingByte;
} else if ((iStep == 3) && (incomingByte == 0xA1)) {
  iStep = 0;
  if (iNewState == 0) {
    relay1 = false;
    relay2 = false;
  }
  if (iNewState == 1) {
    relay1 = true;
    relay2 = false;
  }
  if (iNewState == 2) {
    relay1 = false;
    relay2 = true;
  }
  if (iNewState == 3) {
    relay1 = true;
    relay2 = true;
  }
  // client.publish(MQTT_PUBLISH.c_str(),String(iNewState).c_str());
  if (relay1) client.publish((MQTT_PUBLISH + "/relay1").c_str(), "1");
  else client.publish((MQTT_PUBLISH + "/relay1").c_str(), "0");

  if (relay2) client.publish((MQTT_PUBLISH + "/relay2").c_str(), "1");
  else client.publish((MQTT_PUBLISH + "/relay2").c_str(), "0");
  
} else iStep = 0;

}
}

void setrelays() {
byte b = 0;
if (relay1) b++;
if (relay2) b += 2;
Serial.write(0xA0);
Serial.write(0x04);
Serial.write(b);
Serial.write(0xA1);
Serial.flush();
if (relay1) client.publish((MQTT_PUBLISH + “/relay1”).c_str(), “1”);
else client.publish((MQTT_PUBLISH + “/relay1”).c_str(), “0”);

if (relay2) client.publish((MQTT_PUBLISH + “/relay2”).c_str(), “1”);
else client.publish((MQTT_PUBLISH + “/relay2”).c_str(), “0”);
}


(CMA) #12

Hello Eric, i have successfully flashed the sonoff dual R2 using your bin file “SonoffDual.ino.generic.bin”, the sonoff dual is now appearing on the mobile app, i can toggle the on/off of the both switches. the problem is that the relays are not actually switching!
any ideas ? thank you


(Luis Pinto) #13

Maybe this comes a little bit late but:

I hope Smartthings enable publishing apps again so we can release the integration with ST too.