Page 1 of 2

sonoff dual flashing the ESP

Posted: 26 Mar 2017, 15:02
by Dylantje
Dear all,

I wil try to flash a sonoff dual.
https://www.google.nl/search?q=sonoff+d ... 45&bih=819

I did solder 4 pins on the upper left corner on the board.
Try the flash tool and the 4096 memory...

Only i cannot write with the flashtool [ did other esp without problems ]

So is there someone that have flash this sonoff duo?
Or is there some that have a how to?
Perhaps i use the wrong pins.

Or where do i go wrong :-(

Thanks.

Re: sonoff dual flashing the ESP

Posted: 30 Mar 2017, 00:39
by Zeric
The Sonoff dual has some differences from most other sonoff devices. The one you are likely running into is the button. On most sonoff devices, the button is attached to GPIO0 making it very easy to put it in flash mode (just power up while pressing the button).

Unfortunately on the sonoff dual, the button is not attached to GPIO0, but is attached to a secondary microcontroller (Silabs C8051F330). In order to program the esp8266 on the device, one needs to bring out GPIO0 to another pin so it can be held LOW during power on to enter into the flashing mode. I did this by installing a customized 5 pin header with 4 pins that go into the board, and a fifth pin that hangs off one end with a wire going to GPIO0. This is unfortunately trickier than just soldering in a normal 4 pin header like you can do with most sonoff devices.

Once programmed, dealing with the sonoff dual requires one to interact with the secondary MCU to get anything done. Neither of the relays are simply connected to a GPIO of the esp8266, instead, they are connected to the secondary MCU so you have to instruct the secondary MCU to actuate either relay 1 or relay 2. There is some information online explaining the reverse engineered protocol. I think the only other sonoff device that works this way (with the secondary MCU) is the one with 4 relays.

Image

Image

Re: sonoff dual flashing the ESP

Posted: 30 Mar 2017, 09:17
by Shardan
Zeric wrote:
30 Mar 2017, 00:39
I think the only other Ssonoff device that works this way (with the secondary MCU) is the one with 4 relays.
For your information:
There are several sonoff devices with secondary MCU.
The Sonoff basic works with standard compiled ESPEasy without issues.

The Sonoff 4CH (4 relays) has relays and buttons connected directly to the chip.
But beware: The 4CH has an ESP 8285, not an ESP8266. This s a ESP8266 with a built-in flash
and this memory is handled a bit different.
Use the Arduino IDE to compile source code, with board manager select the ESP8285,
Sonoff 4ch inofs and schematic: https://www.itead.cc/wiki/Sonoff_4CH

I have both flashed with ESPEasy, they work nicely.

For other sonoff devices: There are some with MCU, some without.
I recommend to check the manufacturer's wiki before buying.

Regards
Shardan

Re: sonoff dual flashing the ESP

Posted: 07 Apr 2017, 09:54
by ppaciek
Anybody knows how i can configure the sonoff dual ?
I flash the firmware (ESPEasy), and i have a trouble with configuration. In Basic version the relay was on the GPIO-12, button on GPIO-0 and in Touch version - the same. Here (Dual) is different i think because something MCU inside. How i can configure this? Maybe must something rules? Maybe someone have a compilated ESPEASY firmware for Sonoff dual ?
Thanks for the answer.
Regards,
Pawel

Re: sonoff dual flashing the ESP

Posted: 07 Apr 2017, 12:34
by Shardan
The Sonoff Dual uses a separate MCU connected to the Serial Port of the ESP.
This is not supported by ESPEasy / ESPEasy Mega at this time.

Tere were some efforts already on this device, see
https://www.letscontrolit.com/forum/vie ... ual#p14685

Regards
Shardan

Re: sonoff dual flashing the ESP

Posted: 21 Apr 2017, 13:34
by MortenCopenhagen
While waiting for Sonoff DUAL support in ESP Easy I decided to install the ESPurna with sonoff DUAL on my only DUAL unit from my Windows laptop. I followed the instructions here:
https://bitbucket.org/xoseperez/espurna ... uinoIDE.md
It takes quite a while to install all the libraries and you need a minimal understanding of the arduino IDE program. You need to solder a wire to a very small resistor under the DUAL board. Not easy. This to be able to pull GPIO 0 to ground to enter flash mode. On this page: http://support.iteadstudio.com/support/ ... 1000006870 Markus Maeder has posted a picture to show you where to attach the wire. Compiling and uploading went without a problem. Compiling takes a while though. The ESPurna software also creates a temporary wifi where you need to login and setup your wifi details etc. It is working fine for me since I use my MQTT server to communicate with it. It is now 100% as useful as the other Sonoff unites I have flashed with ESP easy.
Cherrio from Copenhagen

Re: sonoff dual flashing the ESP

Posted: 09 Jun 2017, 19:26
by Dylantje
mmm what pins can i use..
First the 2 for switching
And then what pin i have left for the fun thins?

Re: sonoff dual flashing the ESP

Posted: 15 Jun 2017, 21:43
by the cosmic gate
I also bought this Sonoff dual, and try to flash serveral versions , to strart the latest Mega ( dev 10) / the ESPEASY version 147 etc , but the flashes are okay and finished 100% , but when i reboot the dual only this wil appear :

Code: Select all

[00]rl[00]lœž|[00]Œlà|[02][0C][0C][0C]Œ[0C]lì[0C]b|Ž‚[02]ì[12]’r’bl[0C]bŒònnžlnnœâì[0C]b[1C]pŒŽlrlrl[12]‚rò’nàbânbp[00]ü]

and ESP easy won''t start at all.
Also tried the whipe the eps with some " cleaning" files, but still nothing .

What's wrong , are what did i do wrong ?
Or is this the second controller on the dual that messed this up ?

Re: sonoff dual flashing the ESP

Posted: 18 Jun 2017, 21:49
by Martinus
Shardan wrote:
07 Apr 2017, 12:34
The Sonoff Dual uses a separate MCU connected to the Serial Port of the ESP.
This is not supported by ESPEasy / ESPEasy Mega at this time.

Tere were some efforts already on this device, see
https://www.letscontrolit.com/forum/vie ... ual#p14685

Regards
Shardan
So if someone pushes a plugin to the playground doing stuff like this on a WRITE command:

Code: Select all

  Serial.write(0xA0);
  Serial.write(0x04);
  Serial.write(state); 
  Serial.write(0xA1);
  Serial.flush();
we should be running fine with ESP Easy and Sonoff dual...

Re: sonoff dual flashing the ESP

Posted: 18 Jun 2017, 22:04
by Dylantje
we should be running fine with ESP Easy and Sonoff dual...
I think really there is something strange going on..

Cannot flash any Sonoff.
And i do have still running 6 esp flashed 3-4 times a few months ago without any problem...

Re: sonoff dual flashing the ESP

Posted: 19 Jun 2017, 15:53
by the cosmic gate
Martinus wrote:
18 Jun 2017, 21:49
Shardan wrote:
07 Apr 2017, 12:34
The Sonoff Dual uses a separate MCU connected to the Serial Port of the ESP.
This is not supported by ESPEasy / ESPEasy Mega at this time.

Tere were some efforts already on this device, see
https://www.letscontrolit.com/forum/vie ... ual#p14685

Regards
Shardan
So if someone pushes a plugin to the playground doing stuff like this on a WRITE command:

Code: Select all

  Serial.write(0xA0);
  Serial.write(0x04);
  Serial.write(state); 
  Serial.write(0xA1);
  Serial.flush();
we should be running fine with ESP Easy and Sonoff dual...
As i can read out , they use the some in the Tasmosta sketches :

Code: Select all

  if ((SONOFF_DUAL == sysCfg.module) || (CH4 == sysCfg.module)) {
    Serial.write(0xA0);
    Serial.write(0x04);
    Serial.write(rpower);
    Serial.write(0xA1);
    Serial.write('\n');
    Serial.flush();
    
could somebody transfer this to a playground plugin ?

Re: sonoff dual flashing the ESP

Posted: 19 Jun 2017, 17:47
by papperone
Martinus wrote:
18 Jun 2017, 21:49
Shardan wrote:
07 Apr 2017, 12:34
The Sonoff Dual uses a separate MCU connected to the Serial Port of the ESP.
This is not supported by ESPEasy / ESPEasy Mega at this time.

Tere were some efforts already on this device, see
https://www.letscontrolit.com/forum/vie ... ual#p14685

Regards
Shardan
So if someone pushes a plugin to the playground doing stuff like this on a WRITE command:

Code: Select all

  Serial.write(0xA0);
  Serial.write(0x04);
  Serial.write(state); 
  Serial.write(0xA1);
  Serial.flush();
we should be running fine with ESP Easy and Sonoff dual...
It seems an easy one but do we know the meaning of the bits in the "state" byte? (I mean which bit turns on/off which relay?)
Knowing just that info shoudl be very easy to write a plugin that simply writes to the serial...

Re: sonoff dual flashing the ESP

Posted: 19 Jun 2017, 18:30
by Martinus

Re: sonoff dual flashing the ESP

Posted: 19 Jun 2017, 21:45
by bryan
I've created a plugin to switch the Sonoff Dual and that part is working fine,
but I also want the esp easy to reset the switches in domoticz when the Sonoff dual has been powered off.

I can't get this to work currently.

Where can I find information how to update domoticz on boot?

Regards,

Bryan

Re: sonoff dual flashing the ESP

Posted: 19 Jun 2017, 23:12
by Dylantje
Guys..
I am a Bob the Builder..
I was a hero when i flashed my first esp...
And my dual...

Only hope there is after a time wiki where i can see how i must acting...
This id for me higher math..

xxx
Love

Re: sonoff dual flashing the ESP

Posted: 20 Jun 2017, 01:40
by enesbcs
I have created a plugin for a serial MCU controlled switch, which in theory could work with Sonoff Dual.. if anyone interested in testing. :) Serial MCU controlled switch plugin (beta dev)

Re: sonoff dual flashing the ESP

Posted: 20 Jun 2017, 14:21
by robert324
The Sonoff Dual uses a separate MCU connected to the Serial Port of the ESP.
This is not supported by ESPEasy / ESPEasy Mega at this time

Re: sonoff dual flashing the ESP

Posted: 26 Jun 2017, 10:27
by bryan
Hi,

Here is the plugin code I used for the Sonoff dual.
Had no time to learn/use github.
Plugin number is also probably already used.
Save the code as .ino file and compile esp easy using the guide.

The command Sonoff1 is for the first switch, Sonoff2 for the second.
EG.
http://192.168.0.50/control?cmd=Sonoff2,1
turns switch 2 on
http://192.168.0.50/control?cmd=Sonoff2,0
turns switch2 off.

To reset the state in domoticz after reboot, use rules:

On System#Boot do
timerSet,1,10
endon

On Rules#Timer=1 do
SendToHTTP 192.168.0.xxx,8080,/json.htm?type=command&param=switchlight&idx=11&switchcmd=Off
SendToHTTP 192.168.0.xxx,8080,/json.htm?type=command&param=switchlight&idx=12&switchcmd=Off
endon

Turn off serial on the advanced menu.

Regards,

Bryan

Code: Select all

//#######################################################################################################
//################################# Plugin 101: SONOFF Dual Switch ######################################
//#######################################################################################################

#define PLUGIN_101
#define PLUGIN_ID_101         101
#define PLUGIN_NAME_101       "Sonoff dual"
#define PLUGIN_VALUENAME1_101 "SonoffDual"

boolean Plugin_101(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;
  static byte switchstate[TASKS_MAX];
  static byte outputstate[TASKS_MAX];

  switch (function)
  {
    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_101;
        Device[deviceCount].Type = DEVICE_TYPE_DUMMY;
        Device[deviceCount].VType = SENSOR_TYPE_SWITCH;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].GlobalSyncOption = true;
        break;
      }

    case PLUGIN_GET_DEVICENAME:
      {
        string = F(PLUGIN_NAME_101);
        break;
      }

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_101));
        break;
      }

    case PLUGIN_WEBFORM_LOAD:
      {

        addFormCheckBox(string, F("Send Boot state"),F("plugin_101_boot"),
            Settings.TaskDevicePluginConfig[event->TaskIndex][0]);

        success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        Settings.TaskDevicePluginConfig[event->TaskIndex][0] = isFormItemChecked(F("plugin_101_boot"));

        success = true;
        break;
      }

    case PLUGIN_INIT:
      {
        UserVar[event->BaseVarIndex] = 0;
        success = true;
        break;
      }

    case PLUGIN_WRITE:
      {
        String log = "";
        String command = parseString(string, 1);
        int switchstate = UserVar[event->BaseVarIndex];
        if (command == F("sonoff1"))
        {
          success = true;
          if (event->Par1 >= 0 && event->Par1 <= 1)
          {
            Serial.begin(19200);
            Serial.write(0xA0);
            Serial.write(0x04);
              if (event->Par1 == 0)
              {
                switch (switchstate)
                {
                  case 0:
                  {
                    Serial.write(0x00);
                    break;
                  }

                  case 1:
                  {
                    Serial.write(0x00); 
                    UserVar[event->BaseVarIndex]= 0;
                    break;                  
                  }

                  case 2:
                  {
                    Serial.write(0x02); 
                    break;                  
                  }

                  case 3:
                  {
                    Serial.write(0x02); 
                    UserVar[event->BaseVarIndex]= 2;
                    break;                  
                  }
                }
              }
              if (event->Par1 == 1)
              {
                switch (switchstate)
                {
                  case 0:
                  {
                    Serial.write(0x01); 
                    UserVar[event->BaseVarIndex]= 1;
                    break;
                  }

                  case 1:
                  {
                    Serial.write(0x01); 
                    break;                  
                  }

                  case 2:
                  {
                    Serial.write(0x03); 
                    UserVar[event->BaseVarIndex]= 3;
                    break;                  
                  }

                  case 3:
                  {
                    Serial.write(0x03); 
                    UserVar[event->BaseVarIndex]= 3;
                    break;                  
                  }
                }
              }
            Serial.write(0xA1);
            Serial.flush();
            log = String(F("SW   : Sonoff 1 Set to ")) + String(event->Par1) + String(F(" UserVar Set to ")) + String(UserVar[event->BaseVarIndex]);
            addLog(LOG_LEVEL_INFO, log);
            printToWebJSON = true;
            String reply = String(F("{\"log\": \"Sonoff Switch 1 state = ")) + String(event->Par1) + String(F("\",\"plugin\": 101,\"switch\": 1,\"mode\": \"output\",\"state\": ")) + String(event->Par1) + String(F(" }"));
            SendStatus(event->Source, reply);
          }
        }

        if (command == F("sonoff2"))
        {
          success = true;
          if (event->Par1 >= 0 && event->Par1 <= 1)
          {
            Serial.begin(19200);
            Serial.write(0xA0);
            Serial.write(0x04);
              if (event->Par1 == 0)
              {
                switch (switchstate)
                {
                  case 0:
                  {
                    Serial.write(0x00);
                    break;
                  }

                  case 1:
                  {
                    Serial.write(0x01); 
                    break;                  
                  }

                  case 2:
                  {
                    Serial.write(0x00); 
                    UserVar[event->BaseVarIndex]= 0;
                    break;                  
                  }

                  case 3:
                  {
                    Serial.write(0x01); 
                    UserVar[event->BaseVarIndex]= 1;
                    break;                  
                  }
                }
              }
              if (event->Par1 == 1)
              {
                switch (switchstate)
                {
                  case 0:
                  {
                    Serial.write(0x02); 
                    UserVar[event->BaseVarIndex]= 2;
                    break;
                  }

                  case 1:
                  {
                    Serial.write(0x03); 
                    UserVar[event->BaseVarIndex]= 3;
                    break;                  
                  }

                  case 2:
                  {
                    Serial.write(0x02); 
                    break;                  
                  }

                  case 3:
                  {
                    Serial.write(0x03); 
                    break;                  
                  }
                }
              }
            Serial.write(0xA1);
            Serial.flush();
            log = String(F("SW   : Sonoff 2 Set to ")) + String(event->Par1) + String(F(" UserVar Set to ")) + String(UserVar[event->BaseVarIndex]);
            addLog(LOG_LEVEL_INFO, log);
            printToWebJSON = true;
            String reply = String(F("{\"log\": \"Sonoff Switch 2 state = ")) + String(event->Par1) + String(F("\",\"plugin\": 101,\"switch\": 2,\"mode\": \"output\",\"state\": ")) + String(event->Par1) + String(F(" }"));
            SendStatus(event->Source, reply);
          }
        }

        break;
      }

  }
  return success;
}
Compiled with ESP-Easy mega code from github:
ESPEasy.ino.zip
(357.7 KiB) Downloaded 179 times

Re: sonoff dual flashing the ESP

Posted: 27 Jun 2017, 21:35
by the cosmic gate
bryan wrote:
26 Jun 2017, 10:27
Hi,

Here is the plugin code I used for the Sonoff dual.
Had no time to learn/use github.
Plugin number is also probably already used.
Save the code as .ino file and compile esp easy using the guide.

The command Sonoff1 is for the first switch, Sonoff2 for the second.
EG.
http://192.168.0.50/control?cmd=Sonoff2,1
turns switch 2 on
http://192.168.0.50/control?cmd=Sonoff2,0
turns switch2 off.

To reset the state in domoticz after reboot, use rules:

On System#Boot do
timerSet,1,10
endon

On Rules#Timer=1 do
SendToHTTP 192.168.0.xxx,8080,/json.htm?type=command&param=switchlight&idx=11&switchcmd=Off
SendToHTTP 192.168.0.xxx,8080,/json.htm?type=command&param=switchlight&idx=12&switchcmd=Off
endon

Turn off serial on the advanced menu.

Regards,

Bryan
Thnx for the plugin
Maybe this is more clean :

Code: Select all

//#######################################################################################################
//################################# Plugin 101: SONOFF Dual Switch ######################################
//#######################################################################################################

#define PLUGIN_101
#define PLUGIN_ID_101 101
#define PLUGIN_NAME_101 "Sonoff dual"
#define PLUGIN_VALUENAME1_101 "SonoffDual"

boolean Plugin_101(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
static byte switchstate[TASKS_MAX];
static byte outputstate[TASKS_MAX];

switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_101;
Device[deviceCount].Type = DEVICE_TYPE_DUMMY;
Device[deviceCount].VType = SENSOR_TYPE_SWITCH;
Device[deviceCount].Ports = 0;
Device[deviceCount].GlobalSyncOption = true;
break;
}

case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_101);
break;
}

case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_101));
break;
}

case PLUGIN_WEBFORM_LOAD:
{

addFormCheckBox(string, F("Send Boot state"),F("plugin_101_boot"),
Settings.TaskDevicePluginConfig[event->TaskIndex][0]);

success = true;
break;
}

case PLUGIN_WEBFORM_SAVE:
{
Settings.TaskDevicePluginConfig[event->TaskIndex][0] = isFormItemChecked(F("plugin_101_boot"));

success = true;
break;
}

case PLUGIN_INIT:
{
UserVar[event->BaseVarIndex] = 0;
success = true;
break;
}

case PLUGIN_WRITE:
{
String log = "";
String command = parseString(string, 1);
int switchstate = UserVar[event->BaseVarIndex];
if (command == F("sonoff1"))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= 1)
{
Serial.begin(19200);
Serial.write(0xA0);
Serial.write(0x04);
if (event->Par1 == 0)
{
switch (switchstate)
{
case 0:
{
Serial.write(0x00);
break;
}

case 1:
{
Serial.write(0x00); 
UserVar[event->BaseVarIndex]= 0;
break; 
}

case 2:
{
Serial.write(0x02); 
break; 
}

case 3:
{
Serial.write(0x02); 
UserVar[event->BaseVarIndex]= 2;
break; 
}
}
}
if (event->Par1 == 1)
{
switch (switchstate)
{
case 0:
{
Serial.write(0x01); 
UserVar[event->BaseVarIndex]= 1;
break;
}

case 1:
{
Serial.write(0x01); 
break; 
}

case 2:
{
Serial.write(0x03); 
UserVar[event->BaseVarIndex]= 3;
break; 
}

case 3:
{
Serial.write(0x03); 
UserVar[event->BaseVarIndex]= 3;
break; 
}
}
}
Serial.write(0xA1);
Serial.flush();
log = String(F("SW : Sonoff 1 Set to ")) + String(event->Par1) + String(F(" UserVar Set to ")) + String(UserVar[event->BaseVarIndex]);
addLog(LOG_LEVEL_INFO, log);
printToWebJSON = true;
String reply = String(F("{\"log\": \"Sonoff Switch 1 state = ")) + String(event->Par1) + String(F("\",\"plugin\": 101,\"switch\": 1,\"mode\": \"output\",\"state\": ")) + String(event->Par1) + String(F(" }"));
SendStatus(event->Source, reply);
}
}

if (command == F("sonoff2"))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= 1)
{
Serial.begin(19200);
Serial.write(0xA0);
Serial.write(0x04);
if (event->Par1 == 0)
{
switch (switchstate)
{
case 0:
{
Serial.write(0x00);
break;
}

case 1:
{
Serial.write(0x01); 
break; 
}

case 2:
{
Serial.write(0x00); 
UserVar[event->BaseVarIndex]= 0;
break; 
}

case 3:
{
Serial.write(0x01); 
UserVar[event->BaseVarIndex]= 1;
break; 
}
}
}
if (event->Par1 == 1)
{
switch (switchstate)
{
case 0:
{
Serial.write(0x02); 
UserVar[event->BaseVarIndex]= 2;
break;
}

case 1:
{
Serial.write(0x03); 
UserVar[event->BaseVarIndex]= 3;
break; 
}

case 2:
{
Serial.write(0x02); 
break; 
}

case 3:
{
Serial.write(0x03); 
break; 
}
}
}
Serial.write(0xA1);
Serial.flush();
log = String(F("SW : Sonoff 2 Set to ")) + String(event->Par1) + String(F(" UserVar Set to ")) + String(UserVar[event->BaseVarIndex]);
addLog(LOG_LEVEL_INFO, log);
printToWebJSON = true;
String reply = String(F("{\"log\": \"Sonoff Switch 2 state = ")) + String(event->Par1) + String(F("\",\"plugin\": 101,\"switch\": 2,\"mode\": \"output\",\"state\": ")) + String(event->Par1) + String(F(" }"));
SendStatus(event->Source, reply);
}
}

break;
}

}
return success;
}
Could you post a compiled *.bin ? Becasue i've got some compile troubles ;)

Re: sonoff dual flashing the ESP

Posted: 28 Jun 2017, 20:15
by enesbcs
bryan wrote:
26 Jun 2017, 10:27
Hi,

Here is the plugin code I used for the Sonoff dual.
Had no time to learn/use github.
Plugin number is also probably already used.
Hi,

If you own a Sonoff Dual could you try my serial plugin someday? In theory it has to be working, but i only have the other switch to test (Yewelink) which is working similarly but with different serial command codes.

And on the Domoticz side, how can you use the the two relays independently? I'm using two separated dummy switch with unique IDX, which i can put on the domoticz floorplan, and replacing the URL actions...

first relay:
http://ESPEASY_IP/control?cmd=relay,0,1
http://ESPEASY_IP/control?cmd=relay,0,0
the second:
http://ESPEASY_IP/control?cmd=relay,1,1
http://ESPEASY_IP/control?cmd=relay,1,0

(fresh source and binary uploaded to first post here: viewtopic.php?f=6&t=3245 )

Re: sonoff dual flashing the ESP

Posted: 29 Jun 2017, 19:03
by bryan
Hi enebcs,

All my sonoff duals are in use, but I see on the output off your serial plugin on an esp that it will not work with the sonoff dual.
When sending the on command to relay 1, I don't see anything on the serial.

I've also use 2 dummy switches on the domoticz side and only use the URL actions to switch the relays.
Use command Sonoff1 for the first relay and Sonoff2 for the second.
eg. to turn relay 2 on: http://192.168.0.50/control?cmd=Sonoff2,1
off: http://192.168.0.50/control?cmd=Sonoff2,0

I don't see the reason to add multiple serial devices in 1 plugin, especially since they seem to work differently..

If you want to use Sonoff dual, you can use the plugin I wrote.
Works like a charm (I'm using 3 at the moment), without the difficult setup ;-)

Re: sonoff dual flashing the ESP

Posted: 02 Jul 2017, 19:36
by the cosmic gate
bryan wrote:
29 Jun 2017, 19:03
Hi enebcs,

All my sonoff duals are in use, but I see on the output off your serial plugin on an esp that it will not work with the sonoff dual.
When sending the on command to relay 1, I don't see anything on the serial.

I've also use 2 dummy switches on the domoticz side and only use the URL actions to switch the relays.
Use command Sonoff1 for the first relay and Sonoff2 for the second.
eg. to turn relay 2 on: http://192.168.0.50/control?cmd=Sonoff2,1
off: http://192.168.0.50/control?cmd=Sonoff2,0

I don't see the reason to add multiple serial devices in 1 plugin, especially since they seem to work differently..

If you want to use Sonoff dual, you can use the plugin I wrote.
Works like a charm (I'm using 3 at the moment), without the difficult setup ;-)
This plugin is working fine, but is there way to send the relais state to domoticz ?
Normaly you can use a "switch " devicee to read and send the state, but know this (logicaly) doesnt work

Re: sonoff dual flashing the ESP

Posted: 08 Jul 2017, 13:09
by bryan
Hi cosmic gate,

I've made some changes to the code, so it will send the state to the controller.
I haven't been able to test it, as my sonoff duals are all in use.

There are also a few side effects which I can't eliminate at the moment. The attached binary doesn't have these side effects (see below).

When you change the switch from domoticz, it will be switched on/off twice (as you can see in the domoticz log).
When you change the switch from a url, it will be switched on/off twice (as you can see in the esp log).

Code: Select all

//#######################################################################################################
//################################# Plugin 101: SONOFF Dual Switch ######################################
//#######################################################################################################

#define PLUGIN_101
#define PLUGIN_ID_101         101
#define PLUGIN_NAME_101       "Sonoff dual"
#define PLUGIN_VALUENAME1_101 "SonoffDual"
int switchstate,senddata;

boolean Plugin_101(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;

  switch (function)
  {
    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_101;
        Device[deviceCount].Type = DEVICE_TYPE_DUMMY;
        Device[deviceCount].VType = SENSOR_TYPE_SWITCH;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].ValueCount = 0;
        Device[deviceCount].SendDataOption = false;
        Device[deviceCount].GlobalSyncOption = true;
        break;
      }

    case PLUGIN_GET_DEVICENAME:
      {
        string = F(PLUGIN_NAME_101);
        break;
      }

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_101));
        break;
      }

    case PLUGIN_WEBFORM_LOAD:
      {
            addFormNumericBox(string, F("Sonoff Dual IDX1"), F("IDX1"), ExtraTaskSettings.TaskDevicePluginConfigLong[0]);
            addFormNumericBox(string, F("Sonoff Dual IDX2"), F("IDX2"), ExtraTaskSettings.TaskDevicePluginConfigLong[1]);
            addFormCheckBox(string, F("Send to controller"),F("plugin_101_sendtocontroller"),
            Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
        success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        ExtraTaskSettings.TaskDevicePluginConfigLong[0] = getFormItemInt(F("IDX1"));
        ExtraTaskSettings.TaskDevicePluginConfigLong[1] = getFormItemInt(F("IDX2"));
        Settings.TaskDevicePluginConfig[event->TaskIndex][0] = isFormItemChecked(F("plugin_101_sendtocontroller"));

        success = true;
        break;
      }

    case PLUGIN_INIT:
      {
        UserVar[event->BaseVarIndex] = 0;
        switchstate = 0;
        senddata=0;
        success = true;
        break;
      }

    case PLUGIN_WRITE:
      {
        String log = "";
        String command = parseString(string, 1);
        if (command == F("sonoff1"))
        {
          success = true;
          if (event->Par1 >= 0 && event->Par1 <= 1)
          {
            Serial.begin(19200);
            Serial.write(0xA0);
            Serial.write(0x04);
              if (event->Par1 == 0)
              {
                switch (switchstate)
                {
                  case 0:
                  {
                    Serial.write(0x00);
                    switchstate = 0;
                    break;
                  }

                  case 1:
                  {
                    Serial.write(0x00); 
                    UserVar[event->BaseVarIndex]= 0;
                    switchstate = 0;
                    senddata=1;
                    break;                  
                  }

                  case 2:
                  {
                    Serial.write(0x02); 
                    switchstate = 2;
                    break;                  
                  }

                  case 3:
                  {
                    Serial.write(0x02); 
                    UserVar[event->BaseVarIndex]= 0;
                    switchstate = 2;
                    senddata=1;
                    break;                  
                  }
                }
              }
              if (event->Par1 == 1)
              {
                switch (switchstate)
                {
                  case 0:
                  {
                    Serial.write(0x01); 
                    UserVar[event->BaseVarIndex]= 1;
                    switchstate = 1;
                    senddata=1;
                    break;
                  }

                  case 1:
                  {
                    Serial.write(0x01); 
                    switchstate = 1;
                    break;                  
                  }

                  case 2:
                  {
                    Serial.write(0x03); 
                    UserVar[event->BaseVarIndex]= 1;
                    switchstate = 3;
                    senddata=1;
                    break;                  
                  }

                  case 3:
                  {
                    Serial.write(0x03); 
                    UserVar[event->BaseVarIndex]= 1;
                    switchstate = 3;
                    break;                  
                  }
                }
              }
            Serial.write(0xA1);
            Serial.flush();
            log = String(F("SW   : Sonoff 1 Set to ")) + String(event->Par1) + String(F(" switchstate Set to ")) + String(switchstate);
            addLog(LOG_LEVEL_INFO, log);
            printToWebJSON = true;
            String reply = String(F("{\"log\": \"Sonoff Switch 1 state = ")) + String(event->Par1) + String(F("\",\"plugin\": 101,\"switch\": 1,\"mode\": \"output\",\"state\": ")) + String(event->Par1) + String(F(" }"));
            SendStatus(event->Source, reply);
            Settings.TaskDeviceID[0][event->TaskIndex] = ExtraTaskSettings.TaskDevicePluginConfigLong[0];
            event->sensorType = SENSOR_TYPE_SWITCH;
            if (senddata && Settings.TaskDevicePluginConfig[event->TaskIndex][0]){
              Settings.TaskDeviceSendData[0][event->TaskIndex] = 1;
              Settings.TaskDeviceSendData[1][event->TaskIndex] = 1;
              Settings.TaskDeviceSendData[2][event->TaskIndex] = 1;
              sendData(event);
              senddata=0;
            }
          }
        }
        if (command == F("sonoff2"))
        {
          success = true;
          if (event->Par1 >= 0 && event->Par1 <= 1)
          {
            Serial.begin(19200);
            Serial.write(0xA0);
            Serial.write(0x04);
              if (event->Par1 == 0)
              {
                switch (switchstate)
                {
                  case 0:
                  {
                    Serial.write(0x00);
                    switchstate = 0;
                    break;
                  }

                  case 1:
                  {
                    Serial.write(0x01); 
                    switchstate = 1;
                    break;                  
                  }

                  case 2:
                  {
                    Serial.write(0x00); 
                    UserVar[event->BaseVarIndex]= 0;
                    switchstate = 0;
                    senddata=1;
                    break;                  
                  }

                  case 3:
                  {
                    Serial.write(0x01); 
                    UserVar[event->BaseVarIndex]= 0;
                    switchstate = 1;
                    senddata=1;
                    break;                  
                  }
                }
              }
              if (event->Par1 == 1)
              {
                switch (switchstate)
                {
                  case 0:
                  {
                    Serial.write(0x02); 
                    UserVar[event->BaseVarIndex]= 1;
                    switchstate = 2;
                    senddata=1;
                    break;
                  }

                  case 1:
                  {
                    Serial.write(0x03); 
                    UserVar[event->BaseVarIndex]= 1;
                    switchstate = 3;
                    senddata=1;
                    break;                  
                  }

                  case 2:
                  {
                    Serial.write(0x02); 
                    switchstate = 2;
                    break;                  
                  }

                  case 3:
                  {
                    Serial.write(0x03); 
                    switchstate = 3;
                    break;                  
                  }
                }
              }
            Serial.write(0xA1);
            Serial.flush();
            log = String(F("SW   : Sonoff 2 Set to ")) + String(event->Par1) + String(F(" switchstate Set to ")) + String(switchstate);
            addLog(LOG_LEVEL_INFO, log);
            printToWebJSON = true;
            String reply = String(F("{\"log\": \"Sonoff Switch 2 state = ")) + String(event->Par1) + String(F("\",\"plugin\": 102,\"switch\": 2,\"mode\": \"output\",\"state\": ")) + String(event->Par1) + String(F(" }"));
            SendStatus(event->Source, reply);
            Settings.TaskDeviceID[0][event->TaskIndex] = ExtraTaskSettings.TaskDevicePluginConfigLong[1];
            event->sensorType = SENSOR_TYPE_SWITCH;
            if (senddata && Settings.TaskDevicePluginConfig[event->TaskIndex][0]){
              Settings.TaskDeviceSendData[0][event->TaskIndex] = 1;
              Settings.TaskDeviceSendData[1][event->TaskIndex] = 1;
              Settings.TaskDeviceSendData[2][event->TaskIndex] = 1;
              sendData(event);
              senddata=0;
            }
          }
        }
        break;
      }

  }
  return success;
}
I think it is the best I can do at the moment without changing the esp code (only the plugin).

To reset the state in domoticz after reboot, use rules (and change the idx and ip address):

On System#Boot do
timerSet,1,10
endon

On Rules#Timer=1 do
SendToHTTP 192.168.0.xxx,8080,/json.htm?type=command&param=udevice&idx=11&nvalue=0
SendToHTTP 192.168.0.xxx,8080,/json.htm?type=command&param=udevice&idx=12&nvalue=0
endon

Turn off serial on the advanced menu.

The attached binary does have a slightly adjusted core code. This binary does not have the side effects that the switch is changed twice.
SonoffDual.zip
added OTA version
(723.66 KiB) Downloaded 264 times
Compiled with source from github.

If you want to compile yourself, here are the changed files:
ESPEasy.zip
(13.48 KiB) Downloaded 200 times
Regards,

Bryan

Re: sonoff dual flashing the ESP

Posted: 16 Jul 2017, 10:39
by the cosmic gate
bryan wrote:
08 Jul 2017, 13:09
Hi cosmic gate,

I've made some changes to the code, so it will send the state to the controller.
I haven't been able to test it, as my sonoff duals are all in use.

There are also a few side effects which I can't eliminate at the moment. The attached binary doesn't have these side effects (see below).

When you change the switch from domoticz, it will be switched on/off twice (as you can see in the domoticz log).
When you change the switch from a url, it will be switched on/off twice (as you can see in the esp log).

Code: Select all

//#######################################################################################################
//################################# Plugin 101: SONOFF Dual Switch ######################################
//#######################################################################################################

#define PLUGIN_101
#define PLUGIN_ID_101         101
#define PLUGIN_NAME_101       "Sonoff dual"
#define PLUGIN_VALUENAME1_101 "SonoffDual"
int switchstate,senddata;

boolean Plugin_101(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;

  switch (function)
  {
    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_101;
        Device[deviceCount].Type = DEVICE_TYPE_DUMMY;
        Device[deviceCount].VType = SENSOR_TYPE_SWITCH;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].ValueCount = 0;
        Device[deviceCount].SendDataOption = false;
        Device[deviceCount].GlobalSyncOption = true;
        break;
      }

    case PLUGIN_GET_DEVICENAME:
      {
        string = F(PLUGIN_NAME_101);
        break;
      }

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_101));
        break;
      }

    case PLUGIN_WEBFORM_LOAD:
      {
            addFormNumericBox(string, F("Sonoff Dual IDX1"), F("IDX1"), ExtraTaskSettings.TaskDevicePluginConfigLong[0]);
            addFormNumericBox(string, F("Sonoff Dual IDX2"), F("IDX2"), ExtraTaskSettings.TaskDevicePluginConfigLong[1]);
            addFormCheckBox(string, F("Send to controller"),F("plugin_101_sendtocontroller"),
            Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
        success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        ExtraTaskSettings.TaskDevicePluginConfigLong[0] = getFormItemInt(F("IDX1"));
        ExtraTaskSettings.TaskDevicePluginConfigLong[1] = getFormItemInt(F("IDX2"));
        Settings.TaskDevicePluginConfig[event->TaskIndex][0] = isFormItemChecked(F("plugin_101_sendtocontroller"));

        success = true;
        break;
      }

    case PLUGIN_INIT:
      {
        UserVar[event->BaseVarIndex] = 0;
        switchstate = 0;
        senddata=0;
        success = true;
        break;
      }

    case PLUGIN_WRITE:
      {
        String log = "";
        String command = parseString(string, 1);
        if (command == F("sonoff1"))
        {
          success = true;
          if (event->Par1 >= 0 && event->Par1 <= 1)
          {
            Serial.begin(19200);
            Serial.write(0xA0);
            Serial.write(0x04);
              if (event->Par1 == 0)
              {
                switch (switchstate)
                {
                  case 0:
                  {
                    Serial.write(0x00);
                    switchstate = 0;
                    break;
                  }

                  case 1:
                  {
                    Serial.write(0x00); 
                    UserVar[event->BaseVarIndex]= 0;
                    switchstate = 0;
                    senddata=1;
                    break;                  
                  }

                  case 2:
                  {
                    Serial.write(0x02); 
                    switchstate = 2;
                    break;                  
                  }

                  case 3:
                  {
                    Serial.write(0x02); 
                    UserVar[event->BaseVarIndex]= 0;
                    switchstate = 2;
                    senddata=1;
                    break;                  
                  }
                }
              }
              if (event->Par1 == 1)
              {
                switch (switchstate)
                {
                  case 0:
                  {
                    Serial.write(0x01); 
                    UserVar[event->BaseVarIndex]= 1;
                    switchstate = 1;
                    senddata=1;
                    break;
                  }

                  case 1:
                  {
                    Serial.write(0x01); 
                    switchstate = 1;
                    break;                  
                  }

                  case 2:
                  {
                    Serial.write(0x03); 
                    UserVar[event->BaseVarIndex]= 1;
                    switchstate = 3;
                    senddata=1;
                    break;                  
                  }

                  case 3:
                  {
                    Serial.write(0x03); 
                    UserVar[event->BaseVarIndex]= 1;
                    switchstate = 3;
                    break;                  
                  }
                }
              }
            Serial.write(0xA1);
            Serial.flush();
            log = String(F("SW   : Sonoff 1 Set to ")) + String(event->Par1) + String(F(" switchstate Set to ")) + String(switchstate);
            addLog(LOG_LEVEL_INFO, log);
            printToWebJSON = true;
            String reply = String(F("{\"log\": \"Sonoff Switch 1 state = ")) + String(event->Par1) + String(F("\",\"plugin\": 101,\"switch\": 1,\"mode\": \"output\",\"state\": ")) + String(event->Par1) + String(F(" }"));
            SendStatus(event->Source, reply);
            Settings.TaskDeviceID[0][event->TaskIndex] = ExtraTaskSettings.TaskDevicePluginConfigLong[0];
            event->sensorType = SENSOR_TYPE_SWITCH;
            if (senddata && Settings.TaskDevicePluginConfig[event->TaskIndex][0]){
              Settings.TaskDeviceSendData[0][event->TaskIndex] = 1;
              Settings.TaskDeviceSendData[1][event->TaskIndex] = 1;
              Settings.TaskDeviceSendData[2][event->TaskIndex] = 1;
              sendData(event);
              senddata=0;
            }
          }
        }
        if (command == F("sonoff2"))
        {
          success = true;
          if (event->Par1 >= 0 && event->Par1 <= 1)
          {
            Serial.begin(19200);
            Serial.write(0xA0);
            Serial.write(0x04);
              if (event->Par1 == 0)
              {
                switch (switchstate)
                {
                  case 0:
                  {
                    Serial.write(0x00);
                    switchstate = 0;
                    break;
                  }

                  case 1:
                  {
                    Serial.write(0x01); 
                    switchstate = 1;
                    break;                  
                  }

                  case 2:
                  {
                    Serial.write(0x00); 
                    UserVar[event->BaseVarIndex]= 0;
                    switchstate = 0;
                    senddata=1;
                    break;                  
                  }

                  case 3:
                  {
                    Serial.write(0x01); 
                    UserVar[event->BaseVarIndex]= 0;
                    switchstate = 1;
                    senddata=1;
                    break;                  
                  }
                }
              }
              if (event->Par1 == 1)
              {
                switch (switchstate)
                {
                  case 0:
                  {
                    Serial.write(0x02); 
                    UserVar[event->BaseVarIndex]= 1;
                    switchstate = 2;
                    senddata=1;
                    break;
                  }

                  case 1:
                  {
                    Serial.write(0x03); 
                    UserVar[event->BaseVarIndex]= 1;
                    switchstate = 3;
                    senddata=1;
                    break;                  
                  }

                  case 2:
                  {
                    Serial.write(0x02); 
                    switchstate = 2;
                    break;                  
                  }

                  case 3:
                  {
                    Serial.write(0x03); 
                    switchstate = 3;
                    break;                  
                  }
                }
              }
            Serial.write(0xA1);
            Serial.flush();
            log = String(F("SW   : Sonoff 2 Set to ")) + String(event->Par1) + String(F(" switchstate Set to ")) + String(switchstate);
            addLog(LOG_LEVEL_INFO, log);
            printToWebJSON = true;
            String reply = String(F("{\"log\": \"Sonoff Switch 2 state = ")) + String(event->Par1) + String(F("\",\"plugin\": 102,\"switch\": 2,\"mode\": \"output\",\"state\": ")) + String(event->Par1) + String(F(" }"));
            SendStatus(event->Source, reply);
            Settings.TaskDeviceID[0][event->TaskIndex] = ExtraTaskSettings.TaskDevicePluginConfigLong[1];
            event->sensorType = SENSOR_TYPE_SWITCH;
            if (senddata && Settings.TaskDevicePluginConfig[event->TaskIndex][0]){
              Settings.TaskDeviceSendData[0][event->TaskIndex] = 1;
              Settings.TaskDeviceSendData[1][event->TaskIndex] = 1;
              Settings.TaskDeviceSendData[2][event->TaskIndex] = 1;
              sendData(event);
              senddata=0;
            }
          }
        }
        break;
      }

  }
  return success;
}
I think it is the best I can do at the moment without changing the esp code (only the plugin).

To reset the state in domoticz after reboot, use rules (and change the idx and ip address):

On System#Boot do
timerSet,1,10
endon

On Rules#Timer=1 do
SendToHTTP 192.168.0.xxx,8080,/json.htm?type=command&param=udevice&idx=11&nvalue=0
SendToHTTP 192.168.0.xxx,8080,/json.htm?type=command&param=udevice&idx=12&nvalue=0
endon

Turn off serial on the advanced menu.

The attached binary does have a slightly adjusted core code. This binary does not have the side effects that the switch is changed twice.
SonoffDual.zip
Compiled with source from github.

If you want to compile yourself, here are the changed files:
ESPEasy.zip

Regards,

Bryan
Works like a charm , after some flash troubles ( because of the 1mb memory i had to ftdi flash this to get it running) .
Also the new colors of the ESPEasy interface are better then the default blue :P

Re: sonoff dual flashing the ESP

Posted: 06 Aug 2017, 14:54
by countcobolt
Hi all

maybe a stupid Q, but can I use the sonoff1 id in the rules? I want to make sure that I shut off sonoff1 when enabling sonoff 2 (using this to turn my blinds up and down.)
Also, don't know if this is due to the firmware, but setting a static IP, locks the sonoff and I need to reflash it.

Kind regards
Steve

Re: sonoff dual flashing the ESP

Posted: 06 Aug 2017, 15:00
by LisaM
countcobolt wrote:
06 Aug 2017, 14:54
Hi all

maybe a stupid Q, but can I use the sonoff1 id in the rules? I want to make sure that I shut off sonoff1 when enabling sonoff 2 (using this to turn my blinds up and down.)
Also, don't know if this is due to the firmware, but setting a static IP, locks the sonoff and I need to reflash it.

Kind regards
Steve
https://www.letscontrolit.com/wiki/inde ... GlobalSync

Re: sonoff dual flashing the ESP

Posted: 07 Aug 2017, 11:25
by countcobolt
Hi LisaM,

I am already using global sync, but all my sensors and controllers are not DHCP and sit in a different IP range. I can set a static IP on the other Espeasy's so was wondering if this is due to this?

Anyone who can tell me how to use the sonoff1 / sonoff2 in rules?

Kind regards

Steve

Re: sonoff dual flashing the ESP

Posted: 07 Aug 2017, 18:48
by bryan
countcobolt wrote:
07 Aug 2017, 11:25
Hi LisaM,

I am already using global sync, but all my sensors and controllers are not DHCP and sit in a different IP range. I can set a static IP on the other Espeasy's so was wondering if this is due to this?

Anyone who can tell me how to use the sonoff1 / sonoff2 in rules?

Kind regards

Steve
Hi Steve,
You can try to add a custom event and then call sonoff1 or sonoff2 from there.
Never tried it myself though.
See http call: https://www.letscontrolit.com/wiki/inde ... rial_Rules
Cheers,
Bryan

Re: sonoff dual flashing the ESP

Posted: 08 Aug 2017, 15:17
by countcobolt
Hey Bryan,

just tried it but sitting remote, so cannot see the result. From the log file this does seem to work.

Just another stupid Q: which GPIO's are the additional button 1 and button 2?

Kind regards

Steve

Re: sonoff dual flashing the ESP

Posted: 08 Aug 2017, 20:38
by countcobolt
Just to let you know : It works. Just pay attention when connecting the 220V to it while running. Don't ask me what component I touched, but got zapped twice

Re: sonoff dual flashing the ESP

Posted: 08 Aug 2017, 20:58
by LisaM
countcobolt wrote:
08 Aug 2017, 20:38
Just to let you know : It works. Just pay attention when connecting the 220V to it while running. Don't ask me what component I touched, but got zapped twice
I got zapped so many times, i now exists entirely out of electricity... :lol:

Re: sonoff dual flashing the ESP

Posted: 11 Aug 2017, 20:48
by jomixl
hi Brian,
thanks for your work!
The On/Off commands work fine, but what do i have to do when i want to use the 'LongPulse' command?
I have no experience in EasyEsp and Arduino so is it possible to add a timer in your plugin?

regards
jomixl

Re: sonoff dual flashing the ESP

Posted: 12 Aug 2017, 01:12
by bryan
jomixl wrote:
11 Aug 2017, 20:48
hi Brian,
thanks for your work!
The On/Off commands work fine, but what do i have to do when i want to use the 'LongPulse' command?
I have no experience in EasyEsp and Arduino so is it possible to add a timer in your plugin?

regards
jomixl

Hi Jomixl,
You can use rules to start a timer. Check the rules wiki.
Eg. Create an event called sonoffpulse.
Enable sonoff1, start a timer.
When the timer is finished , disable sonoff1.
Btw. I did not change anything for the rules. I've just added two commands that can be called directly in a url or indirectly using rules.
https://www.letscontrolit.com/wiki/inde ... rial_Rules
Regards,
Bryan

Re: sonoff dual flashing the ESP

Posted: 12 Aug 2017, 17:21
by bryan
countcobolt wrote:
08 Aug 2017, 15:17
Hey Bryan,

just tried it but sitting remote, so cannot see the result. From the log file this does seem to work.

Just another stupid Q: which GPIO's are the additional button 1 and button 2?

Kind regards

Steve
Hi Steve,

The buttons are not connected to the GPIO's from the esp.

Regards,

Bryan

Re: sonoff dual flashing the ESP

Posted: 13 Aug 2017, 09:18
by jomixl
Thanks Bryan,
now i will try to create that rule.....

this is what i did:

On Sonoff1Pulse do
Sonoff1,1
timerSet,1,10
endon

On Rules#Timer=1 do //When Timer1 expires, do
Sonoff1,0
endon

this seems to me ok,
but i am confused about the creation of the event.

i made a switch input named sonoff1pulse
with the value sonoff1 and enabled it

Edit 1 ✔ Switch input Sonoff1Pulse Sonoff1:1
Edit 2
Edit 3
Edit 4

i can switch the relay on but ther is no timerevent to switch it off.
i also tried to call the event itself with
http://192.168.1.40/control?cmd=event,Sonoff1Pulse
it was working and the relay was off again.
now i tried to start it again but ther was no reaktion.
after a few seconds i tried it again and it worked.
do i have to disable somehow the timer when the relay goes off?

ok, to send the event is not relayable, somtimes it works, somtimes not and somtimes the relays stucks on.

in the meantime i tried a lot of silly variations.
i think my main problem is to setup a working event on the sonoff dual.

if you would have a working example it would be great.

regards
jomixl

Re: sonoff dual flashing the ESP

Posted: 13 Aug 2017, 19:30
by jomixl
hello Bryan,
it seems to me that something with the scribt goes wrong.
i have made this rules:

On Sonoff1On do
Sonoff1,1
timerSet,1,5
endon

On Sonoff1Off do
Sonoff1,0
timerSet,1,0
endon

On Rules#Timer=1 do //When Timer1 expires, do
Sonoff1,0
endon

i can switch the relay on with caling sonoff1On and switch it off with caling sonoff1Off, but only sometimes the relay is switched off by
timer1.
In most cases the first call of sonoff1On is working, when i call it again, after the timer switched the relay off, the relay went on again and stays on.

Is this a problem of your plugin or easyesp?

Re: sonoff dual flashing the ESP

Posted: 15 Aug 2017, 11:52
by bryan
jomixl wrote:
13 Aug 2017, 19:30
hello Bryan,
it seems to me that something with the scribt goes wrong.
i have made this rules:

On Sonoff1On do
Sonoff1,1
timerSet,1,5
endon

On Sonoff1Off do
Sonoff1,0
timerSet,1,0
endon

On Rules#Timer=1 do //When Timer1 expires, do
Sonoff1,0
endon

i can switch the relay on with caling sonoff1On and switch it off with caling sonoff1Off, but only sometimes the relay is switched off by
timer1.
In most cases the first call of sonoff1On is working, when i call it again, after the timer switched the relay off, the relay went on again and stays on.

Is this a problem of your plugin or easyesp?
Hi jomixl,
What happens when you disable the controller?
What I can imagine is that the controller sends an update to the esp after you've send the sonoff1on command.
You can also try to remove the timerset,1,0 and just wait for the timer to expire before starting a new command.

Regards,
Bryan

Re: sonoff dual flashing the ESP

Posted: 15 Aug 2017, 12:13
by grovkillen
jomixl wrote:
13 Aug 2017, 09:18
Thanks Bryan,
now i will try to create that rule.....

this is what i did:

On Sonoff1Pulse do
Sonoff1,1
timerSet,1,10
endon

On Rules#Timer=1 do //When Timer1 expires, do
Sonoff1,0
endon

this seems to me ok,
but i am confused about the creation of the event.

i made a switch input named sonoff1pulse
with the value sonoff1 and enabled it

Edit 1 ✔ Switch input Sonoff1Pulse Sonoff1:1
Edit 2
Edit 3
Edit 4

i can switch the relay on but ther is no timerevent to switch it off.
i also tried to call the event itself with
http://192.168.1.40/control?cmd=event,Sonoff1Pulse
it was working and the relay was off again.
now i tried to start it again but ther was no reaktion.
after a few seconds i tried it again and it worked.
do i have to disable somehow the timer when the relay goes off?

ok, to send the event is not relayable, somtimes it works, somtimes not and somtimes the relays stucks on.

in the meantime i tried a lot of silly variations.
i think my main problem is to setup a working event on the sonoff dual.

if you would have a working example it would be great.

regards
jomixl
Your rules are not using correct syntax. "Sonoff1,1" is not doing anything. It should probably be something like this:

Code: Select all

On Sonoff1On do
  GPIO,0,1
  timerSet,1,5 
endon

On Sonoff1Off do
  GPIO,0,0
  timerSet,1,0 
endon

 On Rules#Timer=1 do  //When Timer1 expires, do
   GPIO,0,0
 endon
The event is then sent as described on the rules tutorial page. If you're not able to find it:
https://www.letscontrolit.com/wiki/inde ... nd_Publish
and here
https://www.letscontrolit.com/wiki/inde ... ith_events

Re: sonoff dual flashing the ESP

Posted: 15 Aug 2017, 13:13
by countcobolt
Hi Bryan

I am in a similar situation as above. I am working on a blinds controller, not using any devices, simply your Sonoff nomenclature. Using GPIO does not work. Using Sonoff works, but ... sometimes although the log show that the timers are running and the Sonoff switch are switched, nothing happens. Using 2 timers to delay that actual action (Timer 2 and 3) seems to partially resolve this. Any clues on this ? I can mimic it by simply adding 2 lightbulbs on the sonoff and try to turn the lights off. The main reason for stopping all action first is to make sure that the motor does not get power to both directions.

Code: Select all

On close_blinds do
  Sonoff1,0
  Sonoff2,0
  timerset,2,2
  timerSet,1,17
endOn

On open_blinds do
  Sonoff1,0
  Sonoff2,0
  timerSet,3,2
  timerSet,1,17
endOn

On Rules#Timer=1 do
  Sonoff1,0
  Sonoff2,0
endOn

On Rules#Timer=2 do
  Sonoff1,1
endOn

On Rules#Timer=3 do
  Sonoff2,1
endOn

On stop_blinds do
  Sonoff1,0
  Sonoff2,0
endOn
also in my log I notice that it says switch set to 2

Code: Select all

Aug 15 13:15:41 ESP Unit: 20 : EVENT: Rules#Timer=1
Aug 15 13:15:41 ESP Unit: 20 : ACT  : Sonoff1,0
Aug 15 13:15:41 ESP Unit: 20 : SW   : Sonoff 1 Set to 0 switchstate Set to 2
Aug 15 13:15:41 ESP Unit: 20 : ACT  : Sonoff2,0
Aug 15 13:15:41 ESP Unit: 20 : SW   : Sonoff 2 Set to 0 switchstate Set to 0

Re: sonoff dual flashing the ESP

Posted: 15 Aug 2017, 14:05
by jomixl
hi Bryan,
i am sending the commands by my own tool, that means commands are sent only on a buttonclick.
the sonoff1,1 ond sonoff1,0 commands work stable.
when i set the relay with the scipt Sonoff1On the relay is set but not alltimes reset by the timer1.
the script Sonoff1Off works stabel.

i will try to show this behaviour with a logfile this evening.

.... its good that i'm not the only one with this problem .......

jomixl

Re: sonoff dual flashing the ESP

Posted: 15 Aug 2017, 14:22
by grovkillen
Sorry, I didn't see that you use a plugin. Then it works like you say. Sorry!! :)

Re: sonoff dual flashing the ESP

Posted: 15 Aug 2017, 14:46
by bryan
The switchstate is what is send out on the serial to the pic.
Switchstate 0 = switch 1 is off, switch 2 is off
Switchstate 1 = switch 1 is on , switch 2 is off
Switchstate 2 = switch 1 is off, switch 2 is on
Switchstate 3 = switch 1 is on, switch 2 is on

Did you disable serial in the advanced settings?

It should be disabled, as the serial is used to send the commands.

Could be that that is causing the problem.

Regards,
Bryan

Re: sonoff dual flashing the ESP

Posted: 15 Aug 2017, 18:03
by jomixl
hello Bryan,
since i disabled the serial port it seems to work when i call the event drectly.

But i could not get an event when i just switch Sonoff1 on.
Maybe i ther is a fault in my rules:
what would be the syntax for an event when Sonoff1 goes on and what do i have to do in the devices.
it seams to me that for the donoff-dual it is different.

Thanks
jomixl

Re: sonoff dual flashing the ESP

Posted: 19 Aug 2017, 22:37
by bryan
jomixl wrote:
15 Aug 2017, 18:03
hello Bryan,
since i disabled the serial port it seems to work when i call the event drectly.

But i could not get an event when i just switch Sonoff1 on.
Maybe i ther is a fault in my rules:
what would be the syntax for an event when Sonoff1 goes on and what do i have to do in the devices.
it seams to me that for the donoff-dual it is different.

Thanks
jomixl
Did you add a device with type sonoff dual?
If you add this device and configure the idx, you should get an update as soon as sonoff1 or sonoff2 is called in the rules.

Regards,
Bryan

Re: sonoff dual flashing the ESP

Posted: 23 Aug 2017, 11:16
by Abundis
bryan wrote:
19 Aug 2017, 22:37
jomixl wrote:
15 Aug 2017, 18:03
hello Bryan,
since i disabled the serial port when i call the event drectly.

But i could not get an event when i just switch Sonoff1 on.
Maybe i ther is a fault in my rules:
what would be the syntax for an event when Sonoff1 goes on and what do i have to do in the devices.
it seams to me that for the donoff-dual it is different.

Thanks
jomixl
Did you add a device with type sonoff dual?
If you add this device and configure the idx, you should get an update as soon as sonoff1 or sonoff2 is called in the rules.

Regards,
Bryan
Good advice Bryan.

Re: sonoff dual flashing the ESP

Posted: 17 Sep 2017, 19:23
by Dylantje
mmm
Did flash the dual..
Try some pins..
Cannot get working.
In the wiki are pins: 1, 3, (14) 0 (button), 12 (Relay 10A/16A@230VAC), 13 (LED), 14 (AM2301)
When i try them i get no switch working

Is it correct that i must activate the pins with this command?
:http://192.168.5.112/control?cmd=GPIO,10,1
Or is the dual with the latest dev. software different like the singel sonof??

Do i need to set the pins in the esp with a idx?

I do have the wifi vc and the uptime etc working..
I can see the webgui. so the flash is k i think.

Re: sonoff dual flashing the ESP

Posted: 26 Sep 2017, 20:31
by Dylantje
please???

Help...

Re: sonoff dual flashing the ESP

Posted: 26 Sep 2017, 23:16
by bryan
Please read this topic before asking.

Re: sonoff dual flashing the ESP

Posted: 06 Oct 2017, 09:36
by HEMELIC
Hey guys! This topic was a live saver for me. BUT I have a problem.
So I'm using openhab2 on a Pi (openhabian) and with it I use a mosquitto server. The problem that I'm facing is I can't get the relay state. I can controll the Sonoff Dual but can't get feedback to the server for the state. Does anybody have an idea on how to do it? On the Sonoff basic I use a publish rule.

on lightState#State=0 do
Publish ESP1/netstate,OFF
endon

But because the relay are not directly controlled by the ESP I can't get direct info for the state.

Re: sonoff dual flashing the ESP

Posted: 06 Oct 2017, 22:54
by bryan
The switch state is saved in a local variable, but not yet publicly available.

state = 0, both switches are off
state = 1, switch 1 = on, switch 2 = off
state = 2, switch 1 = off, switch 2 = on
state = 3, switch 1 = on, switch 2 = on

Is it usable when this is publicly available?