Automation to restart Network

I am wondering f it is possible to write an automation to Restart my ETH port connection on my RPi4 which is running HA

I have this issue where for some reason the network drops ( see link below) and I get an Errno101
I don’t need to reboot the RPi to get connect back, just unplug and plug back in the Ethernet cable.

So I am thinking that if it was possible to restart the ETH port whenever I drop network then it would be at least a temporary (permanent :slight_smile: ) solution until I figure out what is going on and stop me from having to physical go tot eh RPi every time it happens…

Still new to HA so any ideas how to do this?

You can always create a script that do that.
But to start it you might need some rights.

For exemple, with Debian

shell_command:
  network_off: sudo /etc/init.d/network-manager stop
  network_on: sudo /etc/init.d/network-manager start

Then you can create a script:

alias: Restart Network
sequence:
  - service: shell_command.network_off
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: shell_command.network_on
    data: {}
mode: single

Now, you need your automation to start the script when a drop is detected.

As mentioned earlier, it’s uncertain whether you possess the capability to execute the commands specified in the shell_command segment. It depends on the way you installed HA.

I would strongly recommend you take a look at your wiring, the PI running HA and your network switches for why this is taking place rather than creating an automation like this to fix a symptom. They should not just stop working. If it does, there is a problem. In networking I have found if something isn’t quite right but you can work-around its annoying behavior, eventually, some day and when it is the worst day this could go wrong, it will break and become a big problem.