-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch logic gets inverted #552
Comments
You can configure your switch as a pushbutton with explicit action for press and release. You will also want to disable any secondary options on this button to avoid unwanted side-effects (ap mode, factory reset). This could be a starting point:
Change BUTTON_MODE flags to match your hardware (maybe it's default low or it already has a pullup). |
Actually I need both buttons to act independently of one another and swith the same single relay. So one button should be a toggle button and the other should be an on/off switch. If at least one of the buttons in in "on" position, relay should be switched on. For example if first button is clicked, relay switches on and no matter what I do with the second button, relay stays on until button is clicked again. And vice versa - if second button (switch) is pressed - relay stays on until button is released. Toggling the first button should not swith the relay off. However ralay should stay on even if second button is released, if first button was clicked while the second button was pressed. As far as I know, current firmware will not allow such configuration. But I know there were plans to make buttons and relays independently configurable, so if two buttons are controlling one relay, nice feature to have would be to define logical function between buttons (AND, OR, XOR). |
I patched the code to make it work the way I need until such functionality is available in stock espurna firmware, but there is one issue. Here's what I did:
And then in relay.ino at the end of relayLoop function I added this line:
As you can see, I created two dummy relays which are assigned to each of the buttons and then actual relay is controlled by OR-ing two dummy relays.
BUTTON_MODE_OFF does not work for some reason after click event |
I think part of the problem is the naming. BUTTON_PUSHBUTTON is a momentary push button: you press it, you might hold it down and you released and it goes back to the original state. A BUTTON_SWITCH is a wall switch, ever time you click it (or slide it, or toggle it) it toggles between teo stable states. Now, there is a tricky thing in ESPurna with indexes. All lists (arrays) are 0-based, so the "Button #1 event 1" log line above is actually BUTTON2_PRESS and the "Button #1 event 4" is BUTTON2_LNGCLICK, that you have defined as "do nothing". |
Yes, PRESS event is fine, but I am not getting CLICK event after button is released. Instead there is "event 4". I am releasimg the button quickly so LNGCLICK should not have been triggered. Are LNGCLICK and LNGLNGCLICK triggered on button release? In that case these events must be set to BUTTON_MODE_OFF in my case, right? |
LNGCLICK is triggered when the button has been held down for at least 2 seconds, LNGLNGCLICK is 10 seconds. Maybe the button logic is inverted? |
Closing since there has been no feedback for several months. Feel free to reopen if necessary. |
If there is a switch tied to relay and relay toggling occurs (button press, MQTT, web e.t.c) while switch is "on", that switch gets inverted so that turning it "off" actually switched relay "on". Is there an easy way to fix this?
There are two different ways it could work and I'll give an example using SONOFF_RF
Turn relay on using swith connected to GPIO14 and then toggle relay using push button or RF remote. At this point relay is off and turning swith off will actually turn relay on. But instead more logical way would be to leave relay off when switch is turned back off. Or second option would be to not allow turning relay off while switch is turned "on".
In other words - I want switches to switch relay on or off not toggle it on each switching edge.
The text was updated successfully, but these errors were encountered: