Page 1 of 1

Sonoff 4CH R3 GPIO

Posted: 06 Nov 2023, 22:11
by DomoticaRob
I have bought a couple of Sonoff 4CH R3 switches.

Sonoff 4CH R3.jpg
Sonoff 4CH R3.jpg (13.78 KiB) Viewed 8501 times

Sonoff 4CH R3 Print.jpg
Sonoff 4CH R3 Print.jpg (394.02 KiB) Viewed 8501 times


I have flashed ESPEasy and now I want to make it suitable for mij Domoticz system.

Google tells me the folowing GPIO declarations:

Button 1 = GPIO 0
Button 2 = GPIO 9
Button 3 = GPIO 10
Button 4 = GPIO 14

Relay 1 = GPIO 12
Relay 2 = GPIO 5
Relay 3 = GPIO 4
Relay 4 = GPIO 15

In ESPEasy I get by devices the folowing GPIO possibilities:

Soort device.jpg
Soort device.jpg (107.36 KiB) Viewed 8501 times

GPIO.jpg
GPIO.jpg (153.94 KiB) Viewed 8501 times

That is totally different then what Sonoff wants

How can I use this Sonoff 4 channel relay box with ESPEasy?

Re: Sonoff 4CH R3 GPIO

Posted: 06 Nov 2023, 22:16
by chromo23
Disable I2C by setting the GPIOs to "none".
After that you can choose the missing GPIOs
i2c.png
i2c.png (85 KiB) Viewed 8498 times

Re: Sonoff 4CH R3 GPIO

Posted: 06 Nov 2023, 22:16
by TD-er
The greyed out options are now set to some other feature, like I2C.
On the Hardware tab, you can set the SDA/SCL pins for I2C to "not set" and then they are available to select in your select options.

The same for the "ESPEasy console" on the Tools->Advanced page.
If you uncheck that option, you can pick GPIO 1 and 3.

Re: Sonoff 4CH R3 GPIO

Posted: 06 Nov 2023, 22:46
by DomoticaRob
Thanks for the very very fast respons.

The relays are working.

Super, super, super.

One 'but' left.

I also want to use the buttons of the Sonoff.

Button 1 = GPIO 0
Button 2 = GPIO 9
Button 3 = GPIO 10
Button 4 = GPIO 14

Button 1, 3,and 4 are directed to the proper GPIO's

Button 2 wants to be directed to GPIO 9 and GPIO 9 is not in the list of ESPEasy.

How can I use button 2?

Re: Sonoff 4CH R3 GPIO

Posted: 06 Nov 2023, 22:59
by TD-er
You can add several switch input tasks.
Each with their own set GPIO and name the tasks with their own unique task name. (e.g. "Button1" ... "Button4")

Then in the rules you can simply act on the events when a button is pressed.

Example rule to couple "button1" to GPIO-12:

Code: Select all

on Button1#switch do
  gpio,12,%eventvalue1%
endon
Just make sure to set the Switch task to "Push Button Active Low" and set the debounce to something like 100 msec.

Re: Sonoff 4CH R3 GPIO

Posted: 06 Nov 2023, 23:03
by Ath
As GPIO is missing from the list, you can set up a monitor for that pin:

Code: Select all

on System#Boot do
  monitor,GPIO,9
endon

on GPIO#9 do
  // Act for Button 2, %eventvalue1% is holding the state 0/1
endon
To start the monitor without a reboot, you can type that "monitor,gpio,9" command (it's not case-sensitive) on the Tools page to activate it immediately.

Re: Sonoff 4CH R3 GPIO

Posted: 06 Nov 2023, 23:13
by Ath
What build of ESPEasy do you have installed? (name of the .bin file please) as most likely the ESP on board is an ESP8285, that should have GPIO 9 available for use, but only a somewhat recent build (max 1 year old) has the auto-detect feature for ESP8266 vs ESP8285, enabling the few extra pins. You can see the detected ESP on the System Info page.

Re: Sonoff 4CH R3 GPIO

Posted: 06 Nov 2023, 23:23
by TD-er
And also the actual size of the flash memory.
There should exist some ESP8285 with 2MB flash and according to some model nr I found in the documentation there might even exist a 4M version of the ESP8285.
If you happen to have one with 2MB or more flash memory, then you could also use a build for 2M flash which makes updating to a newer build a lot simpler.

Re: Sonoff 4CH R3 GPIO

Posted: 07 Nov 2023, 13:09
by Ath
TD-er has deployed a new build on https://td-er.nl/ESPEasy/latest/ that has a fix to allow selection of GPIO 9 on an ESP8285 unit like this Sonoff 4CH R3 seems to be.
You can install and test that when using Chrome or Edge browsers and the unit is connected to your USB Serial connection ( !!! DON'T connect the unit to mains power when also connecting to USB Serial !!! )

Feedback is welcome ;)

Re: Sonoff 4CH R3 GPIO

Posted: 08 Nov 2023, 19:06
by DomoticaRob
I am out for a few days.
After the weekend I wil try the rules thing and the TD binarie.

Re: Sonoff 4CH R3 GPIO

Posted: 08 Nov 2023, 20:43
by DomoticaRob
I had a few minutes extra so I flashed with th TD binarie:

ESP_Easy_mega_20231107_normal_ESP8266_1M

And it works, super.


The only small disadvantage is yhat after a reboot relay 1 and relay 2 are activated.

After pressing the buttons the are de-activated.

I have changed the 'Send Boot State' and also the 'Internal Pull Up' and also the 'Inversed Logic'.

I will look further into it to find out what is the solution.


TD,

Thanks for this binarie, super.

Re: Sonoff 4CH R3 GPIO

Posted: 08 Nov 2023, 21:25
by TD-er
Do you also use some external service/server like Domoticz or HomeAssistant or anything like those?
In other words, do you need to keep the relay state in sync with some external service?

Re: Sonoff 4CH R3 GPIO

Posted: 08 Nov 2023, 22:03
by DomoticaRob
Yes, I use Domoticz.

I was a little too enthousiastic.

When I again pluged in the module it was not reachenable.

I will find out later what is the problem.

Re: Sonoff 4CH R3 GPIO

Posted: 08 Nov 2023, 22:20
by TD-er
Please also have a look at this one:
https://espeasy.readthedocs.io/en/lates ... #p029-page
When you need to keep a relay/switch in sync with Domoticz, you need to take care to not end up with lots of on/off/on/off flipping of the relay when you boot ESPEasy while Domoticz assumes a different state.