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âŚ
NathanCu
(Nathan Curtis)
November 14, 2023, 2:05pm
2
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
NathanCu
(Nathan Curtis)
November 14, 2023, 2:26pm
4
Ok⌠Good start.
Pull up the binary sensor in dev tools. Lets see what it lists. (was the name correct or at least close? )
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
NathanCu
(Nathan Curtis)
November 14, 2023, 3:04pm
6
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.
WallyR
(Wally)
November 14, 2023, 3:14pm
7
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
NathanCu
(Nathan Curtis)
November 14, 2023, 4:40pm
12
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?
Simone77
(Simone)
November 14, 2023, 6:09pm
13
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 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.
NathanCu
(Nathan Curtis)
November 15, 2023, 11:39am
16
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