From 694ada07cd10b68c86af7edd7f5cf4b5869f6106 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Wed, 3 Jul 2024 22:56:34 -0400 Subject: [PATCH 01/16] Change To Split YAML --- .github/workflows/ci.yaml | 21 + Integrations/ESPHome/Core.yaml | 609 +++++++++++++++++++++++ Integrations/ESPHome/MSR-2.yaml | 627 +----------------------- Integrations/ESPHome/MSR-2_Factory.yaml | 82 ++++ 4 files changed, 721 insertions(+), 618 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 Integrations/ESPHome/Core.yaml create mode 100644 Integrations/ESPHome/MSR-2_Factory.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..37048b6 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -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_Factory.yaml + - Integrations/ESPHome/MSR-2.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/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml new file mode 100644 index 0000000..b5b2d55 --- /dev/null +++ b/Integrations/ESPHome/Core.yaml @@ -0,0 +1,609 @@ +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;' + + + +# 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 diff --git a/Integrations/ESPHome/MSR-2.yaml b/Integrations/ESPHome/MSR-2.yaml index f149dec..728fe5c 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.4.1" device_description: ${name} made by Apollo Automation - version ${version}. esphome: @@ -41,7 +41,6 @@ dashboard_import: package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2.yaml import_full_config: false - ota: - platform: esphome id: ota_default @@ -59,71 +58,9 @@ update: name: Firmware Update source: https://apolloautomation.github.io/MSR-2/artifact/manifest.json - -logger: - -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;' - +safe_mode: wifi: - power_save_mode: none # Enable fallback hotspot (captive portal) in case wifi connection fails ap: @@ -131,556 +68,10 @@ wifi: 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 +packages: + remote_package: + url: https://github.com/ApolloAutomation/MSR-2/ + ref: main + files: + - Integrations/ESPHome/Core.yaml + refresh: 0d \ No newline at end of file diff --git a/Integrations/ESPHome/MSR-2_Factory.yaml b/Integrations/ESPHome/MSR-2_Factory.yaml new file mode 100644 index 0000000..b3d6a7b --- /dev/null +++ b/Integrations/ESPHome/MSR-2_Factory.yaml @@ -0,0 +1,82 @@ +#Define Project +substitutions: + name: apollo-msr-2 + version: "24.7.4.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 + +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 + +safe_mode: + +improv_serial: + +esp32_improv: + authorizer: none + +wifi: + + # Enable fallback hotspot (captive portal) in case wifi connection fails + ap: + ssid: "Apollo MSR2 Hotspot" + +captive_portal: + +packages: + remote_package: + url: github://ApolloAutomation/MSR-2/ + ref: main + files: + - Integrations/ESPHome/Core.yaml + refresh: 0d \ No newline at end of file From fd1336c96887bb7fc91110a4ee0abba142e5021a Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Wed, 3 Jul 2024 23:24:30 -0400 Subject: [PATCH 02/16] Add Logger Needed --- .github/workflows/build.yml | 4 +-- .github/workflows/main.yml | 33 ------------------------- Integrations/ESPHome/Core.yaml | 6 ----- Integrations/ESPHome/MSR-2.yaml | 2 -- Integrations/ESPHome/MSR-2_Factory.yaml | 10 +++----- 5 files changed, 6 insertions(+), 49 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6fe9d49..0776714 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,14 +23,14 @@ jobs: uses: esphome/build-action@v3.0.0 id: esphome-build with: - yaml_file: Integrations/ESPHome/${{ env.UPPERCASE_DEVICE_NAME }}.yaml + yaml_file: Integrations/ESPHome/${{ env.UPPERCASE_DEVICE_NAME }}_Factory.yaml version: 'latest' cache: true - name: Read version from YAML file id: read_version run: | - version=$(awk '/substitutions:/ {found=1} found && /version:/ {print $2; exit}' Integrations/ESPHome/${{ env.UPPERCASE_DEVICE_NAME }}.yaml | tr -d '"') + version=$(awk '/substitutions:/ {found=1} found && /version:/ {print $2; exit}' Integrations/ESPHome/${{ env.UPPERCASE_DEVICE_NAME }}_Factory.yaml | tr -d '"') echo "project_version=$version" >> $GITHUB_ENV - name: Move generated files to output 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/Core.yaml b/Integrations/ESPHome/Core.yaml index b5b2d55..642370f 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -297,8 +297,6 @@ binary_sensor: ld2410: id: ld2410_radar - - sensor: - platform: internal_temperature name: "ESP Temperature" @@ -309,7 +307,6 @@ sensor: id: sys_uptime update_interval: 60s - - platform: wifi_signal name: RSSI id: wifi_signal_db @@ -327,7 +324,6 @@ sensor: i2c_id: bus_a ambient_pressure_compensation_source: dps310pressure - - platform: ld2410 moving_distance: name: Radar Moving Distance @@ -407,7 +403,6 @@ sensor: still_energy: name: g8 still energy state_class: measurement - - platform: ltr390 id: ltr_390 @@ -455,7 +450,6 @@ light: update_interval: 100ms min_brightness: 50% max_brightness: 100% - button: - platform: restart diff --git a/Integrations/ESPHome/MSR-2.yaml b/Integrations/ESPHome/MSR-2.yaml index 728fe5c..cec5a9c 100644 --- a/Integrations/ESPHome/MSR-2.yaml +++ b/Integrations/ESPHome/MSR-2.yaml @@ -61,8 +61,6 @@ update: safe_mode: wifi: - - # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "Apollo MSR2 Hotspot" diff --git a/Integrations/ESPHome/MSR-2_Factory.yaml b/Integrations/ESPHome/MSR-2_Factory.yaml index b3d6a7b..48350e3 100644 --- a/Integrations/ESPHome/MSR-2_Factory.yaml +++ b/Integrations/ESPHome/MSR-2_Factory.yaml @@ -1,4 +1,3 @@ -#Define Project substitutions: name: apollo-msr-2 version: "24.7.4.1" @@ -11,7 +10,6 @@ esphome: name_add_mac_suffix: true platformio_options: board_build.flash_mode: dio - on_boot: - priority: 900.0 then: @@ -31,7 +29,6 @@ esphome: min_version: 2024.6.0 -# Define Board esp32: board: esp32-c3-devkitm-1 framework: @@ -66,16 +63,17 @@ esp32_improv: authorizer: none wifi: - - # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "Apollo MSR2 Hotspot" captive_portal: +logger: + level: WARN + packages: remote_package: - url: github://ApolloAutomation/MSR-2/ + url: https://github.com/ApolloAutomation/MSR-2/ ref: main files: - Integrations/ESPHome/Core.yaml From f5f8b56b3efa93a9ad01e1742a7ab92b3c873ab6 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Thu, 4 Jul 2024 00:05:50 -0400 Subject: [PATCH 03/16] Fix Action --- .github/workflows/{ci.yaml => ci.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{ci.yaml => ci.yml} (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yml similarity index 100% rename from .github/workflows/ci.yaml rename to .github/workflows/ci.yml From 76326f72fe1cada4f4b6cd6f1cf7e2d2ccc2b9da Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Thu, 4 Jul 2024 00:20:49 -0400 Subject: [PATCH 04/16] Move More To Core --- Integrations/ESPHome/Core.yaml | 25 +++++++++++++++++++++ Integrations/ESPHome/MSR-2.yaml | 27 +---------------------- Integrations/ESPHome/MSR-2_Factory.yaml | 29 ++----------------------- 3 files changed, 28 insertions(+), 53 deletions(-) diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 642370f..13403af 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -1,3 +1,28 @@ +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 + +safe_mode: + +wifi: + ap: + ssid: "Apollo MSR2 Hotspot" + +captive_portal: + globals: - id: button_press_timestamp restore_value: no diff --git a/Integrations/ESPHome/MSR-2.yaml b/Integrations/ESPHome/MSR-2.yaml index cec5a9c..43d1be9 100644 --- a/Integrations/ESPHome/MSR-2.yaml +++ b/Integrations/ESPHome/MSR-2.yaml @@ -41,35 +41,10 @@ dashboard_import: package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2.yaml 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 - -safe_mode: - -wifi: - ap: - ssid: "Apollo MSR2 Hotspot" - -captive_portal: - packages: remote_package: url: https://github.com/ApolloAutomation/MSR-2/ - ref: main + ref: SplitYaml files: - Integrations/ESPHome/Core.yaml refresh: 0d \ No newline at end of file diff --git a/Integrations/ESPHome/MSR-2_Factory.yaml b/Integrations/ESPHome/MSR-2_Factory.yaml index 48350e3..5f28d21 100644 --- a/Integrations/ESPHome/MSR-2_Factory.yaml +++ b/Integrations/ESPHome/MSR-2_Factory.yaml @@ -38,43 +38,18 @@ dashboard_import: package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2.yaml 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 - -safe_mode: - improv_serial: esp32_improv: authorizer: none -wifi: - ap: - ssid: "Apollo MSR2 Hotspot" - -captive_portal: - logger: - level: WARN + packages: remote_package: url: https://github.com/ApolloAutomation/MSR-2/ - ref: main + ref: SplitYaml files: - Integrations/ESPHome/Core.yaml refresh: 0d \ No newline at end of file From 2c6e6fddd70e1da2569d45f20bde075c175115f7 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Thu, 4 Jul 2024 00:28:54 -0400 Subject: [PATCH 05/16] Add BLE Proxy YAML For Test --- .github/workflows/ci.yml | 1 + Integrations/ESPHome/MSR-2_ble.yaml | 53 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Integrations/ESPHome/MSR-2_ble.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37048b6..0fd2f1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,7 @@ jobs: file: - Integrations/ESPHome/MSR-2_Factory.yaml - Integrations/ESPHome/MSR-2.yaml + - Integrations/ESPHome/MSR-2_ble.yaml steps: - name: Checkout source code uses: actions/checkout@v4.1.7 diff --git a/Integrations/ESPHome/MSR-2_ble.yaml b/Integrations/ESPHome/MSR-2_ble.yaml new file mode 100644 index 0000000..c78615e --- /dev/null +++ b/Integrations/ESPHome/MSR-2_ble.yaml @@ -0,0 +1,53 @@ +#Define Project +substitutions: + name: apollo-msr-2 + version: "24.7.4.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 + +bluetooth_proxy: + active: true + +# 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 + +packages: + remote_package: + url: https://github.com/ApolloAutomation/MSR-2/ + ref: SplitYaml + files: + - Integrations/ESPHome/Core.yaml + refresh: 0d \ No newline at end of file From 2238504d7baacedb1c4444972ed888ad08234b08 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Fri, 5 Jul 2024 20:00:12 -0400 Subject: [PATCH 06/16] Move Update Only To Factory --- .github/workflows/ci.yml | 2 +- Integrations/ESPHome/Core.yaml | 22 +- Integrations/ESPHome/MSR-2.yaml | 636 +++++++++++++++++++++++- Integrations/ESPHome/MSR-2_Factory.yaml | 22 +- 4 files changed, 653 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0fd2f1f..92b1f7c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: file: - Integrations/ESPHome/MSR-2_Factory.yaml - Integrations/ESPHome/MSR-2.yaml - - Integrations/ESPHome/MSR-2_ble.yaml + - Integrations/ESPHome/MSR-2_BLE.yaml steps: - name: Checkout source code uses: actions/checkout@v4.1.7 diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 13403af..a46099a 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -1,28 +1,12 @@ -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 - -safe_mode: - wifi: ap: ssid: "Apollo MSR2 Hotspot" captive_portal: +web_server: + port: 80 + globals: - id: button_press_timestamp restore_value: no diff --git a/Integrations/ESPHome/MSR-2.yaml b/Integrations/ESPHome/MSR-2.yaml index 43d1be9..e44264a 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.4.1" + version: "24.7.5.1" device_description: ${name} made by Apollo Automation - version ${version}. esphome: @@ -41,10 +41,630 @@ dashboard_import: package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2.yaml import_full_config: false -packages: - remote_package: - url: https://github.com/ApolloAutomation/MSR-2/ - ref: SplitYaml - files: - - Integrations/ESPHome/Core.yaml - refresh: 0d \ No newline at end of file +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 + +wifi: + + power_save_mode: none + + # Enable fallback hotspot (captive portal) in case wifi connection fails + 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 diff --git a/Integrations/ESPHome/MSR-2_Factory.yaml b/Integrations/ESPHome/MSR-2_Factory.yaml index 5f28d21..c2867d5 100644 --- a/Integrations/ESPHome/MSR-2_Factory.yaml +++ b/Integrations/ESPHome/MSR-2_Factory.yaml @@ -1,6 +1,6 @@ substitutions: name: apollo-msr-2 - version: "24.7.4.1" + version: "24.7.5.2" device_description: ${name} made by Apollo Automation - version ${version}. esphome: @@ -38,6 +38,26 @@ dashboard_import: package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2.yaml 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: true + +update: + - platform: http_request + id: firmware_update + name: Firmware Update + source: https://apolloautomation.github.io/MSR-2/artifact/manifest.json + + +safe_mode: + improv_serial: esp32_improv: From 0b32961ecd3f62f6f637ce949b4db084af1ad898 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Fri, 5 Jul 2024 20:02:27 -0400 Subject: [PATCH 07/16] Updated Version --- Integrations/ESPHome/MSR-2.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Integrations/ESPHome/MSR-2.yaml b/Integrations/ESPHome/MSR-2.yaml index e44264a..ae2ba75 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.5.1" + version: "24.7.5.2" device_description: ${name} made by Apollo Automation - version ${version}. esphome: From 4ccd5f1970aa1dd9fa7fadbe59ac792797f7c966 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Sat, 6 Jul 2024 13:36:26 -0400 Subject: [PATCH 08/16] Remove OTA Update System --- Integrations/ESPHome/MSR-2_Factory.yaml | 21 +-------------------- Integrations/ESPHome/MSR-2_ble.yaml | 22 ++++++++++++++++++---- PULL_REQUEST_TEMPLATE.md | 2 +- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/Integrations/ESPHome/MSR-2_Factory.yaml b/Integrations/ESPHome/MSR-2_Factory.yaml index c2867d5..6f2fa71 100644 --- a/Integrations/ESPHome/MSR-2_Factory.yaml +++ b/Integrations/ESPHome/MSR-2_Factory.yaml @@ -35,28 +35,9 @@ esp32: type: esp-idf dashboard_import: - package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2.yaml + package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2_Factory.yaml 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: true - -update: - - platform: http_request - id: firmware_update - name: Firmware Update - source: https://apolloautomation.github.io/MSR-2/artifact/manifest.json - - -safe_mode: improv_serial: diff --git a/Integrations/ESPHome/MSR-2_ble.yaml b/Integrations/ESPHome/MSR-2_ble.yaml index c78615e..85a9950 100644 --- a/Integrations/ESPHome/MSR-2_ble.yaml +++ b/Integrations/ESPHome/MSR-2_ble.yaml @@ -1,7 +1,7 @@ #Define Project substitutions: name: apollo-msr-2 - version: "24.7.4.1" + version: "24.7.5.1" device_description: ${name} made by Apollo Automation - version ${version}. esphome: @@ -31,9 +31,6 @@ esphome: min_version: 2024.6.0 -bluetooth_proxy: - active: true - # Define Board esp32: board: esp32-c3-devkitm-1 @@ -44,6 +41,23 @@ dashboard_import: package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2.yaml import_full_config: false + +ota: + - platform: esphome + id: ota_default + +bluetooth_proxy: + active: true + +wifi: + ap: + ssid: "Apollo MSR2 Hotspot" + +captive_portal: + +web_server: + port: 80 + packages: remote_package: url: https://github.com/ApolloAutomation/MSR-2/ diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 1a66c6a..7ac6365 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -10,4 +10,4 @@ Breaks: Checks: - [ ] Documentation Updated -- [ ] Build Number Incremented In AIR-1.yaml \ No newline at end of file +- [ ] Build Number Incremented In YAML (YY-MM-DD-#) \ No newline at end of file From 4e7761ef4500691975da77ab484bf639d571215c Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Sat, 6 Jul 2024 14:36:22 -0400 Subject: [PATCH 09/16] BLE --- Integrations/ESPHome/MSR-2_ble.yaml | 617 +++++++++++++++++++++++++++- 1 file changed, 610 insertions(+), 7 deletions(-) diff --git a/Integrations/ESPHome/MSR-2_ble.yaml b/Integrations/ESPHome/MSR-2_ble.yaml index 85a9950..9f1af46 100644 --- a/Integrations/ESPHome/MSR-2_ble.yaml +++ b/Integrations/ESPHome/MSR-2_ble.yaml @@ -42,6 +42,65 @@ dashboard_import: 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 @@ -58,10 +117,554 @@ captive_portal: web_server: port: 80 -packages: - remote_package: - url: https://github.com/ApolloAutomation/MSR-2/ - ref: SplitYaml - files: - - Integrations/ESPHome/Core.yaml - refresh: 0d \ No newline at end of file + + +# 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 From 3a27f0572d016f690ffa964b85234be01d7944c7 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer <24777085+TrevorSchirmer@users.noreply.github.com> Date: Sat, 6 Jul 2024 14:38:36 -0400 Subject: [PATCH 10/16] Delete Integrations/ESPHome/MSR-2_ble.yaml --- Integrations/ESPHome/MSR-2_ble.yaml | 670 ---------------------------- 1 file changed, 670 deletions(-) delete mode 100644 Integrations/ESPHome/MSR-2_ble.yaml diff --git a/Integrations/ESPHome/MSR-2_ble.yaml b/Integrations/ESPHome/MSR-2_ble.yaml deleted file mode 100644 index 9f1af46..0000000 --- a/Integrations/ESPHome/MSR-2_ble.yaml +++ /dev/null @@ -1,670 +0,0 @@ -#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 From c7d79e50d47809888ef16bb9aa9b9ffb386d500a Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Sat, 6 Jul 2024 18:12:44 -0400 Subject: [PATCH 11/16] Add Back OTA To Factory --- Integrations/ESPHome/MSR-2.yaml | 2 +- Integrations/ESPHome/MSR-2_BLE.yaml | 634 +----------------------- Integrations/ESPHome/MSR-2_Factory.yaml | 22 +- 3 files changed, 28 insertions(+), 630 deletions(-) diff --git a/Integrations/ESPHome/MSR-2.yaml b/Integrations/ESPHome/MSR-2.yaml index ae2ba75..e44264a 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.5.2" + version: "24.7.5.1" device_description: ${name} made by Apollo Automation - version ${version}. esphome: diff --git a/Integrations/ESPHome/MSR-2_BLE.yaml b/Integrations/ESPHome/MSR-2_BLE.yaml index 9f1af46..d02cef8 100644 --- a/Integrations/ESPHome/MSR-2_BLE.yaml +++ b/Integrations/ESPHome/MSR-2_BLE.yaml @@ -40,631 +40,11 @@ esp32: 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 +packages: + remote_package: + url: https://github.com/ApolloAutomation/MSR-2/ + ref: SplitYaml + files: + - Integrations/ESPHome/Core.yaml + refresh: 0d \ No newline at end of file diff --git a/Integrations/ESPHome/MSR-2_Factory.yaml b/Integrations/ESPHome/MSR-2_Factory.yaml index 6f2fa71..48c23a2 100644 --- a/Integrations/ESPHome/MSR-2_Factory.yaml +++ b/Integrations/ESPHome/MSR-2_Factory.yaml @@ -1,6 +1,6 @@ substitutions: name: apollo-msr-2 - version: "24.7.5.2" + version: "24.7.6.1" device_description: ${name} made by Apollo Automation - version ${version}. esphome: @@ -27,7 +27,7 @@ esphome: name: "ApolloAutomation.MSR-2" version: "${version}" - min_version: 2024.6.0 + min_version: 2024.6.4 esp32: board: esp32-c3-devkitm-1 @@ -46,6 +46,24 @@ esp32_improv: logger: +ota: + - platform: esphome + id: ota_esphome + - platform: http_request + id: ota_managed + +http_request: + verify_ssl: true + +update: + - platform: http_request + id: firmware_update + name: Firmware Update + source: https://apolloautomation.github.io/MSR-2/artifact/manifest.json + + +safe_mode: + packages: remote_package: From 17ed7a1fab487a82be485266b09edd01d5f2ed36 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Sat, 6 Jul 2024 19:18:18 -0400 Subject: [PATCH 12/16] Add BLE Safety --- Integrations/ESPHome/Core.yaml | 3 --- Integrations/ESPHome/MSR-2_BLE.yaml | 7 ++++++- Integrations/ESPHome/MSR-2_Factory.yaml | 11 ++++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index a46099a..90e7471 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -1,6 +1,3 @@ -wifi: - ap: - ssid: "Apollo MSR2 Hotspot" captive_portal: diff --git a/Integrations/ESPHome/MSR-2_BLE.yaml b/Integrations/ESPHome/MSR-2_BLE.yaml index d02cef8..ef7052d 100644 --- a/Integrations/ESPHome/MSR-2_BLE.yaml +++ b/Integrations/ESPHome/MSR-2_BLE.yaml @@ -40,7 +40,12 @@ esp32: dashboard_import: package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2.yaml import_full_config: false - + +wifi: + ap: + ssid: "Apollo MSR2 Hotspot" + + packages: remote_package: url: https://github.com/ApolloAutomation/MSR-2/ diff --git a/Integrations/ESPHome/MSR-2_Factory.yaml b/Integrations/ESPHome/MSR-2_Factory.yaml index 48c23a2..fbd1adb 100644 --- a/Integrations/ESPHome/MSR-2_Factory.yaml +++ b/Integrations/ESPHome/MSR-2_Factory.yaml @@ -1,6 +1,6 @@ substitutions: name: apollo-msr-2 - version: "24.7.6.1" + version: "24.7.6.2" device_description: ${name} made by Apollo Automation - version ${version}. esphome: @@ -44,6 +44,15 @@ improv_serial: esp32_improv: authorizer: none +wifi: + on_connect: + - delay: 5s # Gives time for improv results to be transmitted + - ble.disable: + on_disconnect: + - ble.enable: + ap: + ssid: "Apollo MSR2 Hotspot" + logger: ota: From 47216c183a2ecbaa062866c5bb1f6ba4f219becc Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Sat, 6 Jul 2024 19:44:04 -0400 Subject: [PATCH 13/16] Cleanup --- Integrations/ESPHome/Core.yaml | 9 +++++++++ Integrations/ESPHome/MSR-2_BLE.yaml | 13 +++++-------- Integrations/ESPHome/MSR-2_Factory.yaml | 11 +---------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 90e7471..8a488c2 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -1,3 +1,12 @@ +substitutions: + name: apollo-msr-2 + version: "24.7.6.2" + device_description: ${name} made by Apollo Automation - version ${version}. + +esp32: + board: esp32-c3-devkitm-1 + framework: + type: esp-idf captive_portal: diff --git a/Integrations/ESPHome/MSR-2_BLE.yaml b/Integrations/ESPHome/MSR-2_BLE.yaml index ef7052d..a80b3b2 100644 --- a/Integrations/ESPHome/MSR-2_BLE.yaml +++ b/Integrations/ESPHome/MSR-2_BLE.yaml @@ -1,4 +1,3 @@ -#Define Project substitutions: name: apollo-msr-2 version: "24.7.5.1" @@ -29,22 +28,20 @@ esphome: name: "ApolloAutomation.MSR-2" version: "${version}" - min_version: 2024.6.0 + min_version: 2024.6.4 -# 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 + package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2_BLE.yaml import_full_config: false wifi: ap: ssid: "Apollo MSR2 Hotspot" +ota: + - platform: esphome + id: ota_esphome packages: remote_package: diff --git a/Integrations/ESPHome/MSR-2_Factory.yaml b/Integrations/ESPHome/MSR-2_Factory.yaml index fbd1adb..84465b6 100644 --- a/Integrations/ESPHome/MSR-2_Factory.yaml +++ b/Integrations/ESPHome/MSR-2_Factory.yaml @@ -1,8 +1,3 @@ -substitutions: - name: apollo-msr-2 - version: "24.7.6.2" - device_description: ${name} made by Apollo Automation - version ${version}. - esphome: name: "${name}" friendly_name: Apollo MSR-2 @@ -29,10 +24,6 @@ esphome: min_version: 2024.6.4 -esp32: - board: esp32-c3-devkitm-1 - framework: - type: esp-idf dashboard_import: package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2_Factory.yaml @@ -46,7 +37,7 @@ esp32_improv: wifi: on_connect: - - delay: 5s # Gives time for improv results to be transmitted + - delay: 5s - ble.disable: on_disconnect: - ble.enable: From 921a2057f784d9a296d6ff1d346e43c48167ecef Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Sat, 6 Jul 2024 21:04:48 -0400 Subject: [PATCH 14/16] Move To Main Branch --- Integrations/ESPHome/MSR-2_BLE.yaml | 7 +------ Integrations/ESPHome/MSR-2_Factory.yaml | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Integrations/ESPHome/MSR-2_BLE.yaml b/Integrations/ESPHome/MSR-2_BLE.yaml index a80b3b2..e5a3a35 100644 --- a/Integrations/ESPHome/MSR-2_BLE.yaml +++ b/Integrations/ESPHome/MSR-2_BLE.yaml @@ -1,8 +1,3 @@ -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 @@ -46,7 +41,7 @@ ota: packages: remote_package: url: https://github.com/ApolloAutomation/MSR-2/ - ref: SplitYaml + ref: main files: - Integrations/ESPHome/Core.yaml refresh: 0d \ No newline at end of file diff --git a/Integrations/ESPHome/MSR-2_Factory.yaml b/Integrations/ESPHome/MSR-2_Factory.yaml index 84465b6..811a8eb 100644 --- a/Integrations/ESPHome/MSR-2_Factory.yaml +++ b/Integrations/ESPHome/MSR-2_Factory.yaml @@ -68,7 +68,7 @@ safe_mode: packages: remote_package: url: https://github.com/ApolloAutomation/MSR-2/ - ref: SplitYaml + ref: main files: - Integrations/ESPHome/Core.yaml refresh: 0d \ No newline at end of file From f6825a8c50497f9998b2df79f373807632fc60ab Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Sat, 6 Jul 2024 22:05:22 -0400 Subject: [PATCH 15/16] Add BLE --- Integrations/ESPHome/MSR-2_BLE.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Integrations/ESPHome/MSR-2_BLE.yaml b/Integrations/ESPHome/MSR-2_BLE.yaml index e5a3a35..d266a57 100644 --- a/Integrations/ESPHome/MSR-2_BLE.yaml +++ b/Integrations/ESPHome/MSR-2_BLE.yaml @@ -38,6 +38,9 @@ ota: - platform: esphome id: ota_esphome +bluetooth_proxy: + active: true + packages: remote_package: url: https://github.com/ApolloAutomation/MSR-2/ From f8e1671d704ece17c20ab4ea52d75c19ca7613f3 Mon Sep 17 00:00:00 2001 From: Trevor Schirmer Date: Mon, 15 Jul 2024 15:30:22 -0400 Subject: [PATCH 16/16] Remove OTA --- .github/workflows/build.yml | 4 ++-- Integrations/ESPHome/Core.yaml | 2 +- Integrations/ESPHome/MSR-2.yaml | 2 +- Integrations/ESPHome/MSR-2_Factory.yaml | 15 +-------------- PULL_REQUEST_TEMPLATE.md | 2 +- README.md | 8 +++++++- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0776714..6fe9d49 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,14 +23,14 @@ jobs: uses: esphome/build-action@v3.0.0 id: esphome-build with: - yaml_file: Integrations/ESPHome/${{ env.UPPERCASE_DEVICE_NAME }}_Factory.yaml + yaml_file: Integrations/ESPHome/${{ env.UPPERCASE_DEVICE_NAME }}.yaml version: 'latest' cache: true - name: Read version from YAML file id: read_version run: | - version=$(awk '/substitutions:/ {found=1} found && /version:/ {print $2; exit}' Integrations/ESPHome/${{ env.UPPERCASE_DEVICE_NAME }}_Factory.yaml | tr -d '"') + version=$(awk '/substitutions:/ {found=1} found && /version:/ {print $2; exit}' Integrations/ESPHome/${{ env.UPPERCASE_DEVICE_NAME }}.yaml | tr -d '"') echo "project_version=$version" >> $GITHUB_ENV - name: Move generated files to output diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 8a488c2..4179718 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -1,6 +1,6 @@ substitutions: name: apollo-msr-2 - version: "24.7.6.2" + version: "24.7.15.1" device_description: ${name} made by Apollo Automation - version ${version}. esp32: diff --git a/Integrations/ESPHome/MSR-2.yaml b/Integrations/ESPHome/MSR-2.yaml index e44264a..5930841 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.5.1" + version: "24.7.15.1" device_description: ${name} made by Apollo Automation - version ${version}. esphome: diff --git a/Integrations/ESPHome/MSR-2_Factory.yaml b/Integrations/ESPHome/MSR-2_Factory.yaml index 811a8eb..1e24b47 100644 --- a/Integrations/ESPHome/MSR-2_Factory.yaml +++ b/Integrations/ESPHome/MSR-2_Factory.yaml @@ -26,7 +26,7 @@ esphome: dashboard_import: - package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2_Factory.yaml + package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2.yaml import_full_config: false @@ -49,20 +49,7 @@ logger: ota: - platform: esphome id: ota_esphome - - platform: http_request - id: ota_managed -http_request: - verify_ssl: true - -update: - - platform: http_request - id: firmware_update - name: Firmware Update - source: https://apolloautomation.github.io/MSR-2/artifact/manifest.json - - -safe_mode: packages: diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 38bff10..ea41a67 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -10,5 +10,5 @@ Breaks: Checks: - [ ] Documentation Updated -- [ ] Build Number Incremented In YAML (YY-MM-DD-#) +- [ ] Build Number Incremented In YAML (YY.MM.DD.#) diff --git a/README.md b/README.md index 8b31e4d..e1f3377 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,13 @@ This sensor offers a wide range of functionality for Home Assistant in a very tiny package. +YAML Files: +- MSR-2.yaml: This file is a minimal config. It doesn't have the bluetooth or OTA components. Use this if you are looking to add BLE proxy or BLE tracking. +- MSR-2_BLE.yaml: This file contains BLE proxy code. We use it as an automated test during our build process. But can be an example for adding BLE proxy to your device. +- MSR-2_Factory.yaml: This is the firmware flashed by us on new devices. It contains the components for ESP improve, allowing easy adoption in Home Assistant. When you load the device in ESPHome addon, it will grab the firmware from MSR-2.yaml which no longer has the improve. + Links: \ Discord (Support/feedback/discussion/future products): [https://discord.gg/8PpS4yUaUh](https://discord.gg/mMNgQPyF94) \ Shop: [https://apolloautomation.com](https://apolloautomation.com/products/msr-2) \ -Wiki: https://wiki.apolloautomation.com +Wiki: https://wiki.apolloautomation.com \ +3D Files: [https://www.printables.com/model/932026-apollo-automation-msr-2-mmwave-co2-multisensor-for](https://www.printables.com/model/932026-apollo-automation-msr-2-mmwave-co2-multisensor-for)