ESPHome flashed plug. Shuts off at 3am

I have flashed a few devices to ESPhome using tuya-convert. One is a Kogan Smart Plug, the other is an Arlec Powerboard.

I have tested them both with my Modem plugged in, so I can switch the modem on and off if the internet fails. At 3.03am most nights, the plugs reset themselves, losing power to the modem. The power comes back on, so it’s fine, but I get a lot of alerts from my Unifi kit about the internet going down.

Has anyone else experienced this? Is there a way to keep the device on constantly if it does some sort of self check?

Thanks

And are you going to show us your yaml config file?

And no they do not switch off once every 24 hours unless you tell them to.

This is the code from one of the kogan plugs.

They’re not technically switching off, just off and on very quickly causing the modem to lose power and come back on.

substitutions:
  plug_name: kogan_plug_1
  # Higher value gives lower watt readout
  current_res: "0.00087"
  # Lower value gives lower voltage readout
  voltage_div: "2030"
esphome:
  name: ${plug_name}
  platform: ESP8266
  board: esp8285
wifi:
  ssid: 'xx'
  password: 'xx'
# Enable logging
logger:
# Enable Web server
web_server:
  port: 80
# Enable Home Assistant API
api:
  password: 'xx'
ota:
  password: 'xx'
time:
  - platform: homeassistant
    id: homeassistant_time
    
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "${plug_name}_button"
    on_press:
      switch.toggle: relay


switch:
  - platform: gpio
    name: "${plug_name}_Relay"
    pin: GPIO14
    restore_mode: ALWAYS_ON
    id: relay
  - platform: gpio
    name: "${plug_name}_LED_Green"
    pin: GPIO13
    inverted: True
    restore_mode: ALWAYS_OFF

sensor:
  - platform: hlw8012
    sel_pin:
      number: GPIO12
      inverted: True
    cf_pin: GPIO04
    cf1_pin: GPIO05
    current_resistor: ${current_res}
    voltage_divider: ${voltage_div}
    current:
      name: "${plug_name}_Amperage"
      unit_of_measurement: A
    voltage:
      name: "${plug_name}_Voltage"
      unit_of_measurement: V
    power:
      name: "${plug_name}_Wattage"
      unit_of_measurement: W
      id: "${plug_name}_Wattage"
    change_mode_every: 8
    update_interval: 10s
  - platform: total_daily_energy
    name: "${plug_name}_Total Daily Energy"
    power_id: "${plug_name}_Wattage"
    filters:
        # Multiplication factor from W to kW is 0.001
        - multiply: 0.001
    unit_of_measurement: kWh
      
# Extra sensor to keep track of plug uptime
  - platform: uptime
    name: ${plug_name}_Uptime Sensor
# Extra sensor for wifi signal
  - platform: wifi_signal
    name: ${plug_name}_WiFi Signal Sensor

Unplug the modem from the smart plug and monitor the wifi overnight.

A possible scenario:

  • Wifi drops out for whatever reason (scheduled restart/reboot?).
  • Smart plug attempts wifi reconnection, fails, and reboots***
  • This causes the modem to loose power momentarily and restart, restoring wifi.

***

ESPHome reboots on purpose when something is not going right, e.g. wifi connetion cannot be made or api connetion is lost or mqtt connection is lost. So if you are facing this problem you’ll need to explicitely set the reboot_timeout option to 0s on the components being used.

I’ve done some testing. Seems to be the Wifi drops as you say, which reboots the switch. I’ve used the reboot_timeout option for now. Is there a way to make sure that socket comes back on after a reboot? Seems to not reboot to same state.

Looking into why the Unifi drops. I think it may be plex libraries updating, but need some more digging.

Yes use the switch option restore_mode: