Need help adding a remote ESPHome to a local HA instance over the internet, please

Greetings, it has been many moons since I have posted.

I want to ask what the best way is of accessing a remote ESPHome device safely.

Here is my specific use case.

I moved my ultra-ancient parents into a flat nearby where I can keep an eye on them. It has a 5kw backup inverter, because the power out here is prone to drop.

But it’s also colder than I’d like in that flat, so there’s an electric oil heater.

When the power drops, the inverter kicks in seamlessly, but does not enjoy carrying the load of an electric heater for obvious reasons, and the batteries get chewed up quickly, which the landlady is not particularly enjoying.

So to avoid drama, I’m figuring that a Sonoff PowR2 with ESPHome will let me turn the heater off if my HA detects that the grid has dropped. Easy enough in theory.

But.

The cottage is not on my network, but does have Internet access. I need to figure out a way to connect that ESPHome device to my home network transparently, because their inverter isn’t smart, so I will need to tell the device to toggle when I detect that the grid drops.

I thought of two possible ways so far.

One, somehow host an MQTT server somewhere exposed to the Internet; I have no idea if the password scheme used is robust enough for safe use, but I suspect this would be sort of easyish to configure, just need a server somewhere.

Or two, VPN to that network. I worry that I don’t understand VPNs well enough to achieve this, and also, I would need to build them a pi or something to run the VPN software over there. Seems harder. I don’t control that router, so I can’t change the config, I’d need to install a pi somewhere over there.

Do you have any suggestions?

A third way would be to make it not reliant on anything else but itself.
I mean if your HA can detect the power is out, then perhaps it’s possible to do that locally also?

2 Likes

Hi @Hellis81, thank you for your suggestion. I’ve been thinking about that too, but I can’t figure a way.

Because their inverter isn’t smart, I can’t think of a way for any hardware there to detect that the grid has dropped, because it would of necessity be powered by the inverter. Its experience, therefore, will always be that everything is normal.

My inverter is a Victron with smart features. My HA knows the grid is down because the inverter tells it. It then does management based on battery level.

I could tell my Mom’s PowR2 to turn off when I detect the grid is down, if I could communicate with it over the Internet. I think that problem might be easier to solve than having the local device detect the grid drop. Unless you can suggest a way to detect the grid drop locally? That’d be sick too.

Without really understanding all your details but you could have the esp create/update a file on a shared network drive. My router allows to have a usb attached and I can read that in and outside of my home.
EDIT: I do not exactly know how to do write from esp but I read this is posisble quite a while back but have no use case for it so ‘forgot’

Is all outlets powered by the inverter?
If one is or could be wired to not be powered from the inverter when the grid drops then there is a possibility.

If you control your own router/firewall and can whitelist the (static) IP or domain from your parents’ house you have a very safe communication path towards a mosquito HA addon.

Otherwise, you could setup the mosquito addon to use certificates;
and configure ESPHome to use them.

(Ps: I don’t use certificates myself, so I don’t know if I this works and how robust it is).

Still, I’d prefer a totally local option. What if internet goes down as well?

As said above, a non-inverter powered socket would solve all your problems. If need be, plug in a power meter for cost allocation.

Considering cost of a PI or similar I would not bother with Internet and remote access ! Put a local HA that handles everything no ?

Hi @Hellis81, yes, in both my house and hers, the inverters are whole-house inverters. That is the difficulty: no plug to monitor anywhere. I guess a CT clamp could be set up, but again, I can’t shake the feeling that this can be done easily in software somehow. That would be my perfect solution, since it would not require crawling around in my mother’s roof (note I am a fat old man).

But totally. I thought about this too. It’s a workable line of thought, if it weren’t too crazy. CT clamp before the mains in, maybe. It’s doable. Don’t think I could get a CT clamp in my country easily right now, though. Could maybe scavenge one from the ESPHome monstrosity I built to monitor and disconnect the washer and dryer. But PowR2 is in a box in the shed. If I can do this securely in software, it’d be a laugh.

Hi @JeeCee, thanks for addressing the MQTT idea, it seems like the easiest to implement because, like, MQTT. I know the guy at their ISP (we are wayyyyy rural, is why it’s a guy), and he could totally hook up a static IP for her, if it isn’t already. I like this.

There are sadly no plug circuits that aren’t on the inverter.

EDIT: also, seriously, the national grid is a piece of shit out here. The ISPs know that too, so every radio tower has a big ass solar panel and enough battery for (I think) 36 hours of runtime. Internet hardly ever goes down, even the broke dudes have 12V batteries to run their WiFi. It’s like a cultural thing here now.

Hi @vincen

I thought about that first, but there is still no way to detect locally at her house when the grid goes down. That means I would have to tell it somehow, so we are back to the same problem.

Also, there have been no RPI available in my country since early 2021. You can special order for 4x the price. If I build my Mom a HA of her own, then I would have to give up my Rhasspy server. I need it, for when my HA needs to wake me up urgently at night if some shit happens on the farm.

Hi @vingerha, that’s a very creative idea, I like it.

But I feel like it sort of needs reinventing the wheel a little bit. MQTT is already a thing, VPN is already a thing, and both of those are easy to integrate with HA, which would give me a better idea of what’s going on over there, and leaves open the possibility of adding other sensors as time goes on. I am 100% about making my Mom comfortable. Right now she’s cold because she’s scared of killing the inverter. Is why I want a faster fix.

Even so, I like how you think, I would have never come up with that. Pretty sure I can use that idea for some weirdo logging ideas I have. Very cool. Your brain is most excellent; my compliments to your forebears.

It might sound rustic but why not use a simple device based on ESP for example plugged in a wall socket somewhere and when you see it disappears (go offline), it means you have lost main power :wink:

Well I talked about PI as an example, basically you can use Odroid, Tinker,whatever is avalaible on market night now (Tinker board were still avalaible 2 weeks ago when I ordered some here in Switzerland and France too :slight_smile:

I understood you meant that, but it requires hardware that I likely couldn’t afford to import. I should have been more specific: I am in the third world.

I very much enjoyed my opportunity to visit the EU. It is beautiful there, as are your cultures. I only saw the Netherlands, and Poland. The other place I went isn’t in the EU anymore. Would have loved to see France. And Switzerland, and Germany, and every other country that participates in Eurovision. Well, the ones in Europe anyway.

So where do you live? Sounds like in the middle of nowhere…? :rofl:

The safest way to do such a thing is using a VPN. But I wouldn’t advise to do so, as someone already said, who gives you a guarantee, that if the power is out, the internet is still working? And as you said yourself, you’d need some additional hardware.

Anyway, how do you detect a power outage? This might be your entry point. :slight_smile:

In theory you should be able to measure the output from the inverter. If you put a Sonoff into the line from the inverter to the main line of the house, you can measure if it’s running or not or better if it is pushing poweer to the house.

But all of that depends on what you actually have available. You should start with a list of what you can use, you might be able to use, and what you can’t get for an affordable price so won’t be able to use.

One thing is for sure, you will not get away without additional hardware. :slight_smile:

Hi @paddy0174, thanks for your input. I hear you completely, that you’d like me to do this with hardware.

It’s a little embarrassing, but it’s a hard year, and I probably can’t afford new hardware this year, even if it was locally available. I really need to solve this with what I have.

The internet outage really isn’t the issue you think it is, because of the way that the people of this community have, over time, responded to the crumbling of the national power grid. Everyone at minimum has a generator by now. If you’re fortunate, you have an inverter, and pretty much all businesses do by this point. If you’re insanely lucky, you made the call to get solar a few years ago, and you’re so f***ing grateful you did.

I couldn’t put a Sonoff where you’re suggesting, because it would then be permanently inline, and it is not remotely powerful enough to tolerate the total drain of a dwelling. PowR2 maxes out at 10A, 3500W, but it can only hold that level for a short period before burning out, which is why you can’t use it for geysers.

If I absolutely had to do it in hardware, I’d put a CT clamp on the mains in, and run a line from there over to the room where the PowR2 needs to physically be, and figure out how to connect it to spare pins. So long as I can get any reading at all from the CT clamp, mains power is on.

I am not sure if PowR2 has sufficient spare pins to support a CT clamp, so we’re probably looking at a custom build anyway. This solution will require a fat, balding old man to crawl from beam to beam in the ceiling, and drill holes, and fuck around with mains power.

Or I could use a remote MQTT broker. I think I’m going to try to do that now, and come back if I mess it up, which if past form is anything to go by, will be quite likely. I have 2 PowR2s on the shelf! I can screw up at least once! Yaaaaay!

EDIT: nips. PowR2 doesn’t have an analog pin. No CT clamp possible, I’d have to build something based on an ESP of some kind. Wasteful to run two devices to do the job of one.

1 Like

I’m sorry, that shouldn’t have sounded that way! Believe me, I can more than understand that in these uncertain and trying times one wants (and often needs) to work with what is affordable and/or available! Me included! :smiley: We all have our packages to carry, and from what it sounds yours doesn’t seem to be a light one. :slight_smile: I’m living in Germany, and thanks to that idiot in Russia we have something we wouldn’t have expected in our strangest dreams. And I can only imagine, how hard this nonsense in world politics is hitting countries, that are not that decadent like ours is. I know, I am lucky, but I get the feeling, not all of us here in this country are seeing it that way… :wink: But I’m wandering from the subject… :rofl:

Reading what you said, I 'd say you live in SouthAfrica. :slight_smile: That would make sense, as you would know from your energy provider, when the power is cut out, and when it comes back on. And it would make sense, because your power is cut off the same time as your parents is. If the energy provider is the source of the outage and not an “accident”… I’ve seen a great documentation about the outages in your power grid to save it from a total collapse. Congratulations, your politicians really did a great job in the last decades. :slight_smile: :rofl:

But the reason why I’m speculating is, you didn’t answer one of my questions and it could be useful to find a solution. :slight_smile: How did you manage to know the power is out? If this is something like a schedule, it should be possible to work with the provided times.

So my questions again:

  • how do you know about the outage?
  • what hardware do you have available?
  • what hardware could be affordable, if it is a necessity (means not being able to do it otherwise)?

Cheers from Munich! :slight_smile:

1 Like

Hey @paddy0174, You called it, I’m in the extreme Northeast of the country, and it is not possible to hit my nearest neighbour’s roof with a potato cannon, because the distance is more than twice the current world record. I looked it up. But when you look across the valley, it looks so possible. Donk! It’d be great.

Munich, eh? I am keen to visit Germany one day. I was educated by German nuns, and I was taught music by Frau Henschel, an extremely patient but also grumpy lady. Also the nuns had the best chocolate, but you really had to kiss ass to get any.

Right, so, we call our HA instance “Lucy”. I have a Victron Multiplus II inverter, which has smart features. It’s integrated into Lucy, and that is how she knows that the grid has dropped. If it does, this triggers various conditional automations to do with whether the sun is shining or not, and if necessary, she can start shutting down appliances in order of non-essentials if the battery gets low for whatever reason.

So. I know when the grid is down, because my inverter can report that data.

As to what I have on hand, if the A-Team was locked in my workshop, they’d mostly be able to engineer a pointy stick with an LED taped to the end. I have 2 Sonoff PowR2’s, and a roll of duct tape. I love my Mom. If I don’t crack this MQTT bullshit by dawn, I’ll admit defeat and go dismantle something and get parts. Guess I can repurpose the monstrosity I built to manage the washer and dryer loads when we’re on battery. It was noisy as hell in operation anyway.

You really don’t have much material at hand to go on, don’t you? :rofl: :rofl: But I can clearly see your point, I’d have froozen hell for my mother, if necessary. :slight_smile:

So that leaves us with what? An external MQTT broker? Have you thought about using a CloudMQTT? That should be an alternative, if the internet has at least a better reliability than the power grid. :rofl: :rofl: And it would be easy to use, no real configuration needed, does that sound like a deal? :slight_smile:

HiveMQ has a free plan for up to 100 devices, that should at least be enough to just test that method. If it won’t work, you haven’t done any harm (or costs) and we can search again, what woould be the best solution for your mother! :slight_smile:

Hey @paddy0174, just to let you know I admit defeat.

MQTT is a dead end because to be secure you have to use TLS, which I have failed to make work on the ESP8266 inside the PowR2. Looks like you can only really do TLS on an ESP32.

So FINE it’s a hardware solution of some kind. Which basically means a device that can monitor the grid via a CT clamp, and since that’s analog data, it’s a board with an analog pin. And since this isn’t likely to be the last time we have this issue, we may as well just put a Home Assistant over there.

Except, still broke, and no Raspberry Pis have been available in this country for more than a year.

So it’s either the Rhasspy box, or the RetroPi.

Voice notifications are a luxury, but they’re also very useful if you’re asleep when a pump starts sucking air. I’d like to hang onto that.

Sorry boys. You were never as into Contra as I was anyway.

Easiest way to detect mains is to use optoisolator. Mains will light a diode that will put a transistor in conducting stage. Transistor will be fed with voltage from ESP and goes right back to ESP input.

Or if you have two ESP’s lying around, power one from the mains and second via inverter. Assuming the inverter is always running?
Then use hardwired signals from mains powered esp to inverter powered esp. When mains go out, make sure the output pin drops as well.
If you use that arrangement without optoisolator, you must connect GND between ESP’s. Make sure your power supplies are tolerant.

https://smartsolutions4home.com/detecting-mains-voltage-with-microcontroller/

And run local automation in the inverter powered ESP. You can send data to HA via webhooks. But ESP is not able to receive a webhook.