No PING component?

I just brought a ESP32 WT-ETH01 and planned on a project that requires monitoring hosts using the PING function.

I have read that there does not seem to be a PING component for esphome.

What are my options here? I want to ping about 20 hosts, at various times with just 1 or 2 packets, when packets are lost or the host is offline, then I want to trigger a GPIO output on the ESP32.

Any ideas how I can achieve this?

I am looking at this custom integration, but the ESP will not have access to Homeassistant or even internet or anything.

Question is, once flashing it with the local resource, does it need to be able to access the resource to work or is that resource compiled and uploaded to the esp when flashed?

Thanks

Hi

Why do you want to do that in an ESP while you can do it straight from HA ?

Vincèn

Sorry I should have mentioned, it will be completely isolated from Homeassistant and also the internet.

Do you mean ?

It is unrelated to HA

oki so it won’t be connected with HA ? What’s the interest then ? :confused:

Thanks,

Yes, I’ve flashed it with that custom_component, I will see if it will operate stand alone and then I guess that solves my problem.

I just need to figure out when there is packet loss, how can I trigger a GPIO?

Can be on ANY packet loss.

This is the esphome forum after all, esphome doesn’t have to be used with HA.

There is an example in the docs on the component @koying pointed to.

Sorry Nick,

I don’t see any documentation referencing how I could trigger an output based on the ping state.

That’s basic ESPhome.

Read the basic doc, and the myriad sample code all around this very forum, and come back with specific questions if you are lost at some point

Ah ok I wondered if they would work with the custom_integration or if I had to use specific commands for that integration.

I’ll have a play tonight and see how I get on.

Please read again

If you want to take actions on sensor values, see config/influxdb.yaml. In the example, on_value runs an automation (sending the value to influxdb whenever a value is available). Use on_value_range (the documentation) when the sensor value is above, below, or both

Thanks Nick! Sorry I missed that, did not expect it to be in the influxdb.yaml.

Right now, for the life of me I cannot even get a basic switch function to activate the GPIO ouput.

esphome:
  name: eth
  friendly_name: eth
  platform: ESP32
  board: esp-wrover-kit
#external_components:
#  - source:
#      type: local
#      path: /config/esphome/custom_components #Thanks for @ssieb components.


# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: 

ota:
  - platform: esphome
    password:

ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO0_IN
  phy_addr: 1
  power_pin: GPIO16
    
switch:
  - platform: gpio
    name: "Generic Output"
    pin: GPIO4
    id: genericoutput
    inverted: True
    restore_mode: ALWAYS_OFF

#sensor:
#  - platform: ping
#    ip_address: 172.16.102.1
#    num_attempts: 17
#    timeout: 1sec
#    loss:
#      name: Packet loss
#      on_value:
#        then:
#          switch.turn_on:
#            id: genericoutput
#    latency:
#      name: Latency
#      accuracy_decimals: 3
#    update_interval: 60s

Ok i’ve made some good progress,

I now have the relay activating on packet loss, I however now need to restore on ping or packet restore.

switch:
  - platform: gpio
    name: "Generic Output"
    pin: GPIO12
    id: genericoutput
    inverted: True
    restore_mode: ALWAYS_OFF

sensor:
  - platform: ping
    ip_address: HOST_IP
    num_attempts: 17
    timeout: 1sec
    loss:
      name: Packet loss
      on_value:
        then:
          switch.turn_on:
            id: genericoutput
    latency:
      name: Latency
      accuracy_decimals: 3
    update_interval: 60s

Ok I have got this working with the switch.toggle command.

The only issue I see with this is, with multiple ping sensors this is going to go out of sync. For example,

If HOST_1 goes offline and the relay is off, it will turn it on,
Then, if HOST_2 goes offline too, it will turn the relay off again.

sensor:
  - platform: ping
    ip_address: 172.16.102.1
    num_attempts: 17
    timeout: 1sec
    loss:
      name: Packet loss
      on_value:
        then:
          switch.toggle:
            id: alarmoutput

Use one automation to turn the relay on and another to turn it off.

I dont think this is going to work.

I am using,

  - platform: ping
    ip_address: 172.16.102.11
    num_attempts: 1
    timeout: 1sec
    loss:
      name: Packet loss
      on_value_range:
      - below: 30
        then:
          - switch.turn_off: genericoutput
      - above: 30
        then:
          - switch.turn_on: genericoutput

The problem is, the value is based on the percentage of packet loss.

Therefor, is changes with the amount of ping sensors. Also, when one sensor detects packet loss it goes to 100% but then when another sensor sends a command of 0& packet loss it changes to 0%

So, when one sensor is offline, it turn the relay does not even switch on (there is quite a delay) before the next relay reports 0% packet loss, as then turns the relay back off.

I honestly dont know where to go from here.

I almost feel like I might be better off with a simple arduino sketch.

I honestly don’t know why you need to ping more than one host. Perhaps you need to restate your problem.

If I understand correctly, you want to ping 20 hosts and if all are OK the relay will be turned off, but if 1 or more hosts are offline you want the relay to turn on.

If that’s the case, instead of automating each sensor, wouldn’t it be better to use an “interval” to check if any of the sensors have packet loss > 0 and then turn on the relay?