Skip to content
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

Sonoff TH gpio #123

Closed
xoseperez opened this issue Apr 13, 2017 · 7 comments
Closed

Sonoff TH gpio #123

xoseperez opened this issue Apr 13, 2017 · 7 comments
Labels
enhancement New feature or request relay

Comments

@xoseperez
Copy link
Owner

Originally reported by: Carlos (Bitbucket: cnieves1, GitHub: cnieves1)


Hi all,
First of all, congratulations for your great work!
I'm new to espurna, so sorry if this is is documented somewhere.
I'm trying to use a Sonoff TH with a presence detector attached to the external connector.
I would like to configure a gpio to reset the timer of the pulse mode, so it only allows to run the timer when there is no detection.
I didn't found how to add a digital gpio. How can I do that? And, when I figure it, how can I reset the timer with that input?

Thanks in advance,

Carlos

@xoseperez
Copy link
Owner Author

Thanks! :)

Why don't you use your presence detector sensor as a button? You can define it in hardware.h like this (GPIO14 is the digital pin in the external connector for the Sonoff TH, if I'm not wrong):

    #define BUTTON1_PIN         14
    #define BUTTON1_RELAY       1
    #define BUTTON1_DBLCLICK    BUTTON_MODE_NONE
    #define BUTTON1_LNGCLICK    BUTTON_MODE_NONE
    #define BUTTON1_LNGLNGCLICK    BUTTON_MODE_NONE
    #define BUTTON1_MODE        BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH

@xoseperez
Copy link
Owner Author

Original comment by Carlos (Bitbucket: cnieves1, GitHub: cnieves1):


Hi Xose,
Good hint!!

However, if I'm not mistaken, a button is used to toggle the relay (tried that with the external button).
Could I change that behaviour so the gpio button only activates the relay and restart the timer of the pulse mode?

Thanks again,

Carlos

@xoseperez
Copy link
Owner Author

You mean having one button to toggle the relay and another one to reset the pulse timer?

@xoseperez
Copy link
Owner Author

Original comment by Carlos (Bitbucket: cnieves1, GitHub: cnieves1):


Hi Xose,
I have a motion detector connected to GPIO14. This signal is low while
motion is detected, and it goes high after 0.5-1s of no motion detected.
I'm trying to switch on the relay as soon as motion is detected, and switch
off the relay some configurable time after no motion is detected anymore.
Noticed that if motion is detected while the timer is running, the timer
should be stopped and restarted again in the next low to high transition.
I'm using a Sonoff basic.

It's something like "Resettable Single Shot / Watchdog" in:
http://www.airotronics.com/AOTpdfs/multifunction/Airotronics-MC363.pdf
(but my control input is active low instead of active high as shown in that
pdf).

So far, if I configure the hardware.h as a pushbutton, the relay is not
switched, even when this input is working properly.
If I configure it as a switch, then the relay is switching on and off.

My configure.h looks like:
#define BUTTON2_PIN 14
#define BUTTON2_RELAY 1
#define BUTTON2_DBLCLICK BUTTON_MODE_NONE
#define BUTTON2_LNGCLICK BUTTON_MODE_NONE
#define BUTTON2_LNGLNGCLICK BUTTON_MODE_NONE
#define BUTTON2_MODE BUTTON_SWITCH | BUTTON_DEFAULT_HIGH

For the configurable time, I'm using the pulse mode. It seems that the
first time the relay is switched on, a timer is started. If there are
several motion - no motion - motion pulses, I would like each low to high
transition restarts the timer.

It seems this is no supported right now. I read that v2 branch is better in
terms of input configurability. Should I try v2 branch?

I was digging the code, but it's still not clear to me how to modify it in
such a way that the patch could be accepted upstream.

Thanks,

Carlos

@xoseperez
Copy link
Owner Author

Original comment by Carlos (Bitbucket: cnieves1, GitHub: cnieves1):


You have a proposed patch as issue #161, "button with delayed ON or OFF actions".

@xoseperez
Copy link
Owner Author

Released with 1.9.0

@xoseperez
Copy link
Owner Author

Removing milestone: 1.8.4 (automated comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request relay
Projects
None yet
Development

No branches or pull requests

1 participant