Remote WiFi power switch for Raspberry Pi using ESPHome and Home Assistant

I wanted a way to switch power off and on to a remote headless Raspberry Pi in case it becomes unreponsive. Inspired by an Arduino project on Github, I created this: GitHub - ronschaeffer/pi_power_esphome_ha: Remote WiFi power switch for Raspberry Pi using ESPHome for Home Assistant Button

Use an ESP8266 board with ESPHome (D1 mini by default) to remotely power on and off your Raspberry Pi from any device connected to your wireless network and/or from your Home Assistant dashboard.

This method works with either USB or PoE power to the Pi. I have only tested it with the official PoE+ hat.

This is an ESPHome configuration file for the ESP8226 that:

  1. Creates a button on a webpage at a local IP to switch the power on the Pi. Note that the swtich only initates power on or power off. It doesn’t actually know whether the Pi is on or off.
  2. If you are using ESPHome together with Home Assistant, also creates a button in Home Assistant to switch the Pi on or off. Note that Home Assistant only initates power on or power off. It doesn’t actually know whether the Pi is on or off.
  3. Enables the ESP’s built-in led as a power indictation.