Binary sensor works with only one name

I have defined a ping binary sensor as below:

binary_sensor:
  - platform: ping
   host: 8.8.8.8
   count: 2
   scan_interval: 30
   name: Internet_Connection 

I get the result


However, if I change the name to anything other than “Internet_Connection” it doesn’t work. Very strange don’t know why.
Initially I was trying to create two sensors and I thought there was an issue in my code

binary_sensor:
  - platform: ping
    name: Internet_Connection1
    host: 8.8.8.4
    count: 2
    scan_interval: 300
  - platform: ping
    name: Internet_Connection2
    host: 8.8.8.4
    count: 2
    scan_interval: 300


But even if I tried this one

binary_sensor:
  - platform: ping
    name: Internet_Connection1
    host: 8.8.8.4
    count: 2
    scan_interval: 300

still no results.
Any ideas ?

The only thing I see here that is different to my own set up, and to the set up in the documentation example, is that the name is surrounded by double quotes and does not contain any underscores.

I tried this one too

binary_sensor:
  - platform: ping
    name: "internet connection check"
    host: 8.8.8.4
    count: 2
    scan_interval: 300

Still same result

Anything in the log files?

I think I have figured out what was happening.
After changing the .YAML file where the sensor was defined. I went into Development tools and click Ping binary sensor and that is why it worked in certain occasions. Most of the times when I was updating the name I restarted HA when the scan interval was 300 sec so even after starting it does’t scan for 5 mins. While at times I was setting scan internal to 30 sec and only restarted the configuration file.

binary_sensor:
  - platform: ping
    name: ping_google1
    host: 8.8.8.8
    count: 2
    scan_interval: 300
  - platform: ping
    name: ping_google2
    host: 8.8.4.4
    count: 2
    scan_interval: 300

Other than that its a new day that may have fixed the issue :slight_smile:

Yeah, it’d be nice if the ping sensor ran at startup. As you describe they run at the interval defined after startup.

You can force this by creating an automation that trigger off of home assistant start and refreshes the entity.

- id: "ping my device"
  alias: ping my device
  description: "Automation to periodically poll"
  trigger:
    - platform: homeassistant
      event: start
  action:
    - service: homeassistant.update_entity
      data: {}
      target:
        entity_id: “sensor.ping_generator”

1 Like