Help with Script: Switch off Smart Plug if Ping Fails

Hello!

I am moving my first steps with HA.

I would love some help, or even to be pointed in the right direction with a script.

I have HA installed on a Raspberry PI 4; I want to build a series of script into the PI to help me do:

  1. Send me a notification when there is a power outage, the RPi4 is attached to a UPS
  2. Send me a notification when there is a fiber outage and the router switched to the failover LTE
  3. Reboot the router when it is stuck

The most important script needs to do this:

  • Ping Google for 5 times, every 2 minutes
  • If Ping fails, switch off a Tapo P100 Smart Plug
  • Wait 30 Seconds
  • Turn On the above plug

Can you please point me in the right direction, I am not asking for a full script (albeit I’d gladly accept it!)

Thank you

Hi , Does this help ?

I am planning to do the same so might be we can collaborate

1 Like

İf google fails, do you still need an internet connection to reach tapo switch? If tapo requires cloud access, you might switch to some other local solutions as zigbee or zwave

1 Like

I am testing ping now , just wait until HA restart .

If you are asking if your lan devices will be in a mess if the internet goes down then the answer
is yes and no based on your devices and setup . The clouds ones for sure will have problems if the outage is taking a long time .

I will try to test but It could be different in your case

1 Like

================================================
binary_sensor:

  • platform: ping
    host: 142.251.37.238
    name: “pingme”
    count: 2
    scan_interval: 30
    ==========================

now , what you want to do next ?

I SURE love to work together.
ANd defo share my outcomes with the forum.
I just need 2 or 3 days to setup everything and receive some extra HW I got from Amazon

This is very important, I will need some testing.
I dunno if TAPO would work despite an outage, but it does not matter, I can just buy another Smart Switch or use another one I have at home.

If ping fails, power cycle TAPO and send a pushbullet notification to my WhatsAPp

That is really easy , i will do test to power on a device on the lan based on the ping result . but I will test only LAN device , I can not disconnect the WAN now because there are a lot user and devices

What i am also interested in is actually to find if the connection is slow or not ( like a speed test below )
Because I do not expect WAN to face frequent issues ( If your WAN is facing lots of issues then that needs to be fixed on its own ) .

My WAN is still quite new, so I don’t have a lot of information about its reliability.

So far it has been excellent, steady 1 Gbps / 200 Mbps upload.

Another challenge for me it will be to understand when the router switches to the LTE connection

Nowadays with working from home and distant learning if your WAN disconnects for any reason then raise hell with your ISP . I have changed ISP because of one disconnection and now I cant recall when was the last time I faced WAN outage ( i faced power outage only )

Lecture finished :slight_smile:

Now for the issue at hand …

Try the speedtest integration above , it has ping and more . this is all we need to monitor the WAN performance and not only connectivity

If you need few days to setup things then lets talk then because we will customize it to your setup .

Thank you Aldiy.

There is a concern beyond the WAN outage, the entire house automation and security has 2 single points of failure that can be exploited by burglars or even worse:

  1. Fisically cutting the fiber cable, it runs unprotected on the side of the house
  2. Cutting the power.

The former weaknesses is remedied by the LTE failover of the router, it is a LBR20 with 4G sim
The latter is corrected by having all home smart hubs, the router, the RPi4 attached to a UPS APC with apcupsd running.