ESP watchdog in Home Assistant?

Is there a watchdog function for esp32 in Home Assistant?

Which is going to watch which?
You could have typed more than one sentence to describe you question

1 Like

You can set a sensor filter: heartbeat in an esphome sensor and create a template binary_sensor with a trigger, an ā€˜onā€™ state and auto_off. This is a template example

- trigger:
    platform: state
    entity_id: sensor.the_esp32_sensor_name
  binary_sensor:
    - name: the_esp32_sensor_name_heartbeat
      device_class: running
      auto_off: 30
      state: on

The auto_off is 30 seconds, so the heartbeat must be shorter.
When the esp stops sending the heartbeat, the binary_sensor goes to off.

Looking for an ESP watchdog that restarts ESP when, for example, it can not connect to WiFi

It already does. That is standard behaviour.
Not sure how long it keeps trying but it varies with time. So it starts with every two seconds then it drops down to every 10, then every minute or something.

WiFi Component ā€” ESPHome

  • reboot_timeout (Optional, Time): The amount of time to wait before rebooting when no WiFi connection exists. Can be disabled by setting this to 0s, but note that the low level IP stack currently seems to have issues with WiFi where a full reboot is required to get the interface back working. Defaults to 15min.
1 Like

There are tecnically two timeouts. A 15min for no wifi and 15min if it canā€™t conect to the HA API too.
So will also reboot if HA is down for more than 15mins but still has WiFi connected

Ok, thats an ESPHome function. Iā€™m not sure but i think the esphome node tries to reconnect on losing the wifi connection. (is answered above)

Btw a simpeler way of check if a ESPhome node is available is checking/triggering on availability of the node. Iā€™m using it to check on mqtt messages receiving but thatā€™s not your case.

I just use the ESPHome status binary sensor and an automation to alert me if any drop off line.

1 Like

Could you, please, increase the information? Thank you.

If you add the yaml code I provided in the file ā€˜template.yamlā€™, then there should be a binary_sensor available with the name ā€˜the_esp32_sensor_name_heartbeatā€™.
The auto off value should be higher then the update frequence of the ā€˜sensor.the_esp32_sensor_nameā€™.
So if the sensor is updated every 20 seconds, i would use 30 (secs) for the auto_off value.
When the sensor keeps on updating every 25 secs the binary_sensor will never go to the off state.
You can use the binary_sensor for triggering an automation.

You can also use the suggestion of @tom_l ( the ESPHome Status Binary Sensor)

1 Like

An example using that binary sensor:

- id: 4e9af4e4-4675-4b47-813a-3c880127d022
  alias: 'GPIO Bridge Disconnection Alert'
  trigger:
    entity_id: binary_sensor.gpio_bridge_status
    platform: state
    from: 'on'
    to: 'off'
    for: 5
  action:
  - service: notify.telegram_system
    data:
      title: 'āš ļø <b>Bridge disconnected</b>'
      message: "ESP GPIO Bridge has disconnected. Alarm sensors depend on this."
2 Likes

Thank you very much for your answer.
Iā€™m sorry by my inexpertise.
Iā€™m developing a single ESPHome device using HA.
Please, could you answer me next questions?

When you said ā€œtemplate.yamlā€ are you refering to? Is it the file ā€œyamlā€ Iā€™m editing with HA defining the device behavior?.
Best regards and thank you in advance

I refering to the configuration.yaml and template.yaml files in the HA config directory.
In the configuration.yaml you add the line

template: !include template.yaml

You probably have to create the file template.yaml via for example the terminal add-on.
You add the earlier mentioned code in the template.yaml file

When ready, check the configuration in the left side menu ā†’ ā€˜developer toolsā€™ / YAML ā†’ check configuration
And when OK, push below ā€™ YAML configuration reloadingā€™ ā†’ ā€˜template entitiesā€™
After this the binary_sensor should be available.

1 Like

So what @tom_l means is that you need to create a binary sensor in the ESPHome config (if not already done so):

# Binary Sensors.
binary_sensor:
  - platform: status
    name: My ESP Connection Status
    id: esp12_connection_status

Which will create the binary sensor in HA:
binary_sensor.esp12_connection_status, on which you can base the trigger.

Yes thats a better solution for ESP device status monitoring.

Thank you very much.
My intention was to create a HA watchdog, but no for device. I need to check, from the device, if HA is alive.
I solved using a heartbeat generated in HA using Nodered timers.
BR

Is it possible to use ESP32 as a watchdog for other devices?

It is really Really REALLY rare that I have had Home Assistant become unresponsive (<5 times in 5 years) but it would be awesome to have something monitor for this outage and perhaps take action.

Sorry when i slide into this subjectā€¦
Can this be used to let me know when an esphome device is not responding any more?
I have a 4 relay board that stops responding after an unknown time and i cant find out why?!
Getting a notification could at least give me a chance to find a pattern/fix

Thx alot

I guess you could add a time sensor in ESP-Home that is then sent back to HA.
When that time stops updating in HA, that is when it stopped responding.

Iā€™m not sure this actually works, this was just a quick thought

1 Like