Sonoff 4CH R3 GPIO

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
DomoticaRob
Normal user
Posts: 45
Joined: 17 Jan 2018, 18:43

Sonoff 4CH R3 GPIO

#1 Post by DomoticaRob » 06 Nov 2023, 22:11

I have bought a couple of Sonoff 4CH R3 switches.

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

Sonoff 4CH R3 Print.jpg
Sonoff 4CH R3 Print.jpg (394.02 KiB) Viewed 2937 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 2937 times

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

That is totally different then what Sonoff wants

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

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Sonoff 4CH R3 GPIO

#2 Post by chromo23 » 06 Nov 2023, 22:16

Disable I2C by setting the GPIOs to "none".
After that you can choose the missing GPIOs
i2c.png
i2c.png (85 KiB) Viewed 2934 times

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Sonoff 4CH R3 GPIO

#3 Post by TD-er » 06 Nov 2023, 22:16

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.

DomoticaRob
Normal user
Posts: 45
Joined: 17 Jan 2018, 18:43

Re: Sonoff 4CH R3 GPIO

#4 Post by DomoticaRob » 06 Nov 2023, 22:46

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?

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Sonoff 4CH R3 GPIO

#5 Post by TD-er » 06 Nov 2023, 22:59

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.

User avatar
Ath
Normal user
Posts: 3521
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Sonoff 4CH R3 GPIO

#6 Post by Ath » 06 Nov 2023, 23:03

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.
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 3521
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Sonoff 4CH R3 GPIO

#7 Post by Ath » 06 Nov 2023, 23:13

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.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Sonoff 4CH R3 GPIO

#8 Post by TD-er » 06 Nov 2023, 23:23

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.

User avatar
Ath
Normal user
Posts: 3521
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Sonoff 4CH R3 GPIO

#9 Post by Ath » 07 Nov 2023, 13:09

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 ;)
/Ton (PayPal.me)

DomoticaRob
Normal user
Posts: 45
Joined: 17 Jan 2018, 18:43

Re: Sonoff 4CH R3 GPIO

#10 Post by DomoticaRob » 08 Nov 2023, 19:06

I am out for a few days.
After the weekend I wil try the rules thing and the TD binarie.

DomoticaRob
Normal user
Posts: 45
Joined: 17 Jan 2018, 18:43

Re: Sonoff 4CH R3 GPIO

#11 Post by DomoticaRob » 08 Nov 2023, 20:43

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.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Sonoff 4CH R3 GPIO

#12 Post by TD-er » 08 Nov 2023, 21:25

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?

DomoticaRob
Normal user
Posts: 45
Joined: 17 Jan 2018, 18:43

Re: Sonoff 4CH R3 GPIO

#13 Post by DomoticaRob » 08 Nov 2023, 22:03

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.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Sonoff 4CH R3 GPIO

#14 Post by TD-er » 08 Nov 2023, 22:20

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests