Please help with restarting a camera using IKEA tradfri socket off/onn command

I am fairly new to HomeAssistant, so i obviously need some help, please bare with me.

I have 6 cameras connected to my Synology Surveillance Station and I am running HomeAssistant as a DSM service (not in a VM, not in a docker, plain and simple DSM service). They’re not the best, not the cheapest/worst either (the cameras).

My problem is that every once in a while, 2 of my cameras stop working (mainly after the main router reboots - usually i reboot it manually, or after a power cut, when the cameras reboot faster than the router itself).

To ease my life and spare myself from crawling to their power adapters, i added 2 IKEA Tradfri control outlets on these cameras, and i restart the power on these cameras when i detect that they no longer work. Manual on/off from IKEA app or from HAS works just fine.

Now, i would like to take it to the next level: when the NAS Surveillance Station looses contact with the RTSP stream, i would like to know if it is possible to trigger the power outlet off/on automatically if the connection is lost for more than 1-3 minutes, of course, allowing the camera to restart (about 60-90 sec).

If it is possible, may i get a bit of guidance how to do this?

Environment:
DSM : 7.1-42661 update 4 (currently latest available for my DS1621+ NAS)
HA package: Home Assistant Core Version 2021.9.7.15

Thanks in advance
Gabriel

I think I found a way, initial tests look OKay-ish:

Step1: In HA, define a web hook: Settings → Automation → Create automation → Start with empty automation

alias: WebHook-1-PrizaBalcon
description: ""
trigger:
  - platform: webhook
    webhook_id: "<removed>"
condition: []
action:
  - type: turn_off
    device_id: 6d8dcb05861f6d7e534f7d2bb228a03f
    entity_id: switch.o6_cam_balcon
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - type: turn_on
    device_id: 6d8dcb05861f6d7e534f7d2bb228a03f
    entity_id: switch.o6_cam_balcon
    domain: switch
mode: single

Step 2: on Synology Surveillance Station, “Action Rule” application, define an action rule:

  • Give it a name
  • Type: Triggered
  • Action Type: Interruptible
    then, on the Event definition, setup:
  • Interval (seconds): 10
  • Event source: Camera
  • Device: select the device you want to monitor (in my case “Balcony”)
  • Event: Connection lost
  • Trigger type: Constant
    Then, on next screen, the magic is defined:
  • Action device: Webhook
  • URL: http://<HA_IP>:8123/api/webhook/<HOOK_ID_DEFINED_in_step_1>
  • username & password: leave empty
  • Method: POST
  • Content type: application/json
  • Body: {"info":"CAM Balcony - not working"}
  • Times: 1
    On next screen, define when the action rule is to be ON, i left it to 24/7.

Initial testing shows that the web-hook does trigger power outlet power-off , 5 sec delay & power-on for that specific camera…

I hope this helps others looking for similar functionalities…