Reboot automation if no connection

Hello everyone, I would like to create an automation that checks the status of the internet connection every hour and if this is absent, restart the home assistant.
I created a new binary sensor:

binary_sensor:
 - platform: ping
   host: 8.8.8.8
   count: 2
   scan_interval: 1800
   name: state_connection

And its automation:

alias: Restart connection
description: ''
trigger:
  - platform: time_pattern
    hours: '1'
condition:
  - condition: state
    entity_id: binary_sensor.state_connection
    state: 'off'
action:
  - service: homeassistant.restart
    data: {}
mode: single

If I debug the automation, I get the message “No traces found” and I can’t understand if the automation would work or not.
Also, in the sensor settings I get this message “This entity (" binary_sensor.connection_state ") does not have a unique ID, therefore its settings cannot be managed from the user interface. See documentation for more details.”

The sensor works perfectly. How could I fix these errors?

  1. If you don’t have an internet connection, it’s unlikely that restarting HA will fix the issue, unlike it’s something very specific to your setup
  2. You won’t get automation traces because I don’t think those survive an HA restart
  3. Trigger directly on the binary_sensor state, no need for a time pattern, here. If you want to wait a while for the connection to come back by itself, use for: on the trigger