Toggle Power remotely

Pretty new to Home Assistant and automation. I have HS300 Kasa Smart Wi-Fi Power Strip with one of the plugs connected to my internet modem\router\gateway. From outside of my home, I occasionally need to hard power cycle my gateway.

In HA, I see the plugs and the ability to click off but as soon as I do, I’m obviously going to be unable to click the “on” control after about 5 seconds.

Is there a device out there that might be better suited that would receive more of a “toggle” command over the network and then automatically do the off, delay, and then on from within the device?

Hi Nathan,

Perhaps if you set up an script that you could call that would turn it off, wait a minute, then turn it back on?

If you are looking for something that will do this by itself, I share a blueprint that does this. Perhaps you can use it if it fits you needs or use pieces of it to make your own magic. :magic_wand:

🧯 Device_tracker Monitor & Notifier.

1 Like

I recommend creating an automation and a helper that’s a toggle.
The trigger would be when the helper is on
The action will be turning the HS300 off, then a delay maybe 30 seconds or 1 minutes or whatever you may like, then turn the HS300 on, then set the helper to off.

That should do it.

2 Likes

But if the OFF command results in the network going down, the automation wouldn’t ever be able to send the ON command right?

I highly suggest you look at the firmware of your Internet router/modem/gateway and see if there is an update because you should not need to reboot your device often enough to need this.

If your power strip has local control of your HS300, you could do an automation that checks whenever that outlet goes to a status of off, power it back on, again. If you need to wait a few seconds, you can have it wait that long before powering back on that switch.

But, the real fix is why is your router/modem/gateway requiring a reboot that often.

1 Like

If you have a plug through Esphome you can code scripts and delays in the device firmware so local network wouldn’t be required. I use this for a bathroom fan where the smart plug handles the fan control locally. Sorry for the image but phone not letting me select text.

1 Like

I have my router connected through a Shelly plug S. I have it set to turn on the power automatically one minute after the power is turned off. So I have a button in Home assistant where I can turn off the power to the router. Then the power turns on automatically after a minute and the router boots up again.

1 Like

This looks like what I’m after. Sonoff S31 seems like it would be supported.

Mine’s a generic athom plug using esp8266.

1 Like

Unfortunately it’s due to the buried fiber flexing due to cold\hot\rain. It’s not cheap or annoying enough to fix nor do I have choices for 1G internet other than this provider. Only happens once every few months and I can usually just cycle it when I’m home. However, I will be in another house for the majority of this year and need a good way to reboot remotely.

Is this before or after your DMARC? If it is before, my suggestion would be to make them come out and fix it…keep going up the chain of support until they make a support call. You pay for their service and rebooting equipment is not something a customer should be required to do.

If it is beyond the DMARC, still better to fix the problem. Rebooting equipment always makes me worry because if there is a hardware failure, then you might be dead in the water until it is replaced.

1 Like

If I were planning to live here longer I would, but I’m planning to move. Not worth my energy at the moment but toggling a switch when it happens remotely or on a schedule is easy enough to do until then.

@Ellcon

Could you possibly post the full yaml contents with your sensitive info excluded? Just received my S31 device and have it flashed with the basic config and wanted to see the full context of your snippet - planning to look at the syntax and get familiar with ESPhome later today.

My code is split over several yaml files but this should hopefully give you enough to learn from. I am using an Athom plug which has power/energy monitoring and is overkill for controlling a fan. I have simpler Athom switches but they need to be hard wired in.

substitutions:
  device_name: "athom-plug4"
  entity_name: "athom_plug4"
  friendly_name: "Bathroom Fan"
  relay_restore_mode: ALWAYS_OFF
  update_interval: 10s
  fan_on_delay: "180s"
  fan_off_delay: "1080s"
#packages:
#  athom.smart-plug-v2: github://athom-tech/athom-configs/athom-smart-plug-v2.yaml

packages:
  wifi: !include base/wifi.yaml
  base_device: !include base/athomplugdev.yaml

wifi:
  manual_ip:
    static_ip: !secret ip_athomplug4

esphome:
  name: ${device_name}
  friendly_name: ${friendly_name}
  name_add_mac_suffix: False
  on_boot:
    then:
      - script.execute: bathroom_fan_control

esp8266:
  board: esp8285
  restore_from_flash: true
  early_pin_init: false

uart:
  rx_pin: RX
  baud_rate: 4800

binary_sensor:
  - platform: gpio
    pin:
      number: 5
      mode: INPUT_PULLUP
      inverted: true
    name: "Power Button"
    disabled_by_default: true
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - switch.toggle: relay

switch:
  - platform: gpio
    name: "Relay"
    pin: GPIO12
    id: relay
    restore_mode: ${relay_restore_mode}
    on_turn_on:
      then:
        - light.turn_on: blue_led
    on_turn_off:
      then:
        - light.turn_off: blue_led

light:
  - platform: status_led
    name: "Status LED"
    id: blue_led
    restore_mode: ${relay_restore_mode}
    disabled_by_default: true
    pin:
      inverted: true
      number: GPIO13

script:
  - id: bathroom_fan_control
    then: 
      - delay: ${fan_on_delay}
      - switch.turn_on: relay
      - delay: ${fan_off_delay}
      - switch.turn_off: relay
1 Like