Home Automation - Tasmota : Using a Motion Sensor and a Physical Toggle Switch
I've recently been playing with Home Assistant, Tasmota, ESP8266 + ESP32 boards, Sonoff, IR transmitters/receivers, solder, LEDs.. and the list goes on.
It has been quite a learning curve and I have had a lot of success but also a lot of ups and downs in terms of predictable behavior with certain automations.
In particular; I had a licensed electrician install a Shelly 1 switch into my bathroom light switch after my brother(he's in a drywall house with ABS plastic electrical boxes) had his entire house finished with these and raved about the stability and ease of use from Home Assitant. My use case was to control the bathroom light via Wi-Fi from Home Assistant but also use a motion sensor (Zigbee Tuya connected to HA via my Conbee USB II adapter).
Using the Shelly firmware on the device for the first 4-6 weeks I was having frequent lockups requiring me to reset the electrical mains to the house (the circuit breaker box). I believe (suspect/guess) it was caused by electrical interference where the only way to resolve the issue was to reset the mains. DrZzs talks about physical ghost switching on Sonoff which I believe uses the 5V DC circuit to switch and suggests a Low Pass Filter (add a 33nf Capacitor and 4.7k resistor) but I don't like the idea of doing this on a switch using the 240v AC circuit like a Shelly - I'm not an electrician!
I ruled out the house Wi-Fi signal being the issue by installing a Ubiquiti Mesh outdoor AP at the window of the bathroom (to also provide coverage to my backyard, but also to improve Wi-Fi to the switch in my double bricked bathroom) - about 2 meters from the wall switch.
The switch electrical box is not only in double brick but in a steel electrical box and I know from my 802.11 (Wi-Fi) engineer days that this is not good. I have also read some brand wall switches advice against installing in metal wall boxes.
Whilst going to Tasmota (from Shelly) firmware allowed the device to auto recover/reboot without me needing to reset the circuit breaker there was some strange behavior happening.. ghost switching and MQTT and retain.. which was resolved by using SetOption19 1 and having Home Assistant discover and manage the device.
As well as a motion sensor to trigger the light, I wanted the physical toggle wall switch to take precedence over the turn off (from no motion) time . e.g. if the physical wall switch was on, then don't turn the light off if not motion or atleast wait alot longer. While this logic could possibly been done in Home Assistant, I was concerned with the relatively frequent device restarts, so I started looking at what was possible on the Tasmota firmware itself and believe I have a good fit.
I am using PulseTime on device to handle the OFF action so Home Assitant is responsible for only the ON command (on motion from the Tuya sensor). PulseTime is set to 400(300 seconds + 100) which means after 5 minutes (300 seconds) of no motion PulseTime will turn the Relay off. On any new motion before the 5 minutes, the timer will restart. I have then used a rule to say that if Switch1 (the physical switch) is toggled to turn on the relay but also to change the pulsetime to 20 minutes (1200 seconds) which is input as PulseTime 1300 (1200 seconds + 100).
When the physical switch is turned OFF the Relay (POWER1) is set to off, and the pulsetime is set back to 300 (5 minutes).
This way, if my parents (or the in-laws) or older relatives come over and turn on the physical switch there is no chance of the time going off (unless they're in there for 20 minutes and there is no motion at which point maybe an alarm should siren 🤣).
rule1
ON Switch1#state=1 DO Power1 1 ENDON
ON Switch1#state=1 DO PulseTime1 1300 ENDON
ON Switch1#state=0 DO Power1 0 ENDON
ON Switch1#state=0 DO PulseTime1 400 ENDON
rule1 1
Comments
Post a Comment