Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loss sensor doesn't report value #32

Open
Red5d opened this issue Jan 16, 2023 · 5 comments
Open

loss sensor doesn't report value #32

Red5d opened this issue Jan 16, 2023 · 5 comments

Comments

@Red5d
Copy link

Red5d commented Jan 16, 2023

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?

@trombik
Copy link
Owner

trombik commented Jan 17, 2023

please provide logs.

@Red5d
Copy link
Author

Red5d commented Jan 18, 2023

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

@trombik
Copy link
Owner

trombik commented Jan 21, 2023

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.

@Red5d
Copy link
Author

Red5d commented Jan 23, 2023

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:

[21:58:28][C][logger:293]: Logger:
[21:58:28][C][logger:294]: Level: DEBUG
[21:58:28][C][logger:295]: Log Baud Rate: 115200
[21:58:28][C][logger:296]: Hardware UART: UART0
[21:58:28][C][switch.gpio:076]: GPIO Switch 'Sonoff Basic Relay'
[21:58:28][C][switch.gpio:098]: Restore Mode: always ON
[21:58:28][C][switch.gpio:031]: Pin: GPIO12
[21:58:28][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Sonoff Basic Button'
[21:58:28][C][gpio.binary_sensor:016]: Pin: GPIO0
[21:58:28][C][captive_portal:088]: Captive Portal:
[21:58:28][C][web_server:151]: Web Server:
[21:58:28][C][web_server:152]: Address: router-rebooter.local:80
[21:58:28][C][mdns:106]: mDNS:
[21:58:28][C][mdns:107]: Hostname: router-rebooter
[21:58:28][C][ota:093]: Over-The-Air Updates:
[21:58:28][C][ota:094]: Address: router-rebooter.local:8266
[21:58:28][C][api:138]: API Server:
[21:58:28][C][api:139]: Address: router-rebooter.local:6053
[21:58:28][C][api:143]: Using noise encryption: NO
[21:59:32][I][ping:040]: no reply from 8.8.8.8
[22:00:32][I][ping:040]: no reply from 8.8.8.8
[22:01:32][I][ping:040]: no reply from 8.8.8.8
[22:02:32][I][ping:040]: no reply from 8.8.8.8
[22:03:32][I][ping:040]: no reply from 8.8.8.8
[22:04:32][I][ping:040]: no reply from 8.8.8.8
[22:05:32][I][ping:040]: no reply from 8.8.8.8
[22:05:32][I][ping:035]: 64 bytes from 8.8.8.8: icmp_seq=8 ttl=57 time=19 ms
[22:06:32][I][ping:035]: 64 bytes from 8.8.8.8: icmp_seq=9 ttl=57 time=18 ms
[22:08:32][I][ping:040]: no reply from 8.8.8.8
[22:09:32][I][ping:040]: no reply from 8.8.8.8

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.

@trombik
Copy link
Owner

trombik commented Jan 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants