Low cost mains voltage sensor

Hi
I have a requirement for a few mains voltage sensors, wifi connection
Got to be low cost, preferably not need flashing with other software and small.
I just need to know when power has been applied .
example: I have a lamp in the living room whic automatically comes on before sunset.
but once its dark the main light is manually switched on.
application would be to sense when the main lights have been switched on and turm off the lamp, saves me grabbing either the phone or laptop to turn off the lamp.
It doesnā€™t need to be instant so I could use anything that uses mqtt and power that device
on the same supply as the main lights, so when it gets powered up and locates the mqtt server and says its there, that could be used .

Just want to keep the cost right down
thanks
Richard

The easiest way is to use ESP8266 device (like Wemos D1 mini) flashed with ESPHome and react to it going online.
However, I have to warn you that sometimes those devices go offline and back online for no reason, which could create problems.
You can make the sensor better by using a cheap AC/DC adaptor connected do a data pin of ESPHome node defined as a button - that way youā€™ll see that input_boolean on when there is power applied to the AC/DC adaptor. Please not the that the node should be constantly powered up (it may be not, but Iā€™d recommend the former). I use this approach in my ā€œsmarterā€ bathroom extractor fan to keep track of the fanā€™s state.

And you can read this topic and choose something elseā€¦

Are your main lights connected to home assistant? If they were a simple automation would do it easily.

So IMHO the solution is to continue incorporating your house into HA !

I wonder if you could switch it off automatically given the lux of light outside.

It would not be the same as your request though, being triggered by the main light switch but if the assumption is that you turn on the main light because you believe itā€™s needed (dark enough) then you could determine if that is at a certain lux level each time. Once you work out that level then automate it based on that.

And to do that you might then try scraping a wunderground sensor in your neighborhood if there are any with a UV level indicator. I have my lights come on inside when I get to <20. And then sunset +offset turns on some external lights. I donā€™t use sunset for internal lights because I found it to be unreliable when itā€™s overcast.

Wouldnā€™t a simple hall effect sensor work for this? Use it with a D1 mini to detect the presence of a magnetic field. As soon as current is applied to the circuit it will produce a magnetic field sounds right in theory I could knock one up and test if you like?

Thanks for the replies
The main lighting is not incorporated in to HA , as the main lights are usually switched on manually when someone goes past the light switch on the way to the toilet, and that function canā€™t be automated.
But the suggestion of connecting to the data pin may be useful.
Iā€™ve ordered direct from Bulgaria 4 Shelly-1 , so I should be able to get at the data pin on the chip on those.
I can if I dont switch a too biger load, use the mains earth instaed of a nuetral, In the UK they are connected at the mains entry point to the building, but Iā€™ll have to be careful on how much current gets returned on the earth as the the protection trips are set at 30 mA difference between live and neutral, so I should be able tomount a Shelly 1 behind the swich.
Iā€™m not sure if there will be enough change in magnetice field for aa Hall sensor, as the current consumed will be 33mA.
If I could find a hall sensor sensitive enough that give a logic o/p that a possibilty, Iā€™ll check what devices are available.
Thanks for the ideas
Richard

Iā€™m going to start by wearing my nerdy-science-guy hat and pointing out you probably want to sense the current/power not the voltage. I would suggest a split-core current transformer, that way you could just clamp the coil around the live on the lighting circuit and not have to take any wiring apart. There are plenty of guides around online for doing this with Arduinos and Iā€™m sure it would be trivial to get it working on ESPHome or MySensors (see: https://www.mysensors.org/store/power, https://forum.mysensors.org/topic/2700/sct-013-030-energy-meter). The keyword I suggest looking for is non-invasive as anything else would involve patching a homemade device into you mains which I canā€™t recommend (probably invalidates your house insurance). I think that mysensors forum link would be the way I would go.

The only problem with current sensing that way Tom is size. The pattress size is the limiting the patress.
which I just checked and is a shallow 18 mm.
Also foun the light switch was broken as it was pinned up against the earth wire and the plastic housing was cracked., so that has to be changed .
As the pattress is too shallow for the switch Iā€™ll put a deeper one in. catch 22 is I fell off a ladder on Sunday and it looks like Iā€™ve cracked a couple of ribs, so using a hammer and chisel to put a deeper patress in is awkward at the moment.
I may be able to use a two hole ferrite bead, commonly called pig nose, if I can find one with a high enough permiability to be useful at 50 Hz.
Iā€™ll have a look at you link anyway, thanks
Richard

No disrespect, but that is the foolā€™s path. Earth is there for a reason and that is not it. Think about whether you really want the metal parts in every electric device in your house connected to the hot side of your electrics, even through a light bulb.

1 Like

To me there are better ways to achieve what you are ultimately trying to do (like just making your ā€˜main lightā€™ smart)ā€¦ but if you must go with detecting voltage as a means of control, just get one of these (below) and wire it to the input of an ESP8266 running ESphome. Simple.

OK lets point out something very applicable.
Unlike most contries the mains wiring in the UK and ROI is very safe.
We dont use plugs which are not fused and can be inserted either way round, 3 pin square so yiu can not reverse live and neutral,
the point the mains enters the house , neutral and earth are bonded, and usually there is an local external earth, in my case as Iā€™m also a radio amateur there are multiple external local earths, to reduce EMC.
Not only is the neutral connected at the entry point to earth the live and neutral pass through a RCD, which detects any earth leakage greater than 30 mA from live to earth.
So using the earth wire when there is no neutral wire availble is safe as long as you do not exceed the RCD limit of 30mA, which will cause the thing to trip and disconnect the supply to the whole house.

None of this rubbish about exposeing matal parts to the mains.
Bristish standards are very high , unlike the rest of Europe and the USA , from what Iā€™ve seen of American wiring its a bit of a joke, two pin plugs that you can touch the pins when putting it in the socket etc etc.
That cant happen in the UK and ROI , also Cyprus, as the sockets have shutters and the 3 pin non reverable FUSED plugs also have an insulated section on the pins,
The shutters dont open until the plug is inserted enough that all metal parts are not conatactable, thats why the earth pin is longer.
So I can use the earth wire, not accepted practice as a nutral feed as they are at exactly the same potential ZERO VOLTS wrt earth. the limiting factor is the detection current threshold of the RCD, 30mA.
As long as the quiesent current taken by a device is well below the 30mA threshold it will not effect the safety of the user and unit. At least not in the UK, ROI and Cyprus.

If you live in a country wher your main s wiring is below the standards used in the UK, please do not judge us all by your countries standards
Richard

Richard both commentors above are from NZ and AUS respectively, countries which arguably have the highest electrical standards in the world. However back on point 30mA isnā€™t a lot of wiggle room for current draw the rcd is going to trip within a tolerance which is usually under 30mA by around 5%

I doubt if their standard are higher than that of the UK, the Aussie plugs Iā€™ve seen arenā€™t fused for instance.
30mA isnā€™t much, but the wifi sectionusing a 8266 Iq is listed as 12mA, the harder bit is how much current is taken when the relay is energised.
But thats 12mA at 3.3V, it will depend on the power supply method used to get from 240V AC to 3.3V DC. If its a switching supply , maybe Ok , however if its just a resistive dropper, cheap and nasty and something that gets hot, its very tight.
the 8266 data sheet does give consumtion of up to 170mA if used at full RF power of +17dBm, but most devices are used at 1mW 0dBm, and the o/p stages are not run in Class A.
So the power consumption on Tx is going to be much lower.
A lot will depend on the size of the reservoir capacitor on the DC supply, which is proably 12v DC.
The Shelly-1 switches would proably be ideal for this application as they have a switch input , and if the switch state is sent to the mqtt server, it will give an indication of the switch state which can be used for automation.
The lights I need to sense are wall lights, so somewhere in between the switch on the wall is a junction box.
The catch is this house was built in the 1970ā€™s when they used chipboard for flooring upstairs and not wooden boards, Iā€™ve already had to replace the flooring in two rooms and the walls downstairs are solid brick and plaster, so its a sod to get at the cables.
Pendant lights are easy to automate as there is usually a live loop through and neutral available so the wifi switch can be inserted above the light fitting.
If I could the specification of quiesent current of a Shelly-1 with a non energised relay
it would help, also if when a shelly-1 is manually switched by applying volts to SW if the change in switch state is sent to the mqtt server. I can always disable the relay inside the Shelly-1 to reduce the current consumption.
This is not an easy application

What sort of bulbs do the lights take ?
It might be easier to use one of the many WiFi enabled bulbs and simply react to it appearing on the network when it gets powered up.

The idea of doing anything with the earth in a UK house that means it could be exposed to any sort of current really should even being considered. The failure modes that could exist by doing so are potentially lethal

4w LED candle types, wifi enabled eqivilents are expensiveand large.
the second paragraph of your posts suggests you do not fully understand the operation of a RCD.
Any failure mode of the wifi switch will cause the RCD to trip .
Infact the damge to the wifi device will be less than normal usage, which in a lighting circuit have a 5A MCB in line , or if used on the ring main a 30A MCB in line, unless power from a 13A outlet, and that depends on the fuse in the plug, which could be between 3 and 13A.

Ok, assuming E14, then a wifi candle bulb will cost you Ā£10, and doesnā€™t look too different physically, obviously my opinion.

I fully understand how an RCD works, along with the way that UK wiring is protected, and where discrimination comes in to play.

They are B22, where are you seeing Ā£10 the cheapest I can see is Ā£30 , and then its a case of will HA talk to them ?

Ok, hopefully the link will survive.

https://www.ebay.co.uk/itm/LOHAS-B22-500lm-WIFI-LED-Candle-Bulb-Works-With-Alexa-and-Google-Home/401734324180

Admittedly not quite the Ā£10 for an ES

For youā€™re application you simply need to detect if the device is on the network, there are several ways of doing this.

Hereā€™s one example of device detection you could use

Thanks Iā€™ll look into those

Iā€™ve ordered a couple so I have both options available