ESPHome device frozen

I tried to build a simple system to periodically turn on and off a relay connected to a switch for heater.

It had worked for 2 or 3 hours without any problem.
3 hours later, it seems that the ESPhome device was frozen at a certain state.
LED indicating relay ON (blue led) was turned on, and the heater was also turned on during long time.
The ESPHome device lost the connection with HomeAsistant.

According to the log in HomeAssistant,

  1. 11:40:53 Switch turn on trigger by automation
    No turned-off on 11:43:53
  2. 11:45:23 Switch became unavailable
    no response anymore

I got an advice to use “interval component” instead of “delay”.
I could re-implement my code, but I’d like to know the reason why my system was frozen in current code.
I worried about that the ESPHome device was out of control.
It could loss the connections with HomeAssistant, but it should be connected again.
Moreover, “on_turn_on” in ESPHome device was jumped over.
Is there any possibility that my code caused this situation?

According to HA log, there were lot of “became unavailable” records.
But, in all cases except the above one, HA got the control of ESPHome again.

Automation code and ESPhome code

alias: SpaceHeating
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.heater
    from: "off"
    to: "on"
condition: []
action:
  - repeat:
      until:
        - condition: state
          entity_id: switch.heater
          state: "off"
      sequence:
        - if:
            - condition: state
              entity_id: switch.first_heater
              state: "on"
          then:
            - service: switch.turn_on
              data: {}
              target:
                entity_id: switch.first_floor_heater_switch
        - delay:
            hours: 0
            minutes: 30
            seconds: 0
            milliseconds: 0
mode: restart

ESPCode

switch:
  - platform: gpio
    id: relay
    pin:
      number: 0
      inverted: true
    name: "switch"
    on_turn_on:
      - delay: 180s
      - switch.turn_off: relay

If it is a large load like a heater you could be generating EMI when switching the load on and off. This can cause anything from loss of wifi connection to glitching the micro-controller.

2 Likes

Agreeing with Tom here, the ESP’s are sensitive to these issues so need protection included in the relay circuit. If you have the circuit-diagram for the relay and ESP, we might be able to work out whether the protection is present.

The heater is not an electric heater but a hot-water based heating system. Also, it is activated by a servo motor that opens and closes a water valve. Esp board controls the servo using relay.

The upper figure is before modification
The below one is after mod.
My intention was AND operation.
When the original temperture controller decides OPEN VALVE and the ESP also turns on switch, the water valve will be open.

You need a flyback diode in the circuit (D1) across the relay coil pins (RL1):

Also the AC servo should have suppression capacitors across the terminals (maybe it does already), but you should check this.

1 Like

Thank you for the comment!
I used this board with a relay from aliexpress.

I am not sure, but this board may include the diode for the relay.

By the way, one of esp board was frozen again for more than 1 hour. I checked its surface temperature and found out it is very hot. Something has been running on ESP.

It does include a flyback diode (D1 on the board).

Run the circuit with the heater disconnected, so the relay clicks but does not switch any power. See how stable that is.

2 Likes