Skip to content

Add boot improvements and version sensors#75

Open
bharvey88 wants to merge 11 commits intobetafrom
fw-boot-improvements
Open

Add boot improvements and version sensors#75
bharvey88 wants to merge 11 commits intobetafrom
fw-boot-improvements

Conversation

@bharvey88
Copy link
Contributor

@bharvey88 bharvey88 commented Jan 30, 2026

Summary

Adds diagnostic text sensors and connection status indication during boot sequence.

Changes

  • Text Sensors: Added ESPHome Version and Apollo Firmware Version sensors for diagnostics
  • Connection Status: Added statusCheck script matching BTN-1 implementation
    • Blue light (5s): Connected to Home Assistant
    • Green light (5s): Connected to WiFi only
    • Yellow light (5s): Not connected
  • Boot Sequence: Updated to show connection status before hardware test
  • Cleanup: Removed redundant white startup blink

Testing Status

Ready for local testing and validation on hardware.

Files Modified

  • Core.yaml - Added text sensors and statusCheck script
  • MTR-1.yaml - Updated boot sequence
  • MTR-1_BLE.yaml - Updated boot sequence
  • MTR-1_Factory.yaml - Updated boot sequence

Summary by CodeRabbit

  • New Features

    • Two text sensors added for ESPHome and device firmware versions.
    • New statusCheck and diagnosticCheck scripts to indicate connection state via RGB status and run diagnostic sequences; Boot Status LED switch added to control boot-status behavior.
    • Short button press now triggers a diagnostic check.
  • Chores

    • Boot/connect sequencing adjusted so status checks run reliably on first boot and reconnects.

- Add ESPHome Version and Firmware Version text sensors for diagnostics
- Add statusCheck script for connection status indication
  - Blue light: Connected to Home Assistant
  - Green light: Connected to WiFi only
  - Yellow light: Not connected
- Update boot sequence to show connection status before hardware test

Removes white startup blink (redundant with connection status).
Connection status logic matches BTN-1 implementation.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 30, 2026

Walkthrough

Added boot-status globals, new diagnostic text sensors, a Boot Status LED switch, statusCheck and diagnosticCheck scripts, an api.on_client_connected handler, and updated device on_boot/wifi connect sequences to run statusCheck on first boot when enabled.

Changes

Cohort / File(s) Summary
Core — Integrations/ESPHome/Core.yaml
Integrations/ESPHome/Core.yaml
Added globals first_boot_done (bool, initial false, no restore) and boot_status_enabled (bool, initial true, restore yes). Added api.on_client_connected handler (1s delay) to run statusCheck. Added text_sensor entries (ESPHome Version, Apollo Firmware Version). Added switch template for Boot Status LED controlling boot_status_enabled. Added script entries statusCheck and diagnosticCheck (connectivity checks, RGB control, delays) and exposed them as public. Adjusted button diagnostic threshold logic to 2000ms and diagnosticCheck invocation.
Device configs — on_boot / wifi connect
Integrations/ESPHome/MTR-1.yaml, Integrations/ESPHome/MTR-1_BLE.yaml, Integrations/ESPHome/MTR-1_Factory.yaml
Changed esphome.on_boot.priority from -10 to 600. Added wifi.on_connect / wifi.ap.on_connect sequences with delay: 10s and an if guard !id(first_boot_done) && id(boot_status_enabled) that sets id(first_boot_done)=true and executes statusCheck.

Sequence Diagram(s)

sequenceDiagram
    participant Device as Device (on_boot / wifi.on_connect)
    participant API as API (on_client_connected)
    participant Script as Script (`statusCheck`)
    participant HA as HomeAssistant (ink_ha_connected)
    participant WiFi as WiFi (wifi.connected)
    participant RGB as RGB Light (rgb_light)

    Device->>API: on_client_connected / client connects
    API->>Script: delay 1s\nexecute statusCheck
    Script->>HA: check ink_ha_connected
    Script->>WiFi: check wifi.connected
    alt HA connected
        Script->>RGB: set color rgba(0,128,255,0.5)
    else WiFi only
        Script->>RGB: set color rgba(0,128,0,0.5)
    else neither
        Script->>RGB: set color rgba(255,165,0,0.5)
    end
    Script->>Script: delay 5s
    Script->>RGB: turn off
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

bugfix

Suggested reviewers

  • TrevorSchirmer

Poem

🐰 I nudged the boot flag, sniffed the air so bright,
I blinked blue for the host and green for Wi‑Fi light.
Amber if lonely, five seconds then dim —
I’m a hopping little rabbit, testing each limb.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: boot sequence improvements and version sensor additions, covering the primary objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fw-boot-improvements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

bharvey88 and others added 2 commits January 30, 2026 12:21
Changes "Firmware Version" to "Apollo Firmware Version" for clarity.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Changed on_boot priority from -10 to 600 to ensure WiFi is connected
before checking connection status. Previously showed yellow (not connected)
even when device would successfully connect moments later.

Priority 600 runs later in boot sequence, after network initialization.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@Integrations/ESPHome/MTR-1.yaml`:
- Around line 12-15: The on_boot trigger is running statusCheck before WiFi is
connected (so it always reports "not connected"); replace the on_boot block with
the WiFi component's on_connect trigger so statusCheck runs after connection is
established — locate the on_boot block that executes script.execute: statusCheck
and change it to an on_connect trigger under the WiFi component (using
on_connect then: - script.execute: statusCheck), ensuring the statusCheck script
is invoked only after WiFi connects.

bharvey88 and others added 4 commits January 30, 2026 12:31
Moved statusCheck from on_boot to wifi.on_connect trigger to ensure
it only runs after WiFi connection is established. This prevents
showing yellow (not connected) status during boot when the device
will successfully connect moments later.

The on_connect trigger guarantees WiFi is connected when statusCheck
runs, so it will correctly show blue (HA connected) or green (WiFi only).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Added api.on_connect trigger to run statusCheck when HA connects
  This fixes the issue where device showed green even when connected
  to HA, because WiFi connects before API connection is established
- Removed unnecessary update_interval from firmware version sensor
  (version only changes on firmware update, not during runtime)

Now the boot sequence will be:
1. WiFi connects → green light
2. API connects → updates to blue light

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Changed from on_connect to on_client_connected which is the correct
trigger name for the ESPHome API component. The previous on_connect
was causing build failures.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added mode: restart to allow statusCheck to be interrupted when called
again. This fixes cold boot behavior where:
- WiFi connects → green light → statusCheck running
- API connects → tries to run statusCheck but was ignored (single mode)
- Light turns off before showing blue

With restart mode, API connection will interrupt the green light and
immediately show blue when HA connects.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@bharvey88 bharvey88 marked this pull request as draft January 30, 2026 23:23
@Bunton33 Bunton33 marked this pull request as ready for review February 2, 2026 16:50
bharvey88 and others added 4 commits February 2, 2026 16:36
Add first_boot_done global flag to prevent statusCheck from running
on subsequent WiFi/HA reconnections. The LED status indicator now
only shows once per device power cycle:

- Device boots → LED shows connection status (blue/green/yellow)
- HA restarts → No LED (flag already set)
- WiFi roams → No LED (flag already set)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Change statusCheck mode from 'restart' to 'single' to ensure
  the script always completes (including turn_off)
- Add 1s delay to api.on_client_connected for connection stability
- Add 10s delay to wifi.on_connect to give HA priority over WiFi-only status

The bug was caused by mode:restart cancelling the first script run
(with its turn_off) when a second trigger came in, while the guard
check caused the second run to skip everything entirely.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Short press (<1s): Shows connection status (blue=HA, green=WiFi, yellow=none)
- 1-7s press: Hardware test (unchanged)
- 8s+ press: Factory reset (unchanged)

Moved first_boot_done guard from statusCheck script to triggers,
so manual button press always works while automatic triggers only
run once per boot. Matches BTN-1 behavior.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add boot_status_enabled global (persists, ON by default)
- Add "Boot Status LED" switch for users to enable/disable boot status
- Update button: 2-8s hold runs diagnosticCheck (statusCheck + testScript)
- Add diagnosticCheck script: runs statusCheck, waits 3s, runs testScript
- Update all triggers to respect boot_status_enabled toggle

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
Integrations/ESPHome/MTR-1.yaml (1)

12-19: ⚠️ Potential issue | 🟠 Major

Boot test shows LED before status check due to timing, inverting the desired LED sequence when status is enabled.

On boot (priority 600), testScript executes immediately if runTest is true. However, statusCheck only runs later when WiFi or API connects and only on first connection (guarded by first_boot_done and boot_status_enabled). This means the test LED displays before the status LED, which conflicts with the intent to show connection status before hardware diagnostics. When boot_status_enabled is true, use diagnosticCheck instead—it explicitly runs status first, then the test.

Suggested adjustment
   on_boot:
     priority: 600
     then:
       - if:
           condition:
             - lambda: "return id(runTest);"
           then:
             - if:
                 condition:
                   - lambda: "return id(boot_status_enabled);"
                 then:
                   - script.execute: diagnosticCheck
                 else:
                   - script.execute: testScript
Integrations/ESPHome/MTR-1_Factory.yaml (1)

12-19: ⚠️ Potential issue | 🟠 Major

Gate testScript execution on boot_status_enabled to sequence connection status before hardware test.

When both runTest and boot_status_enabled are true, testScript runs immediately on boot while statusCheck attempts to run ~10 seconds later on WiFi connect. This causes LED display conflicts since both scripts control the RGB light independently. The intended sequence is to show connection status first, then run the hardware test.

Use diagnosticCheck when boot_status_enabled=true to ensure statusCheck (connection LED) runs before testScript (test result LED):

Suggested adjustment
   on_boot:
     priority: 600
     then:
       - if:
           condition:
             - lambda: "return id(runTest);"
           then:
-            - lambda: "id(testScript).execute();"
+            - if:
+                condition:
+                  - lambda: "return id(boot_status_enabled);"
+                then:
+                  - script.execute: diagnosticCheck
+                else:
+                  - script.execute: testScript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments