Logging and HA Actions in the on_boot automation - ESP32 S3

Hello Friends!

I have some logging and Home Assistant actions I’m trying to run within the on_boot automation for an ESP32 S3 module. The HA actions I’m trying to run are notify actions.

The boot actions I have configured on local switches (nested in IF - THEN - ELSE blocks) are working as expected but I cannot get any log entries or notifications from within the on_boot automation.

I understand the HA actions rely on the Native API being connected so I have tried several different priorities for the on_boot automation. 600 (default), 300, 150, 10, -10, and -100.

I know my approach is valid because this block of code works just fine. It’s part of a separate template switch configuration in the same device:

    on_turn_off:
      - logger.log:
          level: WARN
          format: "Water automation has been disabled."
          tag: "automation"
      - homeassistant.action:
          action: notify.mobile_app_...
          data:
            title: "Water Automation Disabled"
            message: "Water automation has been disabled."

I’ve included the yaml below incase someone sees something I’m overlooking. There is a lot going on here but I know most of it is working because of the state of entities after the boot sequence has completed.

  on_boot: 
    - priority: -100
      then:
        - logger.log:
            level: INFO
            format: "Starting Well Automation Controller boot sequence..."
            tag: "boot"
        - if:
            any:  # Check for leak conditions on boot
              - binary_sensor.is_on: well_leak
              - binary_sensor.is_on: distribution_leak
            then:
              - switch.template.publish:
                  id: water_automation
                  state: OFF
              - switch.turn_off: well_pump
              - switch.turn_on: pressure_disconnect
              - switch.turn_on: tank_discharge_close
              - homeassistant.action:
                  action: notify.mobile_app_...
                  data:
                    title: "Water Leak Detected!"
                    message: "See the notification panel for more details."
              - homeassistant.action:
                  action: notify.persistent_notification
                  data:
                    title: "Water Leak Detected!"
                    message: |-
                      A water leak has been detected by the well automation controller during startup.
                      To prevent water damage, the well pump has been disabled, the pressure pump disconnected,
                      and the tank discharge valve closed.
                      
                      Please investigate and resolve the leak condition before re-enabling water automation.
            else:
              - if:
                  condition:  # Disable well automation if the tank is full on boot
                    binary_sensor.is_on: tank_full
                  then:
                    - switch.template.publish:
                        id: water_automation
                        state: OFF
                    - switch.turn_off: well_pump
                    - homeassistant.action:
                        action: notify.mobile_app_...
                        data:
                          title: "Water Tank is at Maximum Capacity"
                          message: "See the notification panel for more details."
                    - homeassistant.action:
                        action: notify.persistent_notification
                        data:
                          title: "Water Tank is at Maximum Capacity"
                          message: |-
                            The water storage tank was detected to be full during startup of the well automation controller.

                            To prevent overfilling, well pump automation has been disabled.

                            Investigation into why the Pump_Off trigger did not function properly is recommended.
                  else:
                    if: 
                      condition:  # If the tank level is low on boot, enable automation, set tank mode to fill, and turn off the pressure pump.
                        binary_sensor.is_off: low_water_shutdown
                      then:
                        - switch.template.publish:
                            id: water_automation
                            state: ON
                        - switch.template.publish:
                            id: tank_mode
                            state: OFF  #fill mode
                        - switch.turn_on: pressure_disconnect
                        - homeassistant.action:
                            action: notify.mobile_app_...
                            data:
                              title: "Water Tank Volume is Low"
                              message: "See the notification panel for more details."
                        - homeassistant.action:
                            action: notify.persistent_notification
                            data:
                              title: "Water Tank Volume is Low"
                              message: |-
                                The water storage tank level was detected to be low during startup of the well automation controller.

                                The pressure pump has been disconnected to prevent damage from running dry.

                                Investigation into the low water condition is recommended.
                      else: # No issues were found.  Enable water automation and set tank mode based on well pump trigger state.
                        - logger.log:
                            level: INFO
                            format: "Well Automation Controller started successfully with no issues found.  Enabling water automation."
                            tag: "boot"
                        - switch.template.publish:  #<-- This block executes fine.
                            id: water_automation
                            state: ON
                        - if:
                            condition:
                              binary_sensor.is_off: trigger_well_pump_on
                            then:
                              - switch.template.publish:
                                  id: tank_mode
                                  state: OFF  #fill mode
                            else:
                              - switch.template.publish: #<-- The tank is mostly full right now so this block executes fine.
                                  id: tank_mode
                                  state: ON  #drain mode
                        - homeassistant.action:
                            action: notify.mobile_app_...
                            data:
                              title: "Water Automation Enabled"
                              message: "The controller has successfully started and water automation is enabled."
                        - homeassistant.action:
                            action: notify.persistent_notification
                            data:
                              title: "Water Automation Enabled"
                              message: |-
                                The well automation controller has successfully started and water automation is enabled.
                                
                                Tank mode has been set based on the current water level sensor states.
                        - logger.log:
                            level: INFO
                            format: "Notifications should have been sent by now."
                            tag: "boot"

If you made it this far, thank you for taking the time to look at this. I do appreciate any thoughts and comments.

Should have mentioned, this is on:
Home Assistant Core version 2025.12.5
ESPHome version 2025.12.3

You could try waiting until the api is connected?

1 Like

Two different things. For notifications @Mahko_Mahko gave your steps needed. But if you don’t get anything on esphome logs from on_boot, then you have some issue there.

1 Like

@Mahko_Mahko, great suggestion! Thank you! I hadn’t thought of checking for the API connection before sending the notification. I’ll give it a shot and report back.

If I can get the notifications working the logging is less of an issue. I’ll work on the notifications first.

I’m not sure but I seem to recall missing logs that are logged early on in the boot too.

I think maybe the api needs to be connected for them to be transmitted to the logger console?

And I seem to recall wifi and api connection times being a bottleneck for that.

@jwaz73 are you viewing logs while connected to the esp via wifi or serial? Try serial. I think logs will appear sooner on boot.

I was just thinking about that too. I’m connected to the console via WiFi which I figured also relies on the API being connected.

I’m thinking I will just wrap the whole on_boot automation in a wait.until statement.

on_boot:
  - wait.until:
      api.connected
    then:

Or something like that. I will review the api document again today after work.

No way.

Depends on if you use serial or wifi, obviously wireless logs don’t work before wifi is ready to rock.

2 Likes

If that ends up as part of your solution make sure you have a timeout set in case connections etc don’t happen.

Pretty sure Karosm is right that to view logs over WiFi obviously the wifi needs to be connected but maybe less obviously the api doesn’t (you can view wifi logs before you integrate the device).

So you can look at a wifi connected condition too if needed.

Also search around for how to speed up wifi connection times (static IP, fast connect etc).

1 Like

I think I understand what you guys are saying. Let me clarify my earlier statement. I’m viewing the logs by clicking the ‘Logs’ link from the ESPHome Builder Add-On to Home Assistant. Unfortunately, that’s the only method I have available to me currently. I did not expose the uart pins from the MCU in this prototype version and I blocked (unintentionally) access to the USB port for now. I don’t have an easy way to make a serial connection to the physical device currently. I will correct this for future troubleshooting soon!

For now, both logging and mobile app notifications are working!

I modified the on_boot automation to begin as follows:

  on_boot:
    - priority: -100
      then:
        - wait_until:
            condition:
              api.connected:
                state_subscription_only: True
            timeout: 30s
        - if:
            ...

After applying this update to the device the log entries were visible and my devices were notified.

I’m sure this can still be optimized further but I will work on that for my next iteration on this device. For now I’m finishing the balance of the functionality of this first prototype device.

I appreciate your courteous input! It was very helpful.

1 Like

BTW:
Once the api connected, evaluating the full on_boot module took about 13ms

[21:17:33.290][I][boot:573]: Starting Well Automation Controller boot sequence...
[21:17:33.290][I][boot:737]: Well Automation Controller started successfully with no issues found.  Enabling water automation.
[21:17:33.295][D][switch:065]: 'Water Automation': Sending state ON
[21:17:33.297][D][switch:065]: 'Tank Mode': Sending state ON
[21:17:33.303][I][boot:764]: Notifications should have been sent by now.