ESPHome: on_boot push message over http post

Hello all,

is there anyone who can help?
Error:
INFO ESPHome 2024.7.2
INFO Reading configuration /config/esphome/testesp.yaml…
Failed config
on_boot: [source /config/esphome/testesp.yaml:25]
Component not found: on_boot.

esphome:
  name: testesp
  friendly_name: TestESP

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "<my key>"

ota:
  - platform: esphome
    password: "<my pw>"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

on_boot:
  priority: 250
  then:
    - http_request.post:
        url: https://api.pushover.net/1/messages.json
        headers:
          Content-Type: application/json
        json: !lambda |-
          return {
            "token": "my-token",
            "user": "my-user",
            "message": "Device Booted",
            "title": "ESPHome Alert"
          };

Background Info:
I’m using an esp8266 as a battery powered sensor for a server room door. It gets power when the door is open and sends a pushmessage using pushover immediately with standard arduino code.

Now I wanted to connect it to HomeAssistant with ESPhome but I still want it to send the push message directly instead of sending it over homeassistant. So I thought it might work with the on_boot option.

on_boot: needs to be a subsection of the esphome: component.

Many Thanks!

Here is the working code, if someone stumbles over the same challenge:

esphome:
  name: testesp
  friendly_name: TestESP
  on_boot:
    priority: 250
    then:
      - http_request.post:
          url: https://api.pushover.net/1/messages.json
          headers:
            Content-Type: application/json
          json:
            token: "<myToken>"
            user: "<myUser>"
            message: "Device Booted"
            title: "ESPHome Alert"
            sound: "siren" # optional
            priority: "2" # -2 to 2
            retry: "120" # retry is mandatory with prio 2
            expire: "6000" # expire is mandatory with prio 2

http_request:
  verify_ssl: false