Page 1 of 1

ESP With 2 Relay 1 Button Control?

Posted: 29 Mar 2019, 12:58
by rmhoutz
I have this ESP
ESP8266-120v2relay.JPG
ESP8266-120v2relay.JPG (18.9 KiB) Viewed 3091 times
I have a momentary button connected to GPIO15.
I think the ideal setup is to have relay 1 come on when the button is pressed once and relay 2 come on when the button is pressed twice.
Anyone have any advice on how to do this?
Thanks in advance for any help you can provide.

Re: ESP With 2 Relay 1 Button Control?

Posted: 29 Mar 2019, 13:07
by Domosapiens
Did you study the docs?

You could use double click or long press
https://espeasy.readthedocs.io/en/lates ... ng%20press
and add a rule to it with Switch#State=3, 10 or 11

My experience is that long press is more robust.

Re: ESP With 2 Relay 1 Button Control?

Posted: 29 Mar 2019, 21:34
by rmhoutz
Hi Domosapiens

That's the first I've seen those docs, I've been going by the Wiki all this time, thanks for that.
I should have mentioned I do have a start with this already but I'm not sure it can be adapted to work like this.
I'm by no means a programmer but I have been able to study the rules and with the help of others come up with a solution.
So my current setup is one ESP and One Relay. I have the ESP configured to be manually operated by the momentary pushbutton but I also have it configured to be operated with Openhab.
In ESP Easy I have 2 devices set up they are both Switch input devices configured as normal switches.
The switch with the relay attached to it is configured to send it's state to Openhab MQTT so I can tell if the light is on or off from the Server.
The other device on the ESP is the pushbutton called SwitchIn. When pressed I have a rule that does this.

Code: Select all

On SwitchIn#Switch=0 do      //When The "Button/SwitchIn" is pressed attached to GPIO15 and 3.3v 
     if [Relay1#State]=1      //If the GPIO 12 Relay1 is high/on=1 
         GPIO,12,0            //Set GPIO12 to off=0
     else                    
         GPIO,12,1            //Otherwise set GPIO12 to on=1
      endif
endon
This makes sure if I press the physical button to turn the light on and I leave the room and then look at my phone and notice the light was left on via the software OpenHAB can shut it off with the appropriate command.
I attempted to just create another Rule Set that was adapted double click and the other relay and that worked a little.

Code: Select all

On SwitchIn#Switch=3 do      //When The Button/SwitchIn is pressed attached to GPIO15 and 3.3v 
     if [Relay2#State]=1      //If the GPIO 13 Relay2/SSR is high/on=1 
         GPIO,13,0            //Set GPIO13 to off=0
     else                    
         GPIO,13,1            //Other wise set GPIO13 to on=1
      endif
endon
But with it setup like that it was messing with Relay 1 every time I pushed the button.
Hopefully this clears things up.
Any advice on modifying this setup? Will something like this work?

Code: Select all

On SwitchIn#Switch=0, or 3 do      
     if [Relay1, or Relay2#State]=1      
         GPIO,12,0           
     else                    
         GPIO,12,1 
     else
        GPIO,13,0
     else
        GPIO,13,1                 
    endif
endon
Again I'm not good with creating rules.
Thanks again.

Re: ESP With 2 Relay 1 Button Control?

Posted: 29 Mar 2019, 23:16
by Domosapiens
Learn by trying different options....

Double click seems to be detected as single click first.
That's why I wrote:
My experience is that long press is more robust.