Ghost switch triggers

Sometimes my switches turn themselves on/off for no apparent reason, has anyone else experienced this?
It doesn’t happen often and I think it may have something to do with the wifi connection dropping out but I haven’t been able to duplicate it or problem solve the culprit, so I really have no idea why it does this. Where this is really causing me a problem is with my electric gates. The gates are controlled by HASS through MQTT using a ESP8266 (NodeMCU) with the trigger pins directly wired into the control board. My gates open themselves from time to time and I’ve just lived with it hoping that one day I’ll figure it out but it’s been over a year now and still no brainwave.
The other day I came back from a two week holiday to find my gate already opening and when i checked the logs it had been opening and closing itself 5 times per minute everyday allday and night for the entire time I was away!
I did switch my router off before I left so that may have had something to do with it but it does it when the connection is good too. It woke me up last night opening again for no reason and it is opening right now every 5 minutes or so and the internet and wifi is good so I’m getting a bit desperate now…
When I restart HASSio all the relays in the house click away until it’s up and running again but the gates don’t open then…?!

I’m at a loss how to resolve this, help.:pray:

Have you tried subscribing to the mqtt topic with something like mqttfx to see if the switch is being controlled from HA or if it is an electrical fault?

If it is HA, have you tried disabling relevant automation(s) to see which could be at fault?

I had ghost triggers with my PIR on my ESP8266.
In the end I used a short run of cat5 (twisted pair, shielded) and covered the PIR in foil connected to the shielded part of the cat5 cable. This SEEMS to have stopped my ghost triggering (and moving the baby monitor a little further away from the sensor)

Does HASS show the gate as being triggered open, or does it just open ?
How long is the cable run from the device to the gates ?
Are the two devices (ESP and gateboard) using the same power supply ?

I think I can confidently say that it isn’t HASS, it’s definitely got something to do with the microcontroller, code, interference or power source. When the router is off and the HASS operating system is down it still triggers sometimes, like I discovered when I came back from holiday! :scream: The confusing thing about that situation is that the router was off and the Raspi is connected to the router via ethernet, so there was no connection to each other, it still logged all the triggers. I can’t controll the device when the router is down but somehow it logs its actions?

Every night my router radio turns itself off (wifes request! :roll_eyes:) and then the gate sometimes open several times and somehow HASS logs this too…?

The gate also opens when the router radio is on so I dont’t think it has anything to do with that, but I don’t understand it.

The power source could be one thing, when I restart the microcontroller it ussually sorts it…

It has it’s own power source, separate from the gates board.

I recently installed a powerline router outside nearer the gate and CCTV cameras to provide a better signal tinking that may help but it’s not really made any difference.

The frustrating part is I can’t force the issue so it is difficult to test for, it happens when it wants to.

There is one thing that makes the gate trigger repeatedly and that is when I open the TP Link app “Kasa”, for some reason that really interferes with most my MQTT devices. All my DIY MQTT devices start triggering radomly on and off. So I’ve stopped using Kasa but that makes all my devices trigger and not just the gate trigger. I don’t have these ghost triggers with any other device other than the gate on any other occasion.

Thanks for your interest guys, I appreciate the input.

cooljimy84 - what do you mean ghost triggers with your PIR, was the sensor too sensative?

I’ve just come accross this BRUH video… he seemed to have a similar problem with PIR ghost triggers

Wow thats quite a data dump

so ur router wifi turns off at night, but you then say

“I recently installed a powerline router outside nearer the gate and CCTV cameras to provide a better signal tinking that may help but it’s not really made any difference.”

if thats the same name and password as your router wifi the ESP will rehome to that…

What i’m pointing to is there is something causing the gate system to trigger, RF interference is my bet, either from the wifi on ESP or just a build up of “energy” on the cable between the ESP and the gateboard.

I would set it up like this.
ESP in the same location as the gate control system, and tapping into the same power supply (using buck converter if voltage is different) as the gate board. [so they have a common ground]
Use shielded cable between the ESP and gate control board, and many be even add a decoupling capacitor on the trigger pin. [to help reduce RC building up in the cable a triggering the gate]

Yeah, thats what i had.

The powerline router has a different name to the router for that exact reason. Also the ethernet is run from the router to the powerline access point so if the router is down so is the “extension”

The power supply is the one thing I’ve not tampered with here so powering the esp from the board sounds like an idea, I’ll scratch around as I may even have a suitable converter lying around, the gate board runs on 24v. If not I’ll order one and try this asap and then just wait to see if it works I guess

Don’t forget to post back and marked as solved when you get it fixed.

update/correction. urgh :crazy_face:

I’ve just opened up the control box and I have already trried to isolate the esp from the gate board with relays. I’ve been messing around with this problem since time began I’ve already forgotten all the things I’ve tried!

I’ll draw up a diagram with the connections but in a nutshell I use the board to trigger itself via the relay and the microcontroller opens or closes the relay obviously.
I used to have the pins directly wired into the gate board terminals and triggered them with a 3.3v pulse but with all the false triggers I thought this may not be so wise so isolated the two with the relays.

Not sure if changing the power supply to the board is going to make any difference now?

Maybe not, as the reply with ground to the ESP and just switch the gate board ?

I’ve just seen/heard weird things with electronic that interact with each other, but don’t have a common/shared ground.

If you have a pir connected to an esp, that is a known source of false triggers. You need to shield the pir from the esp.
But I am not sure about your system. Is this the case? If so, does the gate open when the pir senses motion independent of Ha being connected?

No, the gate is triggered with a switch only, no PIR.

The uploaded code is from the shared project below:

Agreed. With your router off the gate controller should not have been able to be contacted by HA.

The ESP doesn’t draw huge power spikes when transmitting (less than 0.2A) so a reasonable sized electrolytic capacitor (470uF to 1000uF) across the power lines close to the ESP module should prevent most problems there. An oscilloscope would be handy to check for noise / spikes on the power lines.

The ESP does output up to +17dBm (50mW) when transmitting which could cause interference with close by sensitive electronics (like cheap PIR modules). Move the ESP module a meter (yard) away from your gate controller electronics to be sure.

Once you have discounted the above sources of interference it’s really down to the code in the ESP.

I think I’ve found the culprit, I don’t understand it and I’ve been here before thinking I’ve solved it, for it to start again a few days down the line…
I took the relay/esp on a battery pack and moved out of the wifi range, when back in range on re-connecting the relay would sometimes trigger. Not everyime just sometimes but I have moved my main router so that I can now get a signal by the gate so I don’t have to rely on the extension anymore. The extension feeds my CCTV cameras and they never drop out so not sure why there seems to be this apparent blip for the gate connection but I’ve not had any ghost triggers since connecting directly to the main router. Also my other relays don’t trigger when my wifi or internet drops out?
So like I said, I still don’t understand what exactly is causing it but it seems to have stopped after changing some things…
I will set up a test mqtt switch connected to the extension and monitor it over the next couple days to compare against the gate switch so I can see if there are any ghost triggers on that but for now the gate remains closed. shew!

So when the wifi drops out the gate sometimes opens?
That’s still not ideal. I’d be looking at the ESP code to correct that. Either to stop it happening or make it constant (i.e. lose wifi and gate opens for access).

The code is slightly adjusted from the shared project by erickjoaquin posted earlier and used widely on other controllers throughout my house and I’m sure many other users houses too. Funny enough the gate hasn’t misbehaved once since changing the router log on details but today my hifi relay has switched itself off and on at lease 4 times today, which I’ve not noticed before, but the logs show no record of this
Maybe there is something wrong with the code…

The answer may lie in the interference. I need to find out from other member who use TP Link switches if they experience problems when opening their KASA app, like I said all my relays click away randomly when the app is open. Causes absolute chaos in my house so I stopped using it

I switch off the router radio at night (wife’s instructions) which automatically turns back on at 6h00 in the morning. This morning the gate opened when the radio came back on an I also heard relays clicking in my bedroom but no lights went on so I guess the on/off is so quick the switch doesn’t have time to react, the gate on the other hand only needs a pulse to activate and open.
Only the gate and a relay in the living room shows up on the log, nothing from the bedroom?

06:01 Diffuser turned off
06:01 Gate turned off
06:01 Car Gate turned off
06:00 Gate turned on
06:00 Car Gate turned on
06:00 Gate turned off
06:00 Pedestrian Gate turned off
06:00 Gate turned on
06:00 Pedestrian Gate turned on

This “self” triggering is just too odd and I can’t find any mention of anyone else experiencing this so I doubt its the code…

I’m starting to think I have a poltergeist?! :hot_face:

My money is on interference from the WiFi , at a push try changing the mode on the esp. mine are all on wireless N , but try some lowering to G or even of u can take the performance hit B !

Wait, does the ESP do a reboot if it looses WiFi / MQTT ?

Are the pins ur using used to set boot modes ?