ESP32s Become unavailable, automation haywire

I wanted to run a stress test on some relays, hence I configured an ESP with six GPIO outputs:

  • platform: gpio
    pin: 16
    name: “T_1”
    id: “T_OP_1”
    restore_mode: RESTORE_DEFAULT_ON
    inverted: true

Pins used were: 16,17,18,19,21

Then, from the HA end, made a quick automation that was meant to switch on all relays together, keep them on for 10 seconds, turn them off. Then repat the cycle every minute.

alias: Test Toggle Automation
description: “”
trigger:

  • platform: time_pattern
    minutes: /1
  • platform: state
    entity_id:
    • switch.t_1
      from: “off”
      to: “on”
      for:
      hours: 0
      minutes: 0
      seconds: 10
      condition:
  • condition: state
    entity_id: input_boolean.test_helper
    state: “on”
    action:
  • service: switch.toggle
    data: {}
    target:
    device_id: 10e9a5f2f256cb56d89c4b74c136f294
    mode: single

Unfortunately, this has not been working for me at all. The ESP functions as intended for the first few iterations, then many things happen:
Either the device becomes unavailable and the entity log on HA says:

Turned off triggered by automation Test Toggle Automation triggered by time pattern

11:24:04 - 17 minutes ago

as a result, when it comes back on, some of the GPIOs fall out of sync, turning on when they should be turning off.
I checked the automation and it seems to be triggering just fine, trouble seems to be on the ESP end.
I have tried multiple ESPs, they all act up. Doesn’t seem to be specific to an individual ESP.

On the ESP end, here’s what it looks like when it randomly resets:

[11:51:00][D][switch:013]: ‘T_1’ Turning ON.
[11:51:00][D][switch:037]: ‘T_1’: Sending state ON
[11:51:05][I][mqtt:216]: MQTT Connected!
[11:51:05][I][app:062]: setup() finished successfully!
[11:51:05][I][app:102]: ESPHome version 2022.9.4 compiled on Oct 18 2022, 19:30:42

It turns on one or some of the GPIOs, then goes into the reboot loops, the beginnings of which is shown above.
The expected cycle looks like this:

[11:55:00][D][switch:013]: ‘T_1’ Turning ON.
[11:55:00][D][switch:037]: ‘T_1’: Sending state ON
[11:55:00][D][switch:013]: ‘T_2’ Turning ON.
[11:55:00][D][switch:037]: ‘T_2’: Sending state ON
[11:55:00][D][switch:013]: ‘T_3’ Turning ON.
[11:55:00][D][switch:037]: ‘T_3’: Sending state ON
[11:55:00][D][switch:013]: ‘T_4’ Turning ON.
[11:55:00][D][switch:037]: ‘T_4’: Sending state ON
[11:55:00][D][switch:013]: ‘T_5’ Turning ON.
[11:55:00][D][switch:037]: ‘T_5’: Sending state ON
[11:55:00][D][switch:013]: ‘T_6’ Turning ON.
[11:55:00][D][switch:037]: ‘T_6’: Sending state ON
[11:55:10][D][switch:017]: ‘T_1’ Turning OFF.
[11:55:10][D][switch:037]: ‘T_1’: Sending state OFF
[11:55:10][D][switch:017]: ‘T_2’ Turning OFF.
[11:55:10][D][switch:037]: ‘T_2’: Sending state OFF
[11:55:10][D][switch:017]: ‘T_3’ Turning OFF.
[11:55:10][D][switch:037]: ‘T_3’: Sending state OFF
[11:55:10][D][switch:017]: ‘T_4’ Turning OFF.
[11:55:10][D][switch:037]: ‘T_4’: Sending state OFF
[11:55:10][D][switch:017]: ‘T_5’ Turning OFF.
[11:55:10][D][switch:037]: ‘T_5’: Sending state OFF
[11:55:10][D][switch:017]: ‘T_6’ Turning OFF.
[11:55:10][D][switch:037]: ‘T_6’: Sending state OFF

I’ll work on getting the verbose logs next

This could be a power supply issue. Are the relay’s and ESP driven from the same power supply? If so, try using a higher wattage supply or, better yet, separate supplies.

Unfortunately, I do not think so. The hardware is running on a AC to 5V5A DC converter that’s very reliable further, it’s on a tested PCB. Definitely do not think that’s the issue. Other functionalities run just fine except for this particular automation.

Relay are very noisy devices. Turning 10 of them on at the same time causes veeery big noise spike. If esp is powered from same supply with relays it can be quite enough for esp to go wild, regardless if psu is high or low quality one, or if it’s powerfull enough…
If you can try this automation with power to relays disconnected. Then repeat with power to relays connected.

1 Like