esphome-component-ping
esphome-component-ping copied to clipboard
loss sensor doesn't report value
I've configured my ping sensor like this:
sensor:
- platform: ping
ip_address: 8.8.8.8
num_attempts: 15
timeout: 60sec
loss:
name: Packet Loss
id: loss
on_value:
then:
- switch.turn_off: relay
- delay: 15s
- switch.turn_on: relay
update_interval: 30s
However, its state only shows up as "NA" in the esphome webui, or "Unknown" in Home Assistant. I've tested with it being able to reach 8.8.8.8 and also having a firewall rule that drops ICMP from its IP address, and the logs reflect that (ping success and failure), but the sensor value doesn't change at all. Am I missing something?
please provide logs.
The only logs I get from it is this (repeated every minute) when ping is blocked:
19:20:24 | [I] | [ping:040] | no reply from 8.8.8.8
...and this when it's not blocked (every minute):
21:06:24 | [I] | [ping:035] | 64 bytes from 8.8.8.8: icmp_seq=4 ttl=58 time=19 ms
Here's my full esphome config:
esphome:
name: router-rebooter
libraries:
- ESP8266WiFi
- https://github.com/akaJes/AsyncPing#95ac7e4
esp8266:
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
api:
web_server:
local: true
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Router-Rebooter Fallback Hotspot"
captive_portal:
external_components:
- source:
type: git
url: https://github.com/trombik/esphome-component-ping
ref: main
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode:
input: true
pullup: true
inverted: true
name: "Sonoff Basic Button"
on_press:
- switch.toggle: relay
switch:
- platform: gpio
name: "Sonoff Basic Relay"
pin: GPIO12
id: relay
restore_mode: ALWAYS_ON
status_led:
pin:
number: GPIO13
inverted: yes
sensor:
- platform: ping
ip_address: 8.8.8.8
num_attempts: 15
timeout: 60sec
loss:
name: Packet Loss
id: loss
on_value:
then:
- switch.turn_off: relay
- delay: 15s
- switch.turn_on: relay
update_interval: 30s
there should be logs like below:
[I][ping_esp32:089]: 17 packets transmitted, 15 received, 11% packet loss, total time 3028ms avg time 68ms
[D][sensor:117]: 'Packet loss': Sending state 11.00000 % with 0 decimals of accuracy
[D][sensor:117]: 'Latency': Sending state 0.06800 s with 3 decimals of accuracy
please enable debug log, and paste "all" the logs.
Here are my logs with the "logger: debug" option set in the config:
INFO Reading configuration /config/router-rebooter.yaml...
INFO Updating https://github.com/trombik/esphome-component-ping@main
INFO Starting log output from router-rebooter.local using esphome API
INFO Successfully connected to router-rebooter.local
[21:58:27][I][app:102]: ESPHome version 2023.1.0-dev compiled on Jan 21 2023, 19:37:28
[21:58:27][C][status_led:019]: Status LED:
[21:58:27][C][status_led:020]: Pin: GPIO13
[21:58:27][C][wifi:504]: WiFi:
The only debug logs I see are when I turn the relay on/off:
22:10:46 | [D] | [switch:017] | 'Sonoff Basic Relay' Turning OFF. 22:10:46 | [D] | [switch:056] | 'Sonoff Basic Relay': Sending state OFF 22:10:47 | [D] | [switch:013] | 'Sonoff Basic Relay' Turning ON. 22:10:47 | [D] | [switch:056] | 'Sonoff Basic Relay': Sending state ON
I've tried on both the "latest" and "dev" esphome versions, but still not seeing debug logs like your example there. Not sure if there's a debug setting I don't know about or an issue with esphome or something.
I can't find any logs fro "sensor" component. Try one of the examples, and make sure that the log includes messages from "sensor" component. After that, modify the config to your needs.