One of the things I’m trying to do with HA and my Sonoff’s is to create light switches around the house that would have a momentary push button and a PIR sensor. The goal is to be able to see the push button LED when it is dark in the house and also have a PIR sensor to set up some future automation to turn lights on or off when there is no activity for some time. Also, there are three requirements that I really wanted to have in place 1) Be able to control the onboard button so that I can restart, reset, etc if needed without opening up the switch. 2) Be able to see all onboard led error indicators (rapid flashing, restarts, etc.) directly on the momentary push button. 3) Do not toggle or do anything to main Relay1 when PIR changes state (Thanks to @DrZzs for helping me figure out that I need to set one of the pins to Relay2 so that Switch2 does not control Relay1).
1) In the first version, I was able to to get the push button LED to be on when the PIR is triggered, see the push button LED when someone is close enough to click it, and keep the LED OFF when the light is On (It’s also OFF when the light in OFF but temporarily visible when PIR is active). However, the disadvantage here is that there is no LED indication of the board’s status.
Module parameters:
- GPIO3 (Serial Out) > Relay2 (LED)
- GPIO14 (Sensor) > Switch2 (PIR AM312)
- SwitchMode2 1 (0 is OFF and 1 in ON)
- LedState 1 (Show power state on led)
Wiring:
- Used 10k resistor to decrease the brightness of push button LED since it will be on all night.
2) In the second version I was able to get the inverted effect of the onboard LED, see the push button LED when the light is OFF, and get notifications on push button LED of board status. However, the horrible disadvantage here is that when someone gets close to the switch to turn it on, the onboard LED will turn on and the push button LED would turn off, so it will disappear into the night (probably good setup for April fools joke).
Module parameters:
- GPIO4 > Relay2 (n/a)
- GPIO14 (Sensor) > Switch2 (PIR AM312)
- SwitchMode2 1 (0 is OFF and 1 in ON)
- LedState 1 (Show power state on led)
Wiring:
3) This last version is probably the one I will stick with. With this, I get the inverted LED effect on the push button, all the onboard LED notifications of status, and it lights up for a few seconds when someone comes close. The only annoyance here is that the PIR has to be always on by default so that onboard LED is also always on so that the push button LED is off unless PIR is triggered (changes state to OFF). I don’t think to have the light on inside the switch all the time would cause much extra to hear or cause it to burn out quickly, but I would have preferred it to be off.
Module parameters:
- GPIO4 > Relay2 (n/a)
- GPIO14 (Sensor) > Switch2 (PIR AM312)
- SwitchMode2 2 (0 is ON and 1 in OFF)
- LedState 1 (Show power state on led)
Wiring: (Same as above)
One of the things that is frequently mentioned in posts is to use a step-down resistor when connecting switches/sensors to the board. However, I did not use any and not sure if that applies to the different setups above.
Anyway, this was all done via trial and error by poking different wires into each and every available slot, so I would appreciate your feedback if you think this may later brow up or if there may be a better way to do it. Also, I don’t think I really understand why the inverted LED effect even works, so this would be nice to know too if anyone has some ideas.