Remotely power cycle a device like a router, hub or network switch using WIFI power switch

If you have ever wanted to reboot a router or hub or network switch remotely here is a neat trick I’ve come up with.

PROBLEM:
If you put a wifi power switch on your network hub and turn it off, you don’t have a network connection to turn it back on again!

SOLUTION:
I’ve used a Tasmota ATHOM wifi Plug.
By default it just has one web button to turn the power on or off. I’ve added a virtual “reboot” button.

  1. Setup a second virtual “button” on the webview by assigning:
    GPIO14 Button 2
    GPIO15 Relay 2

  2. Name the buttons so you don’t get confused what they do. In the webconsole type:
    WebButton1 Power
    WebButton2 Reboot

  3. Set a rule to turn webbutton 1 off for 30 seconds, then back on to power cycle the device thats connected to this plug. In the console type:
    Rule1 ON power2#state=1 DO Backlog Power2 OFF; Power1 OFF; Delay 300; Power1 ON ENDON
    Rule1 1

Now when you press the reboot button (button2) in the web console, or tell home assistant to trigger button2 ON, it will toggle button2 back off, then turn the physical power to device on the outlet OFF for 30 seconds, then turn it back on again.

Added bonus, the Athom plug will track your power usage of that device.

Hope this helps people who have devices that need a powercycle that are in inconvenient places (in the basement, ceiling, shed etc) and or those devices might kill your network if they are off.

I know there are other ways to do this, but I wanted a simple “button” that did a reboot.

Please let me know if this helps , or you have a better solution.

3 Likes

Athom devices are also esphome flashable, so they all get the ability to do that - see

That’s rebooting the switch not the thing plugged into it though?

I have it set up for quite a while for a number of my devices: It’s pretty easy: create a switch in esphome and define action for: off; delay 1s; on. That’s it.
But, you say “if you don’t have network connection”…how you’ll trigger this switch if device is not accessible? If certain router or hub is not accessible nor is device, connected to this router/hub…

I have done this for a long time since every once in a while my router would not natively respond to a reboot request itself so the only alternative was to power cycle it. That handles a router that is still working but won’t reboot. For the case where the net is actually down (and so I can’t reach the Tasmota plug to ask for the reboot) I also have the Tasmota plug periodically ping a well known internet endpoint and if this fails for a few hours, it will reboot the router. This insures that my seasonal home gets back in the net if it’s modem and router crash. I wait a few hours to allow for a ISP outage that might be the cause of the issue.

2 Likes

Oh doing a ping Is a good idea, can you share the code you used to do that please?

Last time I checked you need to generate a version of Tasmota with the ping command enabled. Ping isn’t in the basic function set. There are some instructions on the Tasmota site for doing that. As I recalled I used gitlab to do that since I didn’t want to set up a compile environment on my own system for a one off thing. Once you have that version burned on your switch, you just need to use the timers to get an event every interval that you want to do a ping. The event will tell you if the ping succeeded and if so you reset a different timer that you have set to go off at the interval you want to do a reboot. So long as you get successful pings before the second timer goes off, it will always get reset. But if not, then you get that event which you use to trigger the reboot. I’ve pasted below what I use but you will probably need to alter for your uses.

rule1:
on power1#state=1 do backlog syslog 2; delay 50; power1 0; ruletimer8 86400; syslog 1; endon

rule3:
on system#boot do backlog syslog 2; ruletimer8 43200; ruletimer7 20; syslog 1 endon on rules#timer = 7 do backlog ruletimer7 1200; ping0 google.com endon on ping#google.com#Success==1 do backlog syslog 2; ruletimer8 43200; syslog 1 endon on rules#timer = 8 do backlog ruletimer8 7200; syslog 2;power1 1; endon

Logic: timer8 is  interval to not see internet before try (1 day); after power cycle try every 2 hours until success; do the ping every 20minutes

Awesome. Thanks I’ll be able to work it out from that :+1:

It’s amazing I just got some Athom plugs and giving Tasmota a spin for the first time in my life, and when I was thinking how can I reboot the router or the server without depending on connection to start them again, I found out a guy with the exact same case explaining what to do just a few days ago!! Thank you so much, this is the only topic on web clearly explaining some steps

Now, to the functional part:
I have Athom Tasmota V2 plugs, with firmware 12.3.1:

Just replicating your rule did not work for me, the reboot button needed 2 actions to actually do the cycle. Also in my case, the syntax was with 0&1 instead of OFF&ON - found the alternative syntax here: Automatically reboot router on lost Internet connection with Sonoff switch and Tasmota .
What I did in order to work as you described was to create 2 rules:

Rule1 ON power2#state=1 DO Backlog Power1 0; Power2 0; Delay 150; Power1 1; ENDON
Rule2 ON power2#state=0 DO Backlog Power2 0; ENDON

These rules show the reboot button as OFF by default, going briefly to ON when pressed, then going to OFF together with the Power one. The effect is a reboot at 15 seconds.

I used the GPIOs and naming convention from your example, so I assume you have v2 plugs also, because I noticed v1 plugs have other assignments on them.

PS: This is my first hour with Tasmota and I’m not very comfortable with it yet, sorry if I wrote something stupid.

Not sure if this has been suggested, but a ZigBee device is not dependent on the IP network.

1 Like

Not sure why you need that second rule? isn’t that basically saying if it’s off, turn it off?

Do keep in mind that when you send the commands to the plug, it does what you tell it nearly instantly, however i’ve found the web interface can be several seconds delayed in updating what the actual state of the plug is. ie. says it’s on when it’s off etc. That confused me a bit when I was testing it. So I plugged a lamp in it with a bulb and sat that on my desk.so I could “see” exactly when it was on or off, how long for, what state it went to on resume after power failure etc.

Another trick when hard rebooting your network /coms gear this way- If you want to trigger a reboot on a couple of devices at once, make the first command in the backlog rules a 60 second wait. That way you have time to tell several devices to “reset”, and you don’t have to worry about the first device rebooting and killing your network before the second device even got the message. :slight_smile:

Not sure either, your rule made sense also, but that is the only way I could get the plug to work after trying various logical paths in one rule :frowning: .
The plug clicks when changing state and it wasn’t the case of “it worked, but I didn’t notice in the web GUI”.

Hi Marty,

I was just looking for the solution you provided. I bought a Tasmota plug and start fiddling but I cant get it going.
I assigned the GPIO’s but I just get one web button. Nothing changes in the main menu and in HA is just get one switch and not 2.

I have no clue what I did wrong…

I have some doubt about the configuration settings. The tasmota menu is big question mark

I am be able to configure the module with two buttons but somehow it resets itself back to a basic Sonoff module ??

When I bought it I had power and energy readings but these are gone and don’t come back at a reset. No clue why?

EDIT
Problem solved. For some reason I can’t use button but I have to set switch1 and switch2 to avoid a reset after 40 secs. The rest of your description is flawless. Thanks

1 Like

From the first post in this thread - I am newbie user and have some brand new Athom V2 plugs (EU) with latest firmware (13.4.0)

This info may help other newbies

I added the buttons under ‘Templates’ in configuration. The number you can select in dropdown next to the GPIOs. I used the same one as arty.

When pasting into console, when I did the whole thing it didn’t work. I did it line by line, then after that, I pasted the whole thing in again (so in console it was all on one line) and after that it worked fine.

Thanks to @ArtyMarty for posting, it really helped me out!

1 Like

Thanks for the effort you’ve put into this, it looks really useful.

Could I please request some more information?

Specifically I’m interested in the logic for each use of variables, and which units they are all in.

I’ve read over everything a few times but I don’t feel that it’s sinking in properly.

Thank you so much.