From 4fd3a372aed563943e5a454b1bbc50abe749e0fe Mon Sep 17 00:00:00 2001 From: Brandon Harvey <8107750+bharvey88@users.noreply.github.com> Date: Tue, 7 Jul 2026 15:23:27 -0500 Subject: [PATCH] Add Firmware Channel switching and serve end-user image for OTA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same feature as CAST-1 and AIR-1 (ApolloAutomation/AIR-1#107): - Firmware Channel select (Stable/Beta) sets the OTA manifest URL via a new apply_ota_source script; Firmware Update button force-installs and prevents deep sleep for the download duration. - BTN-1_Minimal.yaml (the adopted end-user config) gains the managed update system so fielded devices can keep updating after leaving the improv image. - build.yml now serves BTN-1_Minimal.yaml at firmware/; BTN-1.yaml (improv + BLE) moves to firmware-factory/ for the web installer only. - build-beta.yml publishes beta builds to a rolling beta pre-release. - update component id renamed firmware_update -> update_http_request to match the other Apollo repos. Beta-channel builds compile thin beta-channel/ wrapper yamls so the Firmware Channel select defaults to Beta on firmware obtained from the beta channel (fresh flashes only; stored choices still win). Version: 26.7.8.1 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- .github/workflows/build-beta.yml | 91 +++++++++++++++++++ .github/workflows/build.yml | 6 +- Integrations/ESPHome/.gitignore | 1 + Integrations/ESPHome/BTN-1.yaml | 4 +- Integrations/ESPHome/BTN-1_Minimal.yaml | 15 +++ Integrations/ESPHome/Core.yaml | 86 +++++++++++++++++- .../ESPHome/beta-channel/BTN-1_Minimal.yaml | 9 ++ static/index.html | 2 +- 8 files changed, 209 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/build-beta.yml create mode 100644 Integrations/ESPHome/beta-channel/BTN-1_Minimal.yaml diff --git a/.github/workflows/build-beta.yml b/.github/workflows/build-beta.yml new file mode 100644 index 0000000..f8d8b59 --- /dev/null +++ b/.github/workflows/build-beta.yml @@ -0,0 +1,91 @@ +name: Build and Publish Beta + +# Builds BTN-1 firmware from the beta branch and publishes it as assets on a +# rolling "beta-fw" pre-release. The on-device "Firmware Channel" select points +# OTA updates at these assets. Stable firmware is built/published separately +# by build.yml (push to main -> GitHub Pages). + +on: + push: + branches: [beta] + paths: + - 'Integrations/ESPHome/**' + workflow_dispatch: + +# Least privilege: read-only by default; only publish-beta is elevated to write. +permissions: + contents: read + +jobs: + version: + name: Read version + runs-on: ubuntu-latest + outputs: + v: ${{ steps.read.outputs.v }} + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + persist-credentials: false + - id: read + run: | + v=$(awk '/substitutions:/ {f=1} f && /version:/ {print $2; exit}' \ + Integrations/ESPHome/Core.yaml | tr -d '"') + echo "v=$v" >> "$GITHUB_OUTPUT" + echo "Beta version: $v" + + build: + name: Build firmware + needs: version + # Beta serves OTA updates only, so it builds the end-user image + # (BTN-1_Minimal.yaml), not the first-flash improv image. + uses: esphome/workflows/.github/workflows/build.yml@025a1e6255610c498ed590403b7e510b69e474df # 2026.4.1 + with: + files: Integrations/ESPHome/beta-channel/BTN-1_Minimal.yaml + esphome-version: stable + combined-name: firmware-beta + release-version: ${{ needs.version.outputs.v }} + + publish-beta: + name: Publish beta release assets + needs: [version, build] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Download firmware artifacts + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + path: fw + pattern: firmware* + + - name: Ensure rolling 'beta-fw' pre-release exists + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release view beta-fw -R "${{ github.repository }}" >/dev/null 2>&1 \ + || gh release create beta-fw -R "${{ github.repository }}" \ + --prerelease --title "Beta (rolling)" \ + --notes "Latest BTN-1 beta firmware. Auto-updated on every push to the beta branch." + + - name: Rewrite manifest to absolute URLs and upload assets + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + BASE="https://github.com/${{ github.repository }}/releases/download/beta-fw" + man=$(find fw/firmware-beta -name manifest.json | head -1) + if [ -z "$man" ]; then + echo "::error::manifest.json not found" + exit 1 + fi + echo "Rewriting $man" + # Make ota.path and parts[].path absolute release-asset URLs so the + # device never has to resolve a relative path against a redirect. + jq --arg base "$BASE" ' + .builds[0].ota.path = ($base + "/" + (.builds[0].ota.path | sub(".*/"; ""))) + | .builds[0].parts |= map(.path = ($base + "/" + (.path | sub(".*/"; "")))) + ' "$man" > manifest.json + cat manifest.json + gh release upload beta-fw manifest.json -R "${{ github.repository }}" --clobber + find fw/firmware-beta -name '*.bin' -print -exec \ + gh release upload beta-fw {} -R "${{ github.repository }}" --clobber \; + echo "Beta assets published." diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a603e42..495dfb6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,9 +24,13 @@ jobs: pull-requests: write with: device-name: btn-1 + # BTN-1_Minimal.yaml is the end-user image served at firmware/ (OTA + # updates and dashboard adoption). BTN-1.yaml (improv + BLE) is only + # used for first flashes via the web installer. yaml-files: | + Integrations/ESPHome/BTN-1_Minimal.yaml Integrations/ESPHome/BTN-1.yaml - firmware-names: "1:firmware" + firmware-names: "1_Minimal:firmware,1:firmware-factory" core-yaml-path: Integrations/ESPHome/Core.yaml esphome-version: stable # Bypass check if manually triggered with bypass option diff --git a/Integrations/ESPHome/.gitignore b/Integrations/ESPHome/.gitignore index d8b4157..78a2a3e 100644 --- a/Integrations/ESPHome/.gitignore +++ b/Integrations/ESPHome/.gitignore @@ -3,3 +3,4 @@ # You can modify this file to suit your needs. /.esphome/ /secrets.yaml +beta-channel/.esphome/ diff --git a/Integrations/ESPHome/BTN-1.yaml b/Integrations/ESPHome/BTN-1.yaml index 572a882..e552bed 100644 --- a/Integrations/ESPHome/BTN-1.yaml +++ b/Integrations/ESPHome/BTN-1.yaml @@ -20,13 +20,13 @@ safe_mode: update: - platform: http_request - id: firmware_update + id: update_http_request name: Firmware Update source: https://apolloautomation.github.io/BTN-1/firmware/manifest.json wifi: on_connect: - - component.update: firmware_update + - component.update: update_http_request ap: ssid: "Apollo BTN1 Hotspot" diff --git a/Integrations/ESPHome/BTN-1_Minimal.yaml b/Integrations/ESPHome/BTN-1_Minimal.yaml index 02a86ca..0f24374 100644 --- a/Integrations/ESPHome/BTN-1_Minimal.yaml +++ b/Integrations/ESPHome/BTN-1_Minimal.yaml @@ -5,8 +5,23 @@ dashboard_import: ota: - platform: esphome id: ota_esphome + - platform: http_request + id: ota_managed + +http_request: + verify_ssl: true + +safe_mode: + +update: + - platform: http_request + id: update_http_request + name: Firmware Update + source: https://apolloautomation.github.io/BTN-1/firmware/manifest.json wifi: + on_connect: + - component.update: update_http_request ap: ssid: "Apollo BTN-1 Hotspot" diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 00cdf8e..62c0d63 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -1,8 +1,17 @@ substitutions: name: apollo-btn-1 - version: "26.3.2.1" + version: "26.7.8.1" device_description: ${name} made by Apollo Automation - version ${version}. + # Default update channel on first boot (no stored user choice yet, i.e. a + # fresh flash). The beta-channel builds override this to "Beta" (see + # Integrations/ESPHome/beta-channel/) so firmware obtained from the beta + # channel keeps tracking it instead of offering a stable "downgrade". + firmware_channel_default: "Stable" + # Manifest URL bases. Stable = GitHub Pages (main branch builds). + # Beta = rolling "beta" pre-release assets (beta branch builds). + stable_manifest_base: "https://apolloautomation.github.io/BTN-1" + beta_manifest_base: "https://github.com/ApolloAutomation/BTN-1/releases/download/beta-fw" esphome: @@ -288,6 +297,52 @@ button: icon: mdi:power-cycle name: "ESP Reboot" + - platform: template + name: "Firmware Update" + id: update_firmware + icon: mdi:cloud-download + entity_category: "config" + on_press: + - logger.log: "Applying firmware based on selected channel" + # OTA download needs the device awake for its whole duration. + - lambda: |- + id(deep_sleep_1).prevent_deep_sleep(); + # Free heap for the TLS download when BLE (improv) is active. Guarded + # so images without BLE compile the same YAML. + - lambda: |- + #ifdef USE_ESP32_BLE + if (esp32_ble::global_ble && esp32_ble::global_ble->is_active()) { + ESP_LOGI("firmware", "Disabling BLE for firmware update"); + esp32_ble::global_ble->disable(); + } + #endif + - delay: 3s + - script.execute: apply_ota_source + - script.wait: apply_ota_source + # The manifest fetch runs in its own task and YAML has no "fetch done" + # condition to wait on (update.is_available stays false for same-version + # switches), so give it a fixed window like R_PRO-1/CAST-1 do. + - delay: 5s + - update.perform: + id: update_http_request + force_update: true + # Only reached if the update did not start (e.g. manifest unreachable). + - lambda: |- + #ifdef USE_ESP32_BLE + if (esp32_ble::global_ble) { + ESP_LOGI("firmware", "Re-enabling BLE (no update performed)"); + esp32_ble::global_ble->enable(); + } + #endif + - if: + condition: + and: + - switch.is_off: prevent_sleep + - binary_sensor.is_off: ota_mode + then: + - lambda: |- + id(deep_sleep_1).allow_deep_sleep(); + # Button entities for physical buttons binary_sensor: - platform: status @@ -678,7 +733,36 @@ light: max_brightness: 100% +select: + - platform: template + name: "Firmware Channel" + id: firmware_channel + icon: mdi:source-branch + entity_category: "config" + optimistic: true + restore_value: true + options: + - "Stable" + - "Beta" + initial_option: "${firmware_channel_default}" + on_value: + then: + - script.execute: apply_ota_source + script: + - id: apply_ota_source + # Sets the OTA manifest URL from the Firmware Channel select. + # Stable = GitHub Pages, Beta = rolling "beta" release assets. + then: + - lambda: |- + const bool beta = id(firmware_channel).current_option() == "Beta"; + std::string url = beta + ? "${beta_manifest_base}/manifest.json" + : "${stable_manifest_base}/firmware/manifest.json"; + ESP_LOGI("firmware", "OTA manifest set to: %s", url.c_str()); + id(update_http_request).set_source_url(url); + - component.update: update_http_request + - id: statusCheck then: - if: diff --git a/Integrations/ESPHome/beta-channel/BTN-1_Minimal.yaml b/Integrations/ESPHome/beta-channel/BTN-1_Minimal.yaml new file mode 100644 index 0000000..b3264e8 --- /dev/null +++ b/Integrations/ESPHome/beta-channel/BTN-1_Minimal.yaml @@ -0,0 +1,9 @@ +# Beta-channel build of BTN-1_Minimal.yaml: the identical image except the Firmware +# Channel select defaults to "Beta" on first boot, so firmware obtained from +# the beta channel keeps tracking it. Built by build-beta.yml only; the +# stable (GitHub Pages) builds use BTN-1_Minimal.yaml directly. +substitutions: + firmware_channel_default: "Beta" + +packages: + base: !include ../BTN-1_Minimal.yaml diff --git a/static/index.html b/static/index.html index 27ac81d..851cf95 100644 --- a/static/index.html +++ b/static/index.html @@ -82,7 +82,7 @@

Apollo BTN-1 Installer

- +