From 4afd66054e93e40787f4d7f70b07f5f8c868c133 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Fri, 5 Jul 2024 12:34:27 -0400 Subject: [PATCH 1/2] Remove Managed Updates --- .github/workflows/ci.yml | 21 + .github/workflows/main.yml | 33 -- Integrations/ESPHome/MSR-2.yaml | 30 +- Integrations/ESPHome/MSR-2_BLE.yaml | 671 ++++++++++++++++++++++++++++ 4 files changed, 700 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/main.yml create mode 100644 Integrations/ESPHome/MSR-2_BLE.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b41fd7c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,21 @@ +name: CI + +on: + pull_request: + +jobs: + ci: + name: Building ${{ matrix.file }} + runs-on: ubuntu-latest + strategy: + matrix: + file: + - Integrations/ESPHome/MSR-2.yaml + - Integrations/ESPHome/MSR-2_BLE.yaml + steps: + - name: Checkout source code + uses: actions/checkout@v4.1.7 + - name: Build ESPHome firmware to verify configuration + uses: esphome/build-action@v3.1.0 + with: + yaml_file: ${{ matrix.file }} \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 673cfc5..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: 'Discord Publisher' - -on: - workflow_dispatch: - push: - branches: - - main - pull_request: - -permissions: - contents: read - pull-requests: read -concurrency: - group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' - cancel-in-progress: true - -jobs: - check-links: - runs-on: ${{ fromJSON('["ubuntu-latest", "self-hosted"]')[github.repository == 'github/docs-internal'] }} - steps: - - name: Discord Commits - uses: Sniddl/discord-commits@v1.6 - with: - # discord webhook url without /github - webhook: ${{ secrets.DISCORDHOOK }} - # A general message that is displayed for all commits. Defaults to the repo name. - message: 'MSR-2' - # Boolean - Include extra embeds provided from templates. - #include-extras: # optional - # The name of of a premade template. - #template: # optional - # Boolean - only show the last commit. - #last-commit-only: # optional diff --git a/Integrations/ESPHome/MSR-2.yaml b/Integrations/ESPHome/MSR-2.yaml index f149dec..13bb5ef 100644 --- a/Integrations/ESPHome/MSR-2.yaml +++ b/Integrations/ESPHome/MSR-2.yaml @@ -1,7 +1,7 @@ #Define Project substitutions: name: apollo-msr-2 - version: "24.7.3.1" + version: "24.7.5.1" device_description: ${name} made by Apollo Automation - version ${version}. esphome: @@ -42,26 +42,6 @@ dashboard_import: import_full_config: false -ota: - - platform: esphome - id: ota_default - - platform: http_request - id: ota_managed - -http_request: - useragent: esphome/device - timeout: 10s - verify_ssl: false - -update: - - platform: http_request - id: firmware_update - name: Firmware Update - source: https://apolloautomation.github.io/MSR-2/artifact/manifest.json - - -logger: - globals: - id: button_press_timestamp restore_value: no @@ -121,8 +101,12 @@ api: id: ld2410_radar password: !lambda 'return password;' +ota: + - platform: esphome + id: ota_default wifi: + power_save_mode: none # Enable fallback hotspot (captive portal) in case wifi connection fails @@ -381,6 +365,7 @@ sensor: name: "ESP Temperature" id: sys_esp_temperature + - platform: uptime name: Uptime id: sys_uptime @@ -683,4 +668,5 @@ script: green: 0% blue: 0% - light.turn_off: - id: rgb_light \ No newline at end of file + id: rgb_light +No newline at end of file diff --git a/Integrations/ESPHome/MSR-2_BLE.yaml b/Integrations/ESPHome/MSR-2_BLE.yaml new file mode 100644 index 0000000..64ffb1d --- /dev/null +++ b/Integrations/ESPHome/MSR-2_BLE.yaml @@ -0,0 +1,671 @@ +#Define Project +substitutions: + name: apollo-msr-2 + version: "24.7.5.1" + device_description: ${name} made by Apollo Automation - version ${version}. + +esphome: + name: "${name}" + friendly_name: Apollo MSR-2 + comment: Apollo MSR-2 + name_add_mac_suffix: true + platformio_options: + board_build.flash_mode: dio + + on_boot: + - priority: 900.0 + then: + - lambda: |- + id(radar_bluetooth).turn_off(); + - priority: -10 + then: + - if: + condition: + - lambda: "return id(runTest);" + then: + - lambda: "id(testScript).execute();" + + project: + name: "ApolloAutomation.MSR-2" + version: "${version}" + + min_version: 2024.6.0 + +# Define Board +esp32: + board: esp32-c3-devkitm-1 + framework: + type: esp-idf + +dashboard_import: + package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2.yaml + import_full_config: false + + +globals: + - id: button_press_timestamp + restore_value: no + type: uint32_t + initial_value: '0' + - id: runTest + restore_value: yes + type: bool + initial_value: "true" + - id: testCycleCount + type: int + restore_value: no + initial_value: "0" + - id: dps310Passed + restore_value: no + type: bool + initial_value: "false" + - id: ltr390lightPassed + restore_value: no + type: bool + initial_value: "false" + - id: ltr390uvindexPassed + restore_value: no + type: bool + initial_value: "false" + - id: ld2410Passed + restore_value: no + type: bool + initial_value: "false" + +# Enable Home Assistant API +# Also Add Buzzer Service Connection +api: + services: + - service: play_buzzer + variables: + song_str: string + then: + - rtttl.play: + rtttl: !lambda 'return song_str;' + + #Co2 Calibration Service + - service: calibrate_co2_value + variables: + co2_ppm: float + then: + - scd4x.perform_forced_calibration: + value: !lambda 'return co2_ppm;' + id: scd40 + + #Setting HLK Password + - service: set_ld2410_bluetooth_password + variables: + password: string + then: + - bluetooth_password.set: + id: ld2410_radar + password: !lambda 'return password;' + +ota: + - platform: esphome + id: ota_default + +bluetooth_proxy: + active: true + +wifi: + ap: + ssid: "Apollo MSR2 Hotspot" + +captive_portal: + +web_server: + port: 80 + + + +# Set Up Key Ports For Communication +i2c: + sda: GPIO1 + scl: GPIO0 + id: bus_a + +uart: + tx_pin: GPIO21 + rx_pin: GPIO20 + baud_rate: 256000 + parity: NONE + stop_bits: 1 + +# Numbers For Configuration +number: + - platform: ld2410 + timeout: + name: Radar Timeout + max_move_distance_gate: + name: Radar Max Move Distance + max_still_distance_gate: + name: Radar Max Still Distance + g0: + move_threshold: + name: g0 move threshold + still_threshold: + name: g0 still threshold + g1: + move_threshold: + name: g1 move threshold + still_threshold: + name: g1 still threshold + g2: + move_threshold: + name: g2 move threshold + still_threshold: + name: g2 still threshold + g3: + move_threshold: + name: g3 move threshold + still_threshold: + name: g3 still threshold + g4: + move_threshold: + name: g4 move threshold + still_threshold: + name: g4 still threshold + g5: + move_threshold: + name: g5 move threshold + still_threshold: + name: g5 still threshold + g6: + move_threshold: + name: g6 move threshold + still_threshold: + name: g6 still threshold + g7: + move_threshold: + name: g7 move threshold + still_threshold: + name: g7 still threshold + g8: + move_threshold: + name: g8 move threshold + still_threshold: + name: g8 still threshold + + + - platform: template + name: DPS Temperature Offset + id: dps310_temperature_offset + restore_value: true + initial_value: 14.54 + min_value: -70.0 + max_value: 70.0 + entity_category: "CONFIG" + unit_of_measurement: "°C" + optimistic: true + update_interval: never + step: 0.1 + mode: box +# Setting start of zone 1 occupancy + - platform: template + name: "Radar Zone 1 Start" + id: radar_z1_start + device_class: distance + min_value: 0 + max_value: 800 + step: 1 + mode: box + update_interval: never + optimistic: true + restore_value: true + initial_value: 0 + icon: "mdi:arrow-collapse-right" + entity_category: CONFIG + unit_of_measurement: "cm" + + # Setting ending of zone 1 occupancy + - platform: template + name: "Radar End Zone 1" + id: radar_z1_end + device_class: distance + min_value: 0 + max_value: 800 + step: 1 + mode: box + update_interval: never + optimistic: true + restore_value: true + initial_value: 50 + icon: "mdi:arrow-collapse-right" + entity_category: CONFIG + unit_of_measurement: "cm" + + # Setting ending of zone 2 occupancy + - platform: template + name: "Radar End Zone 2" + id: radar_z2_end + device_class: distance + min_value: 0 + max_value: 800 + step: 1 + mode: box + update_interval: never + optimistic: true + restore_value: true + initial_value: 150 + icon: "mdi:arrow-collapse-right" + entity_category: CONFIG + unit_of_measurement: "cm" + + # Setting ending of zone 3 occupancy + - platform: template + name: "Radar End Zone 3" + id: radar_z3_end + device_class: distance + min_value: 0 + max_value: 800 + step: 1 + mode: box + update_interval: never + optimistic: true + restore_value: true + initial_value: 250 + icon: "mdi:arrow-collapse-right" + entity_category: CONFIG + unit_of_measurement: "cm" + +# Buzzer +output: + - platform: ledc + pin: GPIO10 + id: buzzer +rtttl: + output: buzzer + + + +binary_sensor: + - platform: status + name: Online + id: ink_ha_connected + - platform: ld2410 + has_target: + name: Radar Target + id: radar_has_target + has_moving_target: + name: Radar Moving Target + id: radar_has_moving_target + has_still_target: + name: Radar Still Target + id: radar_has_still_target + ## Set Up Radar Zones Based On Distance + - platform: template + name: "Radar Zone 1 Occupancy" + id: radar_zone_1_occupancy + device_class: occupancy + icon: mdi:motion-sensor + lambda: |- + if ((id(radar_has_target).state) && ((id(radar_detection_distance).state < id(radar_z1_end).state) && (id(radar_detection_distance).state > id(radar_z1_start).state))){ + return true; + } else { + return false; + } + - platform: template + name: "Radar Zone 2 Occupancy" + id: radar_zone_2_occupancy + device_class: occupancy + icon: mdi:motion-sensor + lambda: |- + if ((id(radar_has_target).state) && ((id(radar_z1_end).state < id(radar_detection_distance).state) && (id(radar_detection_distance).state < id(radar_z2_end).state))) { + return true; + } else { + return false; + } + - platform: template + name: "Radar Zone 3 Occupancy" + id: radar_zone_3_occupancy + device_class: occupancy + icon: mdi:motion-sensor + lambda: |- + if ((id(radar_has_target).state) && ((id(radar_z2_end).state < id(radar_detection_distance).state) && (id(radar_detection_distance).state < id(radar_z3_end).state))) { + return true; + } else { + return false; + } + - platform: gpio + pin: + number: GPIO9 + inverted: true + ignore_strapping_warning: true + mode: + input: true + pullup: true + id: reset_button + on_press: + then: + - lambda: |- + id(button_press_timestamp) = millis(); + + on_release: + then: + - lambda: |- + if (millis() - id(button_press_timestamp) >= 1000) { + id(testCycleCount) = 0; + id(runTest) = true; + id(testScript).execute(); + } + else if (millis() - id(button_press_timestamp) >= 8000) { + id(factory_reset_switch).turn_on(); + + } + +ld2410: + id: ld2410_radar + + + +sensor: + - platform: internal_temperature + name: "ESP Temperature" + id: sys_esp_temperature + + + - platform: uptime + name: Uptime + id: sys_uptime + update_interval: 60s + + + - platform: wifi_signal + name: RSSI + id: wifi_signal_db + update_interval: 60s + entity_category: "diagnostic" + + - platform: scd4x + id: scd40 + co2: + name: "CO2" + id: "co2" + automatic_self_calibration: false + update_interval: 60s + measurement_mode: "periodic" + i2c_id: bus_a + ambient_pressure_compensation_source: dps310pressure + + + - platform: ld2410 + moving_distance: + name: Radar Moving Distance + id: moving_distance + still_distance: + name: Radar Still Distance + id: still_distance + moving_energy: + name: Radar Move Energy + id: radar_moving_energy + still_energy: + name: Radar Still Energy + id: radar_still_energy + detection_distance: + name: Radar Detection Distance + id: radar_detection_distance + g0: + move_energy: + name: g0 move energy + state_class: measurement + still_energy: + name: g0 still energy + state_class: measurement + g1: + move_energy: + name: g1 move energy + state_class: measurement + still_energy: + name: g1 still energy + state_class: measurement + g2: + move_energy: + name: g2 move energy + state_class: measurement + still_energy: + name: g2 still energy + state_class: measurement + g3: + move_energy: + name: g3 move energy + state_class: measurement + still_energy: + name: g3 still energy + state_class: measurement + g4: + move_energy: + name: g4 move energy + state_class: measurement + still_energy: + name: g4 still energy + state_class: measurement + g5: + move_energy: + name: g5 move energy + state_class: measurement + still_energy: + name: g5 still energy + state_class: measurement + g6: + move_energy: + name: g6 move energy + state_class: measurement + still_energy: + name: g6 still energy + state_class: measurement + g7: + move_energy: + name: g7 move energy + state_class: measurement + still_energy: + name: g7 still energy + state_class: measurement + g8: + move_energy: + name: g8 move energy + state_class: measurement + still_energy: + name: g8 still energy + state_class: measurement + + + - platform: ltr390 + id: ltr_390 + light: + name: "LTR390 Light" + id: ltr390light + uv_index: + name: "LTR390 UV Index" + id: ltr390uvindex + + - platform: dps310 + id: dps_310 + pressure: + name: "DPS310 Pressure" + id: dps310pressure + temperature: + name: "DPS310 Temperature" + id: dps310temperature + filters: + - lambda: return x - id(dps310_temperature_offset).state; + update_interval: 30s + i2c_id: bus_a + + +light: + - platform: esp32_rmt_led_strip + id: rgb_light + name: "RGB Light" + pin: GPIO3 + rmt_channel: 0 + default_transition_length: 0s + chipset: WS2812 + num_leds: 3 + rgb_order: grb + effects: + - pulse: + name: "Slow Pulse" + transition_length: 1000ms + update_interval: 1000ms + min_brightness: 50% + max_brightness: 100% + - pulse: + name: "Fast Pulse" + transition_length: 100ms + update_interval: 100ms + min_brightness: 50% + max_brightness: 100% + + +button: + - platform: restart + icon: mdi:power-cycle + name: "ESP Reboot" + + - platform: factory_reset + disabled_by_default: True + name: "Factory Reset ESP" + id: factory_reset_all + + - platform: ld2410 + factory_reset: + name: "Factory Reset Radar" + restart: + name: "Restart Radar" + query_params: + name: query params + - platform: template + name: "Calibrate SCD40 To 420ppm" + id: set_SCD40_calibrate + on_press: + - scd4x.perform_forced_calibration: + value: 420 + id: scd40 + + +switch: + - platform: ld2410 + bluetooth: + name: "ld2410 Bluetooth" + id: radar_bluetooth + engineering_mode: + name: "Radar Engineering Mode" + - platform: template + name: "Startup Light Blink" + id: startup_light_blink + icon: mdi:lightbulb + restore_mode: RESTORE_DEFAULT_ON + optimistic: true + entity_category: "config" + - platform: factory_reset + id: factory_reset_switch + internal: true + +text_sensor: + - platform: ld2410 + version: + name: "Radar Firmware Version" + +select: + - platform: ld2410 + distance_resolution: + name: "ld2410 Gate Size" + disabled_by_default: true + + + +script: + - id: testScript + then: + if: + condition: + - lambda: "return id(runTest) == true;" + then: + - lambda: "id(runTest) = false;" + - lambda: "id(testCycleCount) = 0;" + - while: + condition: + - lambda: "return id(testCycleCount) < 5;" + then: + - if: + condition: + - lambda: "return id(dps310Passed) == false;" + then: + - if: + condition: + - lambda: "return id(dps310pressure).state > 0;" + then: + - lambda: "id(dps310Passed) = true;" + - if: + condition: + - lambda: "return id(ltr390lightPassed) == false;" + then: + - if: + condition: + - lambda: "return id(ltr390light).state > 10;" + then: + - lambda: "id(ltr390lightPassed) = true;" + - if: + condition: + - lambda: "return id(ltr390uvindexPassed) == false;" + then: + - if: + condition: + - lambda: "return !isnan(id(ltr390uvindex).state);" + then: + - lambda: "id(ltr390uvindexPassed) = true;" + - if: + condition: + - lambda: "return id(ld2410Passed) == false;" + then: + - if: + condition: + - lambda: "return (id(radar_has_target).state == true && id(radar_detection_distance).state > 10);" + then: + - lambda: "id(ld2410Passed) = true;" + - if: + condition: + - lambda: "return id(dps310Passed) && id(ltr390lightPassed) && id(ltr390uvindexPassed) && id(ld2410Passed);" + then: + - lambda: "id(testCycleCount) = 10;" + - lambda: "id(runTest) = false;" + - delay: 1s + - lambda: "id(testCycleCount) += 1;" + + #Check If Test Passed To Trigger Lights + - if: + condition: + - lambda: "return id(dps310Passed) && id(ltr390lightPassed) && id(ltr390uvindexPassed) && id(ld2410Passed);" + then: + - lambda: "id(runTest) = false;" + - light.turn_on: + id: rgb_light + red: 0% + green: 100% + blue: 0% + - delay: 5s + - light.turn_on: + id: rgb_light + red: 0% + green: 0% + blue: 0% + - light.turn_off: + id: rgb_light + + else: + - lambda: "id(runTest) = false;" + - light.turn_on: + id: rgb_light + red: 100% + green: 0% + blue: 0% + - delay: 5s + - light.turn_on: + id: rgb_light + red: 0% + green: 0% + blue: 0% + - light.turn_off: + id: rgb_light +No newline at end of file From b158f15120d1bffa1560bb16bd086956a8ae3564 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Fri, 5 Jul 2024 12:37:38 -0400 Subject: [PATCH 2/2] Remove Paste --- Integrations/ESPHome/MSR-2.yaml | 1 - Integrations/ESPHome/MSR-2_BLE.yaml | 1 - 2 files changed, 2 deletions(-) diff --git a/Integrations/ESPHome/MSR-2.yaml b/Integrations/ESPHome/MSR-2.yaml index 13bb5ef..64bc95c 100644 --- a/Integrations/ESPHome/MSR-2.yaml +++ b/Integrations/ESPHome/MSR-2.yaml @@ -669,4 +669,3 @@ script: blue: 0% - light.turn_off: id: rgb_light -No newline at end of file diff --git a/Integrations/ESPHome/MSR-2_BLE.yaml b/Integrations/ESPHome/MSR-2_BLE.yaml index 64ffb1d..9f1af46 100644 --- a/Integrations/ESPHome/MSR-2_BLE.yaml +++ b/Integrations/ESPHome/MSR-2_BLE.yaml @@ -668,4 +668,3 @@ script: blue: 0% - light.turn_off: id: rgb_light -No newline at end of file