Is it possible to ping an IP address from inside an ESPHome node?

Hi all,

Short version: is there an easy way I can do an automation inside ESPhome that will ping an IP address and then do something if there’s no response?

Long version: So I have this IP camera on a backup battery, in an area that suffers frequent outage. When power goes out, it runs off battery, but, if the battery drops below 12V, then the camera crashes, and won’t reboot when the power comes back.

To solve this, I’ve used a little ESP-01 module on a pre-made relay board (the horrible kind that you have to solder and pop off a resister to get the thing to work). I chose this module because a) I had one lying around, and b) it has NC/NO contacts, unlike a Sonoff. That means I can run the 12V the camera needs through the NC contacts, and the relay need only engage to reset the camera, so there’s very little chance of the relay getting stuck.

Now, it works great, but, after a series of SNAFUs around the 1.14.3 upgrade, I am looking at moving certain automation functionality out of HA and into the ESPHome nodes themselves. That way, things will run as they should even if contact between the node and the hub is lost.

So, I had Node-RED pinging the camera every 5 mins to see if it was live, and triggering the relay if it wasn’t. That works, but it presupposes that there’s a good wifi connection. In reality, there might be a million reasons why wifi is currently unavailable.

Therefore, I’d like to move the ping code into the ESPHome node somehow. I read the docs and I don’t think it’s actually possible. I saw something I didn’t understand about ICMP pings, but, it’s over my head.

Can anyone assist with a code example? I’m assuming this will actually have to be a lambda or something. I dunno. I searched this forum but didn’t see something I thought would work.

See this issue on the matter (I’ve had the same idea myself):

Hi @postlund, thanks for that. It seems Otto is suggesting we use a status binary sensor, which is fair enough, but to get the state, we would still need to write C++ code to ping the desired IP address. I googled a little on this subject, and the code I found is wayyyyyyyyyyyyyy over my head.

Pity.

Yeah, it needs some effort to make it happen. I don’t have the time otherwise I would make an attempt.

I don’t have the skill, talent, or ability, otherwise I would also.