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.
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.
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âŚ
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
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).
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.