Rebooting the Raspberry Pi with the ESP01 and ESPHome relays

My Home Assistant on Rasberry Pi 3B+ is intermittently not working. I have backup power but the problem still persists. I want to arrange a Raspberry Pi Reboot using the ESP01 and ESPHome relays when the Home Assistant is not available. The relay must be connected to the power cable before the UPS.

Please tell me how to organize it programmatically. The first thing that comes to my mind is the reaction to the answer in the mqtt topic. is this the best way? If so, how to organize it?

On the Raspberry PI 4 there’s a pin on the board called GLOBAL_EN which restarts the PI when pulled to GND for more than 1ms. That would be easy for an ESP01.

However, you have a 3B+ and I don’t think that board has this GLOBAL_EN. MQTT is an option, can subscribe on a topic and let HA post something on it periodically. Alternative is maybe a ping message. On ESP you can reset the timeout on a message received but once it times out, you switch the relay on.

Something like this:

  # ...
    topic: raspberrypi/keep/alive
    qos: 0
      - script.stop: my_timer
      - script.execute: my_timer

  id: my_timer
    - delay: 30min  # max allowed timeout for pi to not respond
    - switch.turn_off: my_relay
    - delay: 10s    # delay after switch on relay again
    - switch.turn_on: my_relay
  - platform: ...
    id: my_relay
1 Like

The MQTT client component has a Disconnect trigger. That way don’t need to subscribe / send message when broker disconnects. But when the PI hangs, not sure if you’d receive this event.