Power detector (electricity)

Hello please has anybody an idea how to create cheap wireless (let´s say ESP8266 based) electric sensor? I need to monitor if there is current in the wire or not (220V). Thank you.

1 Like

A Sonoff POW might be what you are looking for. It can easily be integrated into Home Assistant with the Tasmota firmware.

3 Likes

But I don´t want to measure power consumption. I only need to check On and OFF state. I mean that there IS current on the wire or IS NOT. I don´t think this will be able to do with POW because POW needs power to running and it measures the same line power consumption - right? I have no problem to get electricity to this device but POW can´t be powered by another source than the one it measures.

If you’re able to split load and neutral wires within a certain distance (several centimeters) then you can use a non-invasive current sensor that will feed data to ADC pin on the ESP8266 (if putting the sensor around a cable that has both wires then there won’t be any reading on the sensor).

However, there are alternate ways of finding on/off state: is there any state led on the device to be monitor? If yes, then a LDR can be mounted near it and connected to the ADC pin of the ESP8266 (ADC needs calibration but it’s rather easy to do it).

Or, use a NO relay connected to the ESP8266 which will control the power line. This way you will be able not only to monitor if device is powered or not, but also to control it through the relay (with MQTT, so that other home automation systems can connect to it, not only HA).

If you are not comfortable creating the 120/240V pilot light death lead use any transformer or switch mode plug pack (e.g. 240V to 12V DC) and an appropriately sized low voltage globe or LED & resistor.

1 Like

Maybe if you are more descriptive about what you want to do.

I am working on a project to tell me when the washing machine is finished. I will use a clamp-on current sensor going into the analog input of a NodeMCU. When the NodeMCU sees low current for a few minutes, it will publish an MQTT message to Home Assistant. It’s a work in progress, but that’s the basic design.

I would be interested in what you come up with here as I am also wanting to track when my washer and dryer finish their cycles. Like most people wanting to do this, mine are in the back of the house and hard to hear when they are done.

Hi Steve… clamp on sounds great approach. Would be great if you can share your project. Ideally i would be interested in

  1. Current state: Low or High current
  2. Changed state: Low->High and High->low

Looking forward to see your updates

It’s a planned winter project, but my experiments so far look promising. Normally I would just find somewhere on the control board to tap off a DC voltage, but pulling the units out of their closet space is an ordeal that I don’t want to have to tackle until we move in a few years. (These are LG washer and dryer, and I didn’t find out until after they were installed that LG has a WiFi option for the appliance status).

I’ve needed a similar solution for the washing machine.

Phase I:

I’ve started with a 433 Mhz weather sensor from which I’ve de-soldered the humidity sensor (it has 2 sensors, one for humidity and one for temperature; I’ve could have used instead the sensor for temperature, however the scale for humidity being 0 to 100% is much easier to work with) and soldered instead a LDR sensor. Then placed the LDR on top of the washing cycle complete led.
https://www.aliexpress.com/item/Digoo-DG-R8S-433MHz-Wireless-Digital-Hygrometer-Thermometer-Weather-Station-Sensor-for-DG-TH8888pro/32884832455.html

For the communication part I used RFLink on Arduino Mega http://www.rflink.nl/blog2/ as I have a bunch of weather sensors placed into locations I wouldn’t usually want to fiddle with electricity (bathroom, fridge). As the weather sensor uses two triple A batteries the risk of electrical shock is minimal even if problems due to high moisture arise.

The LDR sensor needs calibration and I’ve found that when the complete washing cycle is on, the LDR reports around 73% from the state led. When the led is off, the LDR reports around 20%.

Phase II:

This approach was fine however there were a few items that needed further tackling:

  • the weather sensor sends the data at a 30 seconds interval rate so there would be a delay between washing cycle completion and update of the sensor; not a major issue, though;
  • the batteries need to be replaced once per year; I could have used a LDR connected to ADC of an ESP8266 in order to not have to replace the batteries, however I decided not to take any risk of electrical shock in a room with moisture;
  • the sensor is silver thus it breaks the fengshui :slight_smile:

I’ve then switched to the use 433 Mhz buttons, however, any type of switch (Zigbee/Z-wave/etc) can be used. The idea is to press the button after washing cycle begins and then receive a notification/turn on lights/etc. when the time delay set through the input select elapses. There are also all black and red&white combinations of buttons.

Also, another issue with the LDR sensor option was that I couldn’t mount it to the dish washing machine as the state led is only reachable when opening the lid. Putting one button on the handle solved the problem.

I use an OpenMQTT gateway on Arduino (wired, so I don’t have to deal with wifi issues or delays in sending the payload to MQTT broker) to interface with the 433 Mhz devices but I could have used also the RFLink mentioned above. I have multiple PIRs and open door sensors of the 433 Mhz flavor so this required little work to setup.

For the input select delay a more fancy presentation (such as "30 minutes/1 hour/2 hours/etc.) could have been used and then set an automation to modify the value of an intermediate sensor to the template of “hh:mm:ss” but this is on the to do list for the next overhaul. Depending on the length of the washing cycle any delay can be set (or even have two buttons, one for shorter cycles and another for longer ones).

And the most important part: the button is the same color as the washing machine :smiley:

Other ways that I’ve considered for getting the state of the washing machine:

  • clamp sensor (non-invasive magnetic sensor) around one of the wires going to the socket; this would have required cutting through the insulation of the wires so unacceptable in a high moisture environment;
  • smart power meter (there are a few Zigbee and Z-wave options that are small enough for mounting into tight places; wifi sockets are much larger so I’ve excluded them from the beginning); this has also the monitoring advantage so when the level of current is below a certain threshold the washing cycle is complete; a concern might arise from the fact that the washing machine uses inductive load however it is unlikely that it would cause an electrical problem as the breaker would probably pop before the switch turns to flame, but you never know :smiley: (https://www.youtube.com/watch?v=Tq-EpR-8R0w);
  • vibration sensor (there are 433 Mhz and Zigbee options); oddly enough my washing machine doesn’t vibrate sufficiently to trigger it (it is securely mounted so the vibration level is minimal);
  • sound sensor connected to ADC pin of an ESP8266; again, running wires in the bathroom :frowning:

Here’s my setup.

The first part of the action in the automation deals with resetting the binary sensor (this is required for the 433 Mhz switch to be put to off state). Otherwise, when pushing the button, it would receive the same payload again and again so a single state would be recorded; however, depending on the type of switch used, it might not be needed.

Binary sensor (payload on is the message received by the 433 Mhz gateway from the wireless switch):

- platform: mqtt
  state_topic: 'home/433toMQTT'
  name: 'Washing machine'
  payload_on: '10342561'
  payload_off: '10342561Off'
  retain: true

Input select:

  washing_machine_delay:
    name: Washing Machine Delay
    options:
     - 00:30:00
     - 01:00:00
     - 02:00:00
     - 03:00:00
    initial: 02:00:00

Automation:

- alias: Washing machine complete
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.washing_machine
      to: 'on'
  action:
    - service: mqtt.publish
      data:
        topic: "home/433toMQTT"
        payload: "10342561Off"
        qos: 0
        retain: true
    - delay: '{{ states.input_select.washing_machine_delay.state }}'
    - service: light.turn_on
      data_template:
        entity_id: light.livingroom
        rgb_color: [255, 255, 0]

interesting!

I have a capilar thermostatic switch which turns on Grundfos Alpha2 circulating pump in heating circuit. I need to get info if this pump has power. Maybe it will be better to buy flow meter and measure water flow…

Hi Jiran

If I understood correctly you want to plug something on the wall outlet and detect if there’s power or not, right? The dumbiest/easiest way is to plug something with a IP address (a old router, a esp8266) and ping it. If it pings, there’s energy, if not…

1 Like

Thanks @clyra I thought about the same way like you. Yes this is possible. But there is a need to continually ping this device and this causes continual wifi traffic etc. + there is some delay… This solution is sure possible but not smart enough :slight_smile:
BTW is there some esp8266 which is possible to power using 220V only? (like sonoff devices)

Ping sensor in HA barely generates any annoying traffic. Can also use a different interval than the 10 seconds to scan for for the devices (per platform setting) by adding to the ping binary sensor:

scan_interval: x

Or, use the LWT (last will and testament) MQTT topic of an ESP8266 plugged into that socket so that whenever the ESP8266 connects to MQTT broker sends the online payload.

1 Like

@Jiran

There’s another “smart” way, but you will need some knowledge of electronics (which I don’t have). But it’s possible to use esp8266 + esphomelib and watch for a GPIO port state (low, high). The part I don’t know how to do is how you lower the 220v to something which can be fed into GPIO port. Also, there’s some models of esp8266 which you can attach a battery so it would reply even if there’s no power in the outlet.

BTW, you know that a sonoff is a esp8266? you can flash it with tasmota or esphomelib!

Replying to myself and to @Jiran

I just remembered that I have something like that at our datacenter and was made with a dry contact relay. If there’s 220v at the input it close the relay and you can detect it on the esp8266 (we use something fancier which is a ready made solution called “posseidon”).

In the beginning, it said trying to detect current, now it sounds like voltage. Current would be if some device was on, and drawing power. Voltage would mean the socket is live.

I recently made a fairly simple voltage detector. I took a walwart from my junk drawer, this one outputs around 8.5 VDC. So if you plug it into a live outlet, you get 8.5V. I built a voltage divider with a couple resistors to drop the voltage to 3VDC. You can google the circuit, and find online calculators to tell you what value resistors to use to get a specific voltage.
Fed that voltage to a pi to read it. You could also feed to an esp, and have the esp read it as a discrete input.

If you had or bought a walwart that outputs from 3 to 3.3V, you don’t need the two resistors for the voltage divider. I have a bunch of resistors in my junk drawer, so it was easy for me to build. You can also buy a voltage converter that outputs 3.3V.

Back to my circuit. turn the outlet on, and if outputs 3 VDC to the pi. Turn it off, and the output drops to 0V.

OK so let’s define your problem: You have an AC power supply being controlled by a thermostatic switch that is not linked to HA. Upside of the switch there is always 220v between phase and neutral. Downside of the switch there is 220v when the switch is on, 0v when the switch is off.

The first and obvious solution would be to replace the thermostatic switch with an IoT compatible thermostat. Perhaps too simple, and perhaps you don’t want to screw with what is there.

So let’s assume we don’t replace the switch. The things we need to think about:

  • detection of power on the “downside” of the switch, without importing live AC into our electronics or our fingers. Here the usual solution is a optocoupler.
  • microcontroller - there are many but something arduino based is easy to work with and generally available. I include esp8266 as an arduino device.
  • communication with HA - wifi? zigbee? zwave?
  • power supply - this will to a large extent depend on the communication - zigbee or zwave can be battery powered, but wifi is generally too thirsty for battery power. Even if the battery lasts a year it will eventually run out, and we have an always on 220v power supply “upside” of the switch, but not “downside”. So let’s power it from above the switch where there is always 220v.

So TL;DR - at the switch wire an esp8266 power supply on the unswitched side. You can hack up a cell phone charger, or use something like a Meanwell IRM 03-05

Connect it a Esp8266 like a Wemos D1 Mini.

Get an optocoupler and connect it to the down/switched side of the switch. The way to attach an optocoupler to the ESP8266 is all over the internet, as is the software to turn an esp8266 into a IOT device - tasmota comes to mind.

Alternatively use a sonoff basic with an optocoupler connected to the spare pins. That saves finding a power supply.