Ping Sensor triggering automation problem

I have created a Ping sensor in configuration.yaml as follows:

# Ping to test internet connectivity
binary_sensor:
  - platform: ping
    host: 8.8.8.8
    name: "Internet connection"
    count: 1
    scan_interval: 30

I have an automation like this:

alias: System Report Internet Connection State Changed
description: ''
trigger:
  - platform: state
    entity_id:
      - binary_sensor.internet_connection
    from: 'off'
    to: 'on'
condition: []
action: ...

The problem I have is that the automation’s actions run every 30 seconds. This is despite the sensor’s history showing that it has been in the on state for some time.

What’s going on?

I don’t know. I’ve set up exactly the same binary_sensor and automation in my system (Docker container on a Synology NAS with action: [] and an id to enable traces, in case it matters), and I see the expected behaviour of the sensor updating the ping timing and the automation not running as the sensor is continuously on.

What happens if you change the automation to trigger from: 'on'? Does it still trigger? Logically, you’d think it should, if your system is seeing a transition.

Thanks @Troon . I changed the trigger to this:

platform: state
entity_id:
  - binary_sensor.internet_connection
from: 'on'
to: 'on'

I hope that’s what you meant.

Anyway, the action continues to be performed every 30 seconds. It’s weird.

The history looks like this:

That is very strange. My sensor has now been up for 90 mins and the automation hasn’t triggered once.

Assume you’re running a recent-ish version of HA? What system are you running it on?

Thanks @Troon . I’m running HA 2022.6 on HA OS x86 (Dell OptPlex 3040 micro PC).

Did you search automation details for any info? In automations, second icon on the right (looks like a clock with circular arrow). There are step details which can may help to answer why it’s trigerring…

Thanks @Protoncek . I’m not sure if any of this will help. I have:

Step details > Changed variables:

this:
  entity_id: automation.system_report_internet_connection_state_changed
  state: 'on'
  attributes:
    last_triggered: '2022-07-04T10:14:05.765541+00:00'
    mode: single
    current: 0
    id: '1656920814827'
    friendly_name: System Report Internet Connection State Changed
  last_changed: '2022-07-04T12:19:39.941572+00:00'
  last_updated: '2022-07-04T12:19:39.941572+00:00'
  context:
    id: 01G74JDTS4K0VS0F3JJZTX9Z7W
    parent_id: null
    user_id: e0f220080b9d4ac4ad12573fe4691d12
trigger:
  id: '0'
  idx: '0'
  platform: state
  entity_id: binary_sensor.internet_connection
  from_state:
    entity_id: binary_sensor.internet_connection
    state: 'on'
    attributes:
      round_trip_time_avg: 14.211
      round_trip_time_max: 14.211
      round_trip_time_mdev: ''
      round_trip_time_min: 14.211
      device_class: connectivity
      friendly_name: Internet connection
    last_changed: '2022-07-04T07:29:05.430721+00:00'
    last_updated: '2022-07-04T12:19:36.015434+00:00'
    context:
      id: 01G74JDPYFASAPHPTEGZ4MZNDG
      parent_id: null
      user_id: null
  to_state:
    entity_id: binary_sensor.internet_connection
    state: 'on'
    attributes:
      round_trip_time_avg: 15.165
      round_trip_time_max: 15.165
      round_trip_time_mdev: ''
      round_trip_time_min: 15.165
      device_class: connectivity
      friendly_name: Internet connection
    last_changed: '2022-07-04T07:29:05.430721+00:00'
    last_updated: '2022-07-04T12:20:06.016739+00:00'
    context:
      id: 01G74JEM800A30C12R8DY8AJ3G
      parent_id: null
      user_id: null
  for: null
  attribute: null
  description: state of binary_sensor.internet_connection

Step details > Related log book entries:

System Report Internet Connection State Changed triggered by state of Internet connection
13:20:06 -

It’s behaving as if the from: and to: are being ignored and it’s triggering on attribute updates: see the first paragraph of:

Can you paste your exact automation code please? If you’re using the UI editor, perhaps also include a screenshot.

Thanks @Troon .

Code:

alias: System Report Internet Connection State Changed
description: ''
trigger:
  - platform: state
    entity_id:
      - binary_sensor.internet_connection
    from: 'on'
    to: 'on'
condition: []
action:
  - service: tts.cloud_say
    data:
      entity_id: media_player.home_control_panel_media_player
      message: Internet connection is re-established
mode: single

UI:

2022-07-04 14_55_31-Settings – Home Assistant - Personal - Microsoft​ Edge


2022-07-04 14_56_42-Settings – Home Assistant - Personal - Microsoft​ Edge

First you must change “from: on” back to “from: off”. When do you want trigger to happen? When internet connection returns from off to on (when connection returns)?

Idealy I want two triggers: one for when the internet connection is lost and one for when it is reconnected. I’ll then use trigger ids and a Choose to take appropriate action.

I’ve changed the ‘from: on’ to ‘from: off’ and it’s triggering every 30 seconds.

Then i’m lost…
i created same sensor as you and same automation and my automation also doesn’t trigger at all, like Troon’s one…
Try to increase count (or remove line and set to default=5), since help manual says:

Number of packet used for each device (avoid false detection).

Have you tried it by just not setting the value for “to” and/or “from”?

Thanks to @Troon , @Protoncek and @paddy0174 for all you help.

I think it is working now. The problem was due to an error on my part. I had a piece of disfuntional yaml which got highlighted when I changed the ‘count’ from 1 to 4 and then checked the yaml. However, I’m not sure why this was having an effect because:

  • I always check my yanl before I restart HA;
  • changes to configuration.yaml only take effect with a restart;
  • I didn’t think HA would restart with disfunctional yaml; and
  • I don’t understand why this would cause the automation to keep triggering.

Anyway, thanks to everyone again!

1 Like