Sensor to know if there is power

Hi! I’m looking for something very simple but I guess I haven’t found the right keywords: basically it’s plugged to the main house power source and “transmit” when it’s on, preferably using the wifi but I can compromise eventually.

Then I capture whatever is transmitted and know the city power is working (or not). Of course looking for something cheap. Any suggestion?Thank you.

I have a mains power to DC 3.3V plug pack supplying a raspi gpio. The raspi itself has battery backup, as should your home assistant or this is pointless.

I thought about using a Bayesian sensor. If a lot of mains powered devices (smart plugs, lights etc…) go offline but battery powered ones do not, it would be likely that mains power has failed.

I see. Thank you for that very prompt answer. I didn’t know of such sensor.

Actually thinking about this more, the sensor just needs to be on to know there is power. I could for example have a LED and a light detection sensor and that would work too. I was just thinking of something all integrated that has minimum configuration needed. Looking at the Bayesian sensor it seems there are a few support questions related to version numbering and compatibility.
Let’s see it seems like a “complicated device” from a very simple task.

PS: actually I found this page https://www.home-assistant.io/integrations/binary_sensor/ . so what would be the device to use to get that power binary sensor listed below in the page?

You might just have an, e.g., an ESP8266 / ESPHome-based device plugged into the wall. When it starts up, it publishes an “on” value for some binary sensor. And you have an MQTT LWT topic that the broker will transmit when some keepalive mechanism fails during power loss.

I’ve not thought real hard about how to configure the binary sensor, and if you can have an “off” value default when the sensor is otherwise unavailable?

1 Like

Yes that’s definitely something along the way. It’s nothing crucial, just on/off in fact, where I don’t care about off, only when it’s ON again.
I also found that https://smart4house.net/en/products/binary-sensor but not sure what is this smart4house thing (nor have I been able to find it on eBay as they say yet.

You can do that with the ESPHome and api using the status sensor too.

Yes so the ESP8266 is probably the way to go. Thanks a lot for all your comments and help in solving my issue.
:slight_smile:
Fred

You could get a cheap Sonoff switch, and reflash the firmware to avoid having to build and package the hardware…

1 Like

Hi! That sounds interesting (as I was also planning to get a few other Sonoff devices). So there would be only 2 wires as input which would transmit to the Wifi when there is city power. Would that actually let me know it’s on?
Thank you.
Fred
ps: also it says max current 10A. Would that actually be a problem plugging it in at the incoming electricity line?

That’s a maximum load current rating. You have no load on this, you’re just using it to sense the voltage. So no it is not a problem.

Yes. You will have these power states (for power on /off):
On.
Unavailable.

Or using the ESPhome Status sensor you will have
Connected
Disconnected

Or using MQTT LWT, you will have:
Online
Unavailable

All of which can be changed using a template sensor to whatever states you want.

Cool, that sounds even easier that the ESP8266. Thank you very much.

I’m really curious how you are going to use this. If the power goes down, will your HA instance still be running? And your internal LAN/WLAN? And your internet connection? How will you be notified if the power goes down?

haha… actually I want to be notified when the city power comes back, so I can go outside switch off my generator and go back to the main (and quieter) source of electricity. This avoids me to:

  • Get out of the house every 10 minutes to check
  • Ask the neighbors if there is actual city electricity (as the installers “forgot” to add a small led to let me know)
  • Be alerted as soon as power is back
    When power is down I know right away as some unneccesarry devices will go off such as fans and lamps.

Received my Sonoff Basic R3, struggled to flash its firmware under Linux (had to use 2 guides to make it work) and now I have Tasmota on it. Next step is how to get the reading I’m looking for. Is there any documentation about scripts/automation and Sonoff Basic for my use case somewhere? I’m really starting from the ground up and so many things to learn. So any tip will be welcome!
Thanks a lot.

Fred

do you have the mosquitto addon installed?
first step is set up mqtt on tasmota (ip, username, password, topic)
then add your switch to HA:

This could be automated pretty easily if you have a battery starter for your generator also - just have HA start it when power goes out, and stop it again once power is back, should be doable with just a couple of relays.

Reply to both of you: so yes I flashed the Sonoff Basic and it’s running Tasmota and I also installed Mosquitto Broker on HA. Is this what you are asking? I can see/add the Sonoff device as a sensor but that’s about it. I think… (added some lines into my yaml file while writing the post, re-tested - no improvement though) I may have some values missing so I added payload and state, still I’m confused and don’t see what I’m trying to see.

I don’t understand the battery need actually. What I’m looking for is to know if power is going inside or not: is that the payload_on/off value? Then when it goes from OFF to ON I’d like to trigger an alert as well as eventually show those 2 values (ON or OFF) on HA home screen.

Oh no, you don’t need a battery starter for the solution you describe, I was just thinking if you have an automatic (turnkey) starter for your genny it could be starte remotely:)

Well here is how i solved it in two different ways:
First of all you do require a UPS for that purpose. And it should be connected to your modem/router and HA server; otherwise when the power goes down; there is no way HA will know it or send you a message about it.

  1. With a connected UPS to HA, you can use NUT or any other UPS component to follow up Online or battery discharge and send a message accordingly.
  2. I have a consumer grade alarm system which has its own battery and IP Module. It has a binary sensor ‘mains’ which tells if the mains power is on or off. This can also trigger a message to HA; provided that HA and the router/modem still has its own UPS battery.

Hey!
Thanks a lot for the follow up. I think I didn’t explain myself correctly (and yes there is a UPS for IT stuff including HA). What i need is that Sonoff basic monitoring (so there is power) to now when power is back. So if I understood correctly that would be the payload on/off? or is it state on/off? So what that is goes from off (or no signal) to on I would like to trigger “something”.