Trigger automation when ESP boots

Hi!

I have a ESP-01s with esphome in deep-sleep. The only thing this ESP shall do is trigger an automation if it boots, then go to sleep. Going to sleep works well. But I am not shure, how to trigger an automation in this case. I tried the following way:

esphome:
  name: esp-01s-0123456789
  on_boot:
    priority: -100.0
    then:
      - homeassistant.event:
          event: esphome.button_pressed
          data:
            message: Button was pressed

But how can I modify this, to trigger an automation? And how would I configure the automation? This does not seem to work:

trigger:
  - platform: event
    event_type: esphome.button_pressed

Best

Pascal

First thing you should check for is if the the api is connected:

esphome:
  on_boot:
    if:
      condition:
        api.connected:
      then:
        - logger.log: API is connected! Now we can trigger what we want!
        - homeassistant.service:
            service: notify.html5
            data:
              message: We got this happening!
        - logger.log: Time for deep sleep! zzZ

Maybe you want to run a script instead?

I am sorry, but this doesn’t work. If I do not add the priority, it defaults to 600. This is before WiFi is even connected. So the condition will never be fullfilled. But using the “if” + “priority” does not compile.

Did you try something like:

esphome:
  on_boot:
    priority: -100.0
    then:
      if:
        condition:
          api.connected:
        then:
          - logger.log: ...

And if that doesn’t compile what do the logs tell you/us about it? :thinking: