Automating Smart Plug Control on Ping Failure with Home Assistant

I’m new to this fantastic system called Home Assistant, and I have a question about automating the process of turning off and on a smart plug when a camera fails to respond to a ping. I have several SmartLife smart plugs, and Home Assistant is installed as my server. I’d like Home Assistant to be able to turn off the corresponding smart plug when my camera doesn’t respond to a ping and then turn it back on after a 30-second delay. Is this possible? If so, could you provide some guidance on how to set up this automation?

I want to express my gratitude in advance to all the readers and the creators of this fantastic Home Assistant system. Your community is amazing, and I’m excited to learn from you!

First you create a binary sensor :

  - platform: ping
    name: mycamera
    host: 10.0.0.190
    count: 2
    scan_interval: 30

Then you create an automation

- id: '1564816850591'
  alias: restart camera
  trigger:
  - entity_id: binary_sensor.mycamera
    platform: state
    to: 'off'
  action:
  - data:
      entity_id: switch.myswitch
    service: switch.turn_off
  - delay: 00:00:30
  - data:
      entity_id: switch.myswitch
    service: switch.turn_on