ESPHome restart notification

I’m trying to get a notification when ESPhome restarts, without success.

I have this binary sensor in my ESPHome:

 - platform: template
    name: "Pond control has restarted"
    id: pond_control_restarted

and this in on_boot:

  on_boot:
    then:
      - binary_sensor.template.publish:
          id: pond_control_restarted
          state: ON

and in HA I have:

- alias: Pond control has restarted
  initial_state: 'on'
  trigger:
    - entity_id: binary_sensor.pond_control_has_restarted
      platform: state
      from: 'OFF'
      to: 'ON'
  action:
    - service: notify.ALL_DEVICES
      data:
        title: "Koi pond..."
        message: "...control has restarted"
    - service: binary_sensor.turn_off
      entity_id: binary_sensor.pond_control_has_restarted

Using States in Dev tools to toggle binary_sensor.pond_control_has_restarted delivers the notification OK.

What am I missing here?

Try it without the from: 'OFF' in the trigger.
My esphome binary sensors go from ‘unavailable’ to ‘on’ after a restart.

1 Like

Thank you. I’d already tried that option without success.

Does the rest of it look OK to you.

It might be that the on_boot action is failing because the network isn’t connected at that time. Perhaps add a delay or check for wifi connection?

Alternatively, set up an uptime sensor and write the HA automation based off that (if the sensor drops below say 300s, send the notification).

1 Like

Fixed it!

Interestingly, in states, the binary sensor shows as ‘On’ or ‘Off’ with the ESPhome publishing ON (as per the docs) at boot.

Setting the automation trigger to ‘on’, ‘On’ or ‘ON’ failed to trigger the automation. However, when I set the publish to ‘On’ all works fine.

I’m missing the logic to that though :confused:

I think that your problem was that you didn’t have the single quotes around ON.

1 Like

You may well be correct, but the docs don’t call for quotes to be used.

I’ll give it another go with the quotes tomorrow and see what the differences are. It’s alway good to understand these anomalies.

EDIT: I may have mislead you with my post there. I don’t have On in quotes in the publish action, yet it all works fine.

      - binary_sensor.template.publish:
          id: pond_control_restarted
          state: On
- alias: Pond control has restarted
  initial_state: 'on'
  trigger:
    - entity_id: binary_sensor.pond_control_has_restarted
      platform: state
      to: 'On'

As far as I understand (don’t quote me on this), Esphome translates the YAML into C/C++ and C/C++ is case sensitive and very picky regarding syntax. Please try it and let us know the results. Thanks

We cross posted there. Please see above.

This is my understanding also.