TLDR:
What kind of electronics would I need to detect 220v mains and use this to trigger GPIO14 on a sonoff basic?
My goal is to have setup where the light switches works as they do now, bu the light is also controllable via mqtt.
In my house (in Denmark) i have light sockets that looks like this picture: . From this socket I can get both uninterrupted 220v (from M2 and N) as well as a 220v line that is controlled by two switches (a 3-way switch for the americans). My idea is that I can connect the constant line to the In of the sonoff and somehow use the āswitchedā to toggle the sonoff.
I have managed to flash tasmota on a sonoff, connected it to HA, and I have configured it to toggle the relay when GPIO14 is connected and disconnected from the ground pin. So I am looking for a way to do something like that, but controlled by the 220v mains circuit.
Im in NZ which has 240v I have 10 Sonoff in my house and have more on the way
what I do is flash them with Tasmota put them in the wall to control the lights and with the switch to GPI0 14 and ground on the sonoff HA can turn them on/off and wife can turn them on/off at the switch and HA keeps track on there status
and those ā240V 220V AC Mains Sensor opto-isolatorā look very cool will look more into them
I have watched the videos by @DrZzs and others, but they donāt cover my exact situation.
I could follow his instructions, but that would require:
that i mess with both switches to install sonoffs
that my mqtt broken and HA instances in online for things to work.
What Iām imagining requires only one sonoff to be places by the lamp socket (so no messing with the switches) , and will work even when the wifi is down.
Since I have two mains circuits in the lamp socket, one that is constantly on and one that can be switched by the existing switches, all I need to figure out is how to use the switched AC circuit to toggle the GPIO14 pin on the sonoff.
I have ordered one of the opto-isolator devices to experiment with, so that might be a feasible way.
I was able to do this with several Sonoff Basics. I had a similar wall outlet that had both a constant and a switched socket. For the switched socket, I used a 120VAC-to-12VDC transformer (wall plug) connected to a 12V automotive relay to switch the GPIO on the Sonoff, It worked great!
Sonoffs donāt need wifi to work directly, if you connect the switch to GPIO it works exactly like a normal switch if all is up or when thereās no wifi or HA is down.
There are a lot of variables depending on what your local wiring standards are, be they the weird US ones, the sensible UK ones or the could a mix of both that seems to occur in other countries. If you could elaborate on what the Danish standard are we could give you more specific help.
I understand that sonoffs work without wifi. But I think the 3-way setup in the drZzs video does not. Two of the sonoffs just sends mqtt messages and then HA sends a message out to the one actually controlling the light.
With the relay idea from @bgehrich or something similar I hope to avoid this issue and use only a single sonoff (+ a phone charger and a relay board and whatever else).
Thatās why I asked what the Danish wiring standards are, if theyāre like the UK you can do it with one and it works exactly how I said because thatās what I have in my house and demonstrated in other thread on the topic.
Obviously if youāre determined to make it overly complicated without checking if itās actually necessary carry on
Hiā
Iām new to all this Home Assistant, Sonoff/Tasmota etc., but learning every day
As Iām quite reluctant to āimplementā Sonoff devices in my new house in/behind my wall switches (Iām in Denmark as well), Iām planning to implement in the same way as Pengman describes. Mainly due to the potential fire hazard with these devices behind the wall and covered in insulation Iāve actually bought the same optocoupler as in the link to detect 230v presence and would like to implement the first devices ASAP at the loft for some outdoor downlight led fixtures in carport etc.
But could i wire the optocouplers output directly to the GPIO14 pin without additional pulldown resistor ?
Iāll drive the optocoupler with 3,3v from the Sonoff PCB, so output should be same voltage.
To be honest I never figured out how to use that octocoupler device, but Iām no electrician so there might be a way.
Below are my observations (from memory)
To function as a switch I needed to have a relay that switches connection from GPIO14 to GND, it might be possible to configure it otherwise, or to use a transistor as you suggest, but I never found an explanation that was at my level of understanding
When fed from 3.3v the āonā voltage from the octodevice was very low, too low to drive the relays I had then.
I ended out pursuing the idea proposed by bgehrich, but I havenāt finished it yet.
Iād like to hear if you have any success with your project.
I still have no idea what you two are trying to achieve but if it helps the Sonoffs also have 5v on the board before going down to 3.3v, Iām using the reverse of that and using a USB charger to power some of mine that are switching low voltage DC.
Before anyone asks, Iām using Basics rather SVs because theyāre cheaper, have a case ā¦and I had several sitting on a shelf doing nothing
Take a look at the Shelly devices. They support tasmota and have 240/220v switch inputs. From reading your posts you want to place a wifi relay at the light socket in your roof and use the switch on the wall to control them with another wire.
What I would do if you cannot modify your old wall switches is to place a Sonoff in the roof at the light and use a Xiaomi button or lightswitch to switch the Sonoff through wifi. If your wifi, Hass or Mqtt goes down you can use the old wall switch by setting the Sonoff poweronstate to 1.
Thank you all for the replies
Yes, as I live in a fairly new house (build 2012) I would prefer not mess with the switches if that could be avoided. But I agree that implementing the Sonoff Basics in/behind the switch, would be the easiest approach for a satisfying solution that would maintain use of original switch (also without Wifi) and additional HA/Wifi/RF switch control.
But I thought that the next best solution would be to use the 230v output from original wall switch as detection to switch the Sonoff Basic at the roof near the lights. I believe all main cables could be found under 50-60cm of insulation
Iāve actually tested my setup and it works perfectly
230v output from wall switch to Optocoupler. Sonoff Basic feeds the optocoupler with 3,3v, gnd and output from optocoupler directly to GPIO14. No other special settings in Tasmota besides setting Switchmode 2 (inverted FOLLOW (0 = On, 1 = Off)) and Switchtopic 0 (direct relay). Last to maintain use of original wall switch if wifi should be down.
I use the āsingleā optocoupler version and the Sonoff Basic has no problems delivering enough power to operate the optocoupler and switch relays. That might not be the case with the 3 on 1 PCB optocoupler ??
Iām just a bit annoyed about the fact that the wall switch could be in a āwrongā position if used to turn Sonoff on and Sonoff later is turned off again via wifi switch, HA etc. That could be fixed by adding a spring to my LK wall switches which would turn them into switch buttons instead. I actually believe that most LK wall switches are prepared for this ? But Iāll have to investigate this further.
Once again, thank you all for your input and suggestions
Just an update to this topic. Iāve bought some Shelly one switches as well. As you know thereās not much room left behind danish wall switches and ceiling outlets. But a 'Tasmotaāed Shelly 1 actually fits behind standard LK Fuga switches. Itās a tight fit, but it can be done Iāve also installed a Shelly in a ceiling outlet. This is impossible to do with a Sonoff Basic without serious modifications to the switch wall socket. The Shelly is also much saver to use in wall/behind outlets in my opinion. Iāll go for the Shellyās for my future smart updates of switches in my home