From 16997342fdd0397221940867ed6c84091f7c25f6 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Thu, 19 Dec 2024 16:27:10 -0500 Subject: [PATCH 1/3] Create Minimal Firmware On ESPHome Addon Import --- Integrations/ESPHome/Core.yaml | 20 ++- Integrations/ESPHome/H-1.yaml | 2 +- Integrations/ESPHome/H-1_Minimal.yaml | 177 ++++++++++++++++++++++++++ 3 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 Integrations/ESPHome/H-1_Minimal.yaml diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 1d7870b..03ae187 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -1,5 +1,5 @@ substitutions: - version: "24.11.25.1" + version: "24.12.19.1" esp32: board: esp32-c3-devkitm-1 @@ -72,6 +72,24 @@ button: name: "Factory Reset" entity_category: diagnostic internal: true + - platform: template + id: btn_play_song_1 + name: "Play Song 1" + on_press: + then: + - script.execute: play_song_1 + - platform: template + id: btn_play_song_2 + name: "Play Song 2" + on_press: + then: + - script.execute: play_song_2 + - platform: template + id: btn_play_song_3 + name: "Play Song 3" + on_press: + then: + - script.execute: play_song_3 number: - platform: template diff --git a/Integrations/ESPHome/H-1.yaml b/Integrations/ESPHome/H-1.yaml index 9f33c01..a94b7d7 100644 --- a/Integrations/ESPHome/H-1.yaml +++ b/Integrations/ESPHome/H-1.yaml @@ -36,7 +36,7 @@ esphome: - light.turn_off: rgb_light dashboard_import: - package_import_url: github://ApolloAutomation/H-1/Integrations/ESPHome/H-1.yaml + package_import_url: github://ApolloAutomation/H-1/Integrations/ESPHome/H-1_Minimal.yaml import_full_config: false improv_serial: diff --git a/Integrations/ESPHome/H-1_Minimal.yaml b/Integrations/ESPHome/H-1_Minimal.yaml new file mode 100644 index 0000000..70d3b08 --- /dev/null +++ b/Integrations/ESPHome/H-1_Minimal.yaml @@ -0,0 +1,177 @@ +esphome: + name: "apollo-h-1" + friendly_name: Apollo H-1 Minimal + comment: Apollo H-1 Minimal + name_add_mac_suffix: true + platformio_options: + board_build.flash_mode: dio + + project: + name: "ApolloAutomation.H-1_Minimal" + version: "${version}" + + min_version: 2023.11.1 + on_boot: + - priority: 500 + then: + - lambda: |- + id(deep_sleep_1).set_sleep_duration(id(deep_sleep_sleep_duration).state * 60 * 60 * 1000); + - if: + condition: + or: + - binary_sensor.is_on: ota_mode + - switch.is_on: prevent_sleep + then: + - lambda: |- + ESP_LOGW("Apollo", "Preventing Deep Sleep Due To OTA On Boot"); + id(deep_sleep_1).prevent_deep_sleep(); + - priority: -10 + then: + - if: + condition: + - lambda: "return id(runTest);" + then: + - lambda: "id(testScript).execute();" + on_shutdown: + - light.turn_off: rgb_light + +dashboard_import: + package_import_url: github://ApolloAutomation/H-1/Integrations/ESPHome/H-1_Minimal.yaml + import_full_config: false + +improv_serial: + +ota: + - platform: esphome + id: ota_esphome + +wifi: + ap: + ssid: "Apollo H1 Hotspot" + +logger: + +captive_portal: + +web_server: + port: 80 + +api: + services: + - service: play_buzzer + variables: + song_str: string + then: + - rtttl.play: + rtttl: !lambda 'return song_str;' + - service: play_song_1 + then: + - script.execute: play_song_1 + - service: play_song_2 + then: + - script.execute: play_song_2 + - service: play_song_3 + then: + - script.execute: play_song_3 + reboot_timeout: 0s + on_client_connected: + then: + - delay: 5s + - if: + condition: + or: + - binary_sensor.is_on: ota_mode + - switch.is_on: prevent_sleep + then: + - lambda: |- + ESP_LOGW("Apollo", "Preventing Deep Sleep Due To OTA Or Switch"); + id(deep_sleep_1).prevent_deep_sleep(); +switch: + - platform: template + name: "Prevent Sleep" + id: prevent_sleep + icon: mdi:sleep + restore_mode: RESTORE_DEFAULT_ON + optimistic: true + entity_category: "config" + on_turn_on: + then: + - lambda: |- + id(deep_sleep_1).prevent_deep_sleep(); + on_turn_off: + then: + - if: + condition: + binary_sensor.is_off: ota_mode + then: + - lambda: |- + id(deep_sleep_1).allow_deep_sleep(); + +binary_sensor: + - platform: status + name: Online + id: ink_ha_connected + - platform: homeassistant + name: "OTA Mode" + id: ota_mode + entity_id: input_boolean.apollo_ota_mode + on_press: + then: + - lambda: |- + id(deep_sleep_1).prevent_deep_sleep(); + on_release: + then: + - if: + condition: + switch.is_off: prevent_sleep + then: + - lambda: |- + id(deep_sleep_1).allow_deep_sleep(); + +sensor: + - platform: wifi_signal + name: RSSI + id: wifi_signal_db + update_interval: 60s + entity_category: "diagnostic" + +script: + - id: statusCheck + then: + - if: + condition: + - lambda: 'return id(ink_ha_connected).state;' + then: + - logger.log: "Apollo Automation: Connected To HA" + - light.turn_on: + id: rgb_light + brightness: 40% + red: 0% + green: 0% + blue: 100% + else: + - if: + condition: + - wifi.connected + then: + - logger.log: "Apollo Automation: Connected To Wifi" + - light.turn_on: + id: rgb_light + brightness: 40% + red: 0% + green: 100% + blue: 0% + else: + - logger.log: "Apollo Automation: Not Connected To Wifi" + - light.turn_on: + id: rgb_light + brightness: 40% + red: 100% + green: 100% + blue: 0% + - delay: 5s + - light.turn_off: rgb_light + + +packages: + core: !include Core.yaml From 930377a8d0ca8d932a9bf3a2cdbe95929c130439 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Thu, 19 Dec 2024 16:29:09 -0500 Subject: [PATCH 2/3] Add To CI --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 811417f..ce6f7c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,7 @@ jobs: file: # TODO: Rename - Integrations/ESPHome/H-1.yaml - Integrations/ESPHome/H-1D.yaml + - Integrations/ESPHome/H-1_Minimal.yaml steps: - name: Checkout source code uses: actions/checkout@v4.1.7 From 470c7dfe3e05e3dd899aba3816102eb1e5258bb2 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Fri, 20 Dec 2024 12:45:45 -0500 Subject: [PATCH 3/3] Fix Problem With Random --- .github/workflows/ci.yml | 6 +++++- Integrations/ESPHome/Core.yaml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce6f7c9..0247b9f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,10 +9,14 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - file: # TODO: Rename + file: - Integrations/ESPHome/H-1.yaml - Integrations/ESPHome/H-1D.yaml - Integrations/ESPHome/H-1_Minimal.yaml + esphome-version: + - stable + - beta + - dev steps: - name: Checkout source code uses: actions/checkout@v4.1.7 diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 03ae187..ece66a0 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -309,7 +309,7 @@ light: lambda: |- for (int i = 0; i < it.size(); i++) { // Generate a random brightness factor between 50% and 100% - float brightness_factor = 0.5 + (esp_random() % 30) / 75.0; + float brightness_factor = 0.5 + (rand() % 30) / 75.0; // Apply brightness to white color (255, 255, 255) for a twinkle effect int white_r = 255 * brightness_factor;