Is there really no ping sensor in ESPHome?

Really? This gives me a “platform not found” error.

binary_sensor:
  - platform: ping
    name: JackiesiPhone7
    host: 192.168.0.79
    count: 2
    scan_interval: 300
2 Likes

There really isn’t.

This request has been open for a year or two and there are instructions for implementing a custom component in the comments:

I am already using the esp8266ping.h library in my Arduino sketch. I am trying to move my ESP projects to ESPHome, but one, which is rather simple, uses ping to verify that my servers, router and external internet are online.

Custom components are above my pay grade. It took me two days to get blink to work.

You can use Status Binary Sensor — ESPHome for this and then f.i. use and automation or node-red to get an alert if the device is no longer connected!

No he can’t. The status sensor only reports on the ESP device itself. Not other specified IP addresses. Look at the first post. The ping was monitoring someone’s phone.

As Tom noted, I am looking to ping servers not on my net. It is not an ESP device.

The backstory:
My wife: “The network isn’t working”.
Me: Start pinging various servers on my network, the router and a random external server, like Google.com.
If all pings pass, then the problem may be in her computer or possibly an operator error.
Solution:
I built a device on the Wemos D1 Mini that pings the obvious culprits and for each given ping, turn an LED on “red” or “green”. If the status board is all green, then much of my troubleshooting is done already.

I wanted to move the code to ESPHome, mostly for the learning experience. Yes, I can ping from Home Assistant. But this means that my device is no longer stand-alone. If my router goes offline, the stand-alone device can set the router LED to red. But if I am depending on HA for the ping and the router is offline, then how will the device see this over the API?

I just find it strange that there is a ping platform on Home Assistant but not on ESPHome core.

1 Like

OK, so maybe a custom_component?

So, I am trying to follow the example given in Custom Sensor Component — ESPHome, but I am getting a couple of errors that I am not sure how to handle.

Compiling /data/wemos_test/.pioenvs/wemos_test/src/main.cpp.o
/config/esphome/wemos-test.yaml: In lambda function:
/config/esphome/wemos-test.yaml:30:28: error: expected type-specifier before 'MyCustomSensor'
   30 |     auto my_sensor = new MyCustomSensor();
      |                            ^~~~~~~~~~~~~~
/config/esphome/wemos-test.yaml:32:24: error: could not convert '{my_sensor}' from '<brace-enclosed initializer list>' to 'std::vector<esphome::sensor::Sensor*>'
   32 |     return {my_sensor};
      |                        ^
      |                        |
      |                        <brace-enclosed initializer list>
*** [/data/wemos_test/.pioenvs/wemos_test/src/main.cpp.o] Error 1

Here is my device yaml:

substitutions:
  device_name: wemos_test
  
esphome:
  name: ${device_name}
  platform: ESP8266
  board: d1_mini
  includes:
    - my_custom_component.h

  on_boot:
    then:
      - logger.log: "Hello World"


packages:
  wifi: !include common/wifi.yaml

logger:
  level: VERBOSE     # default is DEBUG

api:

ota:
  safe_mode: True

sensor:
- platform: custom
  lambda: |-
    auto my_sensor = new MyCustomSensor();
    App.register_component(my_sensor);
    return {my_sensor};

  sensors:
    name: "My Custom Sensor"

Lambdas are my current weakness (after finally getting a handle on automations).

Any tips would be appreciated.

Any reason you don’t want to use the “ready” custom component mentioned by @tom_l ?

It has a nice read me which should get you started very quickly :rocket:

Two.
First, in my Arduino sketch I am pinging four IP addresses, and one, the external IP, is selected at random from an array of 24 IP addresses. This is to prevent anyone from thinking that my pings could be an attack test. The “ready” custom component hard codes a single IP.
Second, I did try, but I can’t get past this error:
Integration error: external_components - Integration 'external_components' not found.

Here is the configuration.yaml code from the example:

external_components:
  - source:
      type: local
      path: ../components/esphome-component-ping/components

So, it looks like my version of Home Assistant doesn’t have an external_components integration?

@stevemann configuration.yaml is the Home Assistant configuration file. The ping custom component is for ESPHome, so it goes into the YAML of your ESP device.

I do use ping in the configuration.yaml file for presence detection, but I need it to run in the ESP device independent of whether HA or my broker are running.