Ping internet - cant wrap my head around it

I am brand new to HA, so very much learning the logic.
I have installed the HA OS on a Raspberry Pi 4.

I have spent some time trying to understand this thread . Ping 8.8.8.8 connectivity check - #8 by tom_l

I can kind of gather than I need to template a binary sensor AND template a sensor:

So this is what I have created so far:
Binary template:

binary_sensor:
  - platform: ping
    host: 8.8.8.8
    name: "Google DNS Ping"
    count: 1
    scan_interval: 5

sensor:

template:
  - sensor:
      - name: "Ping"
        icon: "mdi:speedometer"
        unit_of_measurement: "ms"
        state: "{{ state_attr('binary_sensor.ping', 'round_trip_time_avg')|round(2) }}"

But I cant get it to work…

I guess there is a link in the naming I am missing here…

In the second sensor you are building you reference

binary_sensor.ping

Im assuming you wanted to refer to whatever sensor was built out of the first sensor?

If that’s the case the first sensor will have a name that’s built from:

name: "Google DNS Ping"

That is slugified (lowercase, trimmed and replace all spaces with underscore) to

google_dns_ping

And used to build the entity id:

binary_sensor.google_dns_ping

Which I suspect is what you need to ACTUALLY refer to instead on your last line.

Go look for the sensor in your entities list to get the actual name and replace sensor.ping with what it really is.

Thanks - I have updated the code. I suspected that there was a wrong link, but was not sure what to go for.

I still get an error that the Entity is unavailable.

Also the binary sensor shows status as always “Off”…which seems a little odd, but again I am new to this

1 Like

Ok… Good start.

Pull up the binary sensor in dev tools. Lets see what it lists. (was the name correct or at least close? :slight_smile: )

Can you ping 8.8.8.8 from a work station on your local network?

This is the entity name :

binary_sensor.google_dns_ping

Current state is off
There is only one line in the attributes :

friendly_name: Google DNS Ping

Is that not odd, considering the documentation Ping (ICMP) - Home Assistant ?

And yes I can ping 8.8.8.8 :slight_smile:

It’s what I expect if the ping failed. It can’t populate the other fields because on fail there won’t be data. Kind of like trying divide by zero or something.

Does the log say anything about ping? If no… Can you throw the ping integration intk debug mode logging and restart?

If the sensor exists it is defined properly. We just need to figure out why it’s not pinging.

Count set to 1 might be an issue.
Some networks will fail on the first ping, because the NAT’ing is slow to set up the port.

1 Like

The log just shifts between ‘unavailable’ and ‘off’.
Does the ‘unavailable’ represent its trying to ping?

Tried to change it to 5 and 30 seconds interval

Should I run some kind of refresh of the config as I am updating?

1 Like

I have now also changed it to ping my router gateway, which its incidentally connected directly to… still no bueno.

I did see the state of the binary sensor change from ‘off’ to ‘unknown’
Does that make sense?

1 Like

It does.

Unavailable means for some reason the sensor itself is broken or unavailable (if the code was invalid)
Unknown is I don’t have data yet. (probably initialized but hasn’t recorded a valid response)
Off - false: ping failed
On - true: ping worked. Will also generate attributes.

So I’m thinking unknown - it recycled properly (reboot etc. - btw you’re new, as a reminder you must restart HA for your changes to take effect we’ll discuss nuances later when you can skip it) and you checked before it had attempted to ping.

When off it had pinged and didnt get a response.

Yeah I really want to see this debug log now. Do you know how to set that up?

Can you try removing the count in the binary sensor?

And what for do you also need the second sensor?

My binary sensor Is same as yours with the onlu differences that I dont have the " " in the name and no count.

Keep in mind to reboot after the changes.

I am sorry, but I dont :frowning: I know its purpose, but the right way to do it in this scenario, I am not familiar with…do you have a guide/link I can follow? I would certainly like to see the steps the code tries to take…

1 Like

I tried re-doing the entire setup and rebooting as well.

The binary sensor “show” return attributes, like response times.
Thats what the other sensor is for - it will pick up the response times etc.

Certainly.

I belive the component you’ll need to setup is:
homeassistant.components.ping

(it’ll make sense when you read the article)

Sorry, for taking a long to respond. I will give the logger a try.

I did try the ping command from console and there is no issue there…so ping in itself is not blocked