substitutions: version: "26.11.16.1" device_description: ${name} made by Apollo Automation - version ${version}. # Default OTA password. Override in your device YAML by re-declaring # `substitutions: { ota_password: !secret _ota_password }` so each # device on your network uses a unique secret instead of the shared default. # To use encrypted OTA (API noise key) instead of a password, add to your # device YAML: # ota: # - id: !extend ota_default # password: !remove # encryption: ota_password: "apolloautomation" # Manifest URL bases. Stable = GitHub Pages (main branch builds). # Beta = rolling "beta" pre-release assets (beta branch builds). stable_manifest_base: "https://apolloautomation.github.io/MSR-1" beta_manifest_base: "https://github.com/ApolloAutomation/MSR-1/releases/download/beta-fw" # Per-variant OTA manifest URLs. Core defaults to the unified (standard) # image; MSR-1_BLE.yaml overrides these so legacy BLE devices stay on the # firmware-ble manifest. ota_stable_manifest: "${stable_manifest_base}/firmware/manifest.json" ota_beta_manifest: "${beta_manifest_base}/manifest-standard.json" # Bluetooth Proxy switch state on a device with no stored preference yet # (first boot after this switch was added, or after a factory reset). The # unified image ships the proxy off; MSR-1_BLE.yaml overrides this to ON so # legacy BLE devices keep proxying instead of going quiet after an update. bluetooth_proxy_restore_mode: RESTORE_DEFAULT_OFF esphome: # List form so package merging concatenates with each variant's own on_boot # entries (mapping form would be replaced by the variant's block instead). on_boot: - priority: -100 then: - script.execute: apply_ota_source # Re-apply the Bluetooth Proxy switch after all components set up, so BLE # scanning matches the switch state restored from flash. - priority: -300 then: - if: condition: switch.is_on: bluetooth_proxy_switch then: - esp32_ble_tracker.start_scan: continuous: true else: - esp32_ble_tracker.stop_scan: esp32: variant: esp32c3 flash_size: 4MB framework: type: esp-idf esp32_ble_tracker: id: ble_tracker scan_parameters: continuous: true bluetooth_proxy: captive_portal: web_server: port: 80 version: 3 http_request: verify_ssl: true # GitHub release-asset downloads answer with a redirect carrying a # ~3.6 KB Content-Security-Policy header; each header line must fit # this buffer or the request fails with "HTTP_CLIENT: Out of buffer". buffer_size_rx: 5120 # The redirect target is a signed URL with a ~850-char query string; the # follow-up request line must fit the TX buffer or esp_http_client_open # fails with "Out of buffer" before sending anything. buffer_size_tx: 2048 api: encryption: on_client_connected: - delay: 1s - light.turn_off: rgb_light - lambda: 'id(cycleCounter) = 30;' actions: - action: play_buzzer variables: song_str: string then: - rtttl.play: rtttl: !lambda 'return song_str;' #Co2 Calibration Action - action: calibrate_co2_value variables: co2_ppm: float then: - scd4x.perform_forced_calibration: value: !lambda 'return co2_ppm;' id: scd40 #Setting HLK Password - action: set_ld2410_bluetooth_password variables: password: string then: - bluetooth_password.set: id: ld2410_radar password: !lambda 'return password;' globals: - id: cycleCounter type: int restore_value: no initial_value: '0' - id: button_press_timestamp restore_value: no type: uint32_t initial_value: '0' - id: ltr390_last_update restore_value: no type: uint32_t initial_value: '0' - id: runTest restore_value: no type: bool initial_value: "false" - id: testCycleCount type: int restore_value: no initial_value: "0" - id: bme280Passed type: bool restore_value: no initial_value: "false" - id: scd40Passed type: bool restore_value: no initial_value: "false" - id: lightSensorPassed type: bool restore_value: no initial_value: "false" - id: uvIndexPassed type: bool restore_value: no initial_value: "false" - id: ld2410Passed type: bool restore_value: no initial_value: "false" i2c: sda: GPIO1 scl: GPIO0 id: bus_a uart: tx_pin: GPIO21 rx_pin: GPIO20 baud_rate: 256000 parity: NONE stop_bits: 1 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: BME280 Humidity Offset id: bme280_humidity_offset restore_value: true initial_value: -18.86 min_value: -70.0 max_value: 70.0 entity_category: "CONFIG" unit_of_measurement: "%" optimistic: true update_interval: never step: 0.1 mode: box - platform: template name: BME280 Temperature Offset id: bme280_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 - platform: template name: LTR390 Update Interval id: ltr390_update_interval disabled_by_default: true restore_value: true initial_value: 60 min_value: 1 max_value: 300 entity_category: "CONFIG" unit_of_measurement: "s" optimistic: true update_interval: never step: 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: |- bool still_in_zone = id(radar_has_still_target).state && (id(still_distance).state >= id(radar_z1_start).state) && (id(still_distance).state <= id(radar_z1_end).state); bool moving_in_zone = id(radar_has_moving_target).state && (id(moving_distance).state >= id(radar_z1_start).state) && (id(moving_distance).state <= id(radar_z1_end).state); if (still_in_zone || moving_in_zone) { 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: |- bool still_in_zone = id(radar_has_still_target).state && (id(still_distance).state > id(radar_z1_end).state) && (id(still_distance).state <= id(radar_z2_end).state); bool moving_in_zone = id(radar_has_moving_target).state && (id(moving_distance).state > id(radar_z1_end).state) && (id(moving_distance).state <= id(radar_z2_end).state); if (still_in_zone || moving_in_zone) { 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: |- bool still_in_zone = id(radar_has_still_target).state && (id(still_distance).state > id(radar_z2_end).state) && (id(still_distance).state <= id(radar_z3_end).state); bool moving_in_zone = id(radar_has_moving_target).state && (id(moving_distance).state > id(radar_z2_end).state) && (id(moving_distance).state <= id(radar_z3_end).state); if (still_in_zone || moving_in_zone) { return true; } else { return false; } - platform: template name: "Radar Zone Occupancy" id: "radar_zone_occupancy" device_class: occupancy icon: mdi:motion-sensor lambda: |- bool zone1 = id(radar_zone_1_occupancy).state; bool zone2 = id(radar_zone_2_occupancy).state; bool zone3 = id(radar_zone_3_occupancy).state; return zone1 || zone2 || zone3; - 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: # Tap: status + self-test; hold 10 s: factory reset. # 3-10 s does nothing on this mains-powered sensor. - if: condition: lambda: "return millis() - id(button_press_timestamp) >= 10000;" then: - switch.turn_on: factory_reset_switch else: - if: condition: lambda: "return millis() - id(button_press_timestamp) < 3000;" then: # Let the status colour finish before the self-test takes the LED. # YAML waits/delays keep the main loop running (no blocking delay()). - script.execute: statusCheck - script.wait: statusCheck - delay: 3s - lambda: |- id(testCycleCount) = 0; id(runTest) = true; - script.execute: testScript ld2410: id: ld2410_radar sensor: - platform: internal_temperature name: "ESP Temperature" id: sys_esp_temperature filters: - lambda: |- static float last_reported_value = NAN; static uint32_t last_report_time = 0; float current_value = x; // Reduce DB Reporting: report on a meaningful change, but at least hourly so the sensor never looks frozen if (id(reduce_db_reporting).state) { uint32_t now = millis(); bool is_first_publish = last_report_time == 0; bool nan_state_changed = isnan(current_value) != isnan(last_reported_value); if (is_first_publish || nan_state_changed || abs(current_value - last_reported_value) >= 5.0 || (now - last_report_time) >= 3600000UL) { last_reported_value = current_value; last_report_time = now; return current_value; } return {}; // Within delta and under the hourly heartbeat -> discard } else { last_reported_value = current_value; last_report_time = millis(); return current_value; } - 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: bme280pressure - platform: ld2410 moving_distance: name: Radar Moving Distance id: moving_distance filters: - lambda: |- static float last_reported_value = 0.0; float current_value = x; // Check if the radar_has_moving_target sensor is off if (!id(radar_has_moving_target).state) { return NAN; } // Check if the reduce_db_reporting switch is on if (id(reduce_db_reporting).state) { // Apply delta filter: only report if the value has changed by 2 or more if (abs(current_value - last_reported_value) >= 5.0) { last_reported_value = current_value; // Update the last reported value return current_value; } else { // Return the last reported value without updating if change is less than 2 return {}; // Discard the update } } else { // If reduce_db_reporting is off, report the current value normally last_reported_value = current_value; return current_value; } still_distance: name: Radar Still Distance id: still_distance filters: - lambda: |- static float last_reported_value = 0.0; float current_value = x; // Check if the radar_has_still_target sensor is off if (!id(radar_has_still_target).state) { return NAN; } // Check if the reduce_db_reporting switch is on if (id(reduce_db_reporting).state) { // Apply delta filter: only report if the value has changed by 2 or more if (abs(current_value - last_reported_value) >= 5.0) { last_reported_value = current_value; // Update the last reported value return current_value; } else { // Return the last reported value without updating if change is less than 2 return {}; // Discard the update } } else { // If reduce_db_reporting is off, report the current value normally last_reported_value = current_value; return current_value; } moving_energy: name: Radar Move Energy id: radar_moving_energy filters: - lambda: |- if (id(reduce_db_reporting).state) return {}; return x; still_energy: name: Radar Still Energy id: radar_still_energy filters: - lambda: |- if (id(reduce_db_reporting).state) return {}; return x; detection_distance: name: Radar Detection Distance id: radar_detection_distance filters: - lambda: |- static float last_reported_value = 0.0; float current_value = x; // Check if the radar_has_target sensor is off if (!id(radar_has_target).state) { return NAN; } // Check if the reduce_db_reporting switch is on if (id(reduce_db_reporting).state) { // Apply delta filter: only report if the value has changed by 2 or more if (abs(current_value - last_reported_value) >= 5.0) { last_reported_value = current_value; // Update the last reported value return current_value; } else { // Return the last reported value without updating if change is less than 2 return {}; // Discard the update } } else { // If reduce_db_reporting is off, report the current value normally last_reported_value = current_value; return current_value; } g0: move_energy: name: g0 move energy still_energy: name: g0 still energy g1: move_energy: name: g1 move energy still_energy: name: g1 still energy g2: move_energy: name: g2 move energy still_energy: name: g2 still energy g3: move_energy: name: g3 move energy still_energy: name: g3 still energy g4: move_energy: name: g4 move energy still_energy: name: g4 still energy g5: move_energy: name: g5 move energy still_energy: name: g5 still energy g6: move_energy: name: g6 move energy still_energy: name: g6 still energy g7: move_energy: name: g7 move energy still_energy: name: g7 still energy g8: move_energy: name: g8 move energy still_energy: name: g8 still energy - platform: bme280_i2c id: bme_280 temperature: name: "BME280 Temperature" id: bme280temperature filters: - lambda: return x - id(bme280_temperature_offset).state; pressure: name: "BME280 Pressure" id: bme280pressure humidity: name: "BME280 Humidity" id: bme280humidity filters: - lambda: return x - id(bme280_humidity_offset).state; update_interval: 60s i2c_id: bus_a address: 0x76 - platform: ltr390 id: ltr_390 update_interval: never light: name: "LTR390 Light" id: ltr390light filters: - lambda: |- static float last_reported_value = NAN; static uint32_t last_report_time = 0; float current_value = x; // Reduce DB Reporting: report on a meaningful change, but at least hourly so the sensor never looks frozen if (id(reduce_db_reporting).state) { uint32_t now = millis(); bool is_first_publish = last_report_time == 0; bool nan_state_changed = isnan(current_value) != isnan(last_reported_value); if (is_first_publish || nan_state_changed || abs(current_value - last_reported_value) >= 20.0 || (now - last_report_time) >= 3600000UL) { last_reported_value = current_value; last_report_time = now; return current_value; } return {}; // Within delta and under the hourly heartbeat -> discard } else { last_reported_value = current_value; last_report_time = millis(); return current_value; } uv_index: name: "LTR390 UV Index" id: ltr390uvindex filters: - lambda: |- static float last_reported_value = NAN; static uint32_t last_report_time = 0; float current_value = x; // Reduce DB Reporting: report on a meaningful change, but at least hourly so the sensor never looks frozen if (id(reduce_db_reporting).state) { uint32_t now = millis(); bool is_first_publish = last_report_time == 0; bool nan_state_changed = isnan(current_value) != isnan(last_reported_value); if (is_first_publish || nan_state_changed || abs(current_value - last_reported_value) >= 20.0 || (now - last_report_time) >= 3600000UL) { last_reported_value = current_value; last_report_time = now; return current_value; } return {}; // Within delta and under the hourly heartbeat -> discard } else { last_reported_value = current_value; last_report_time = millis(); return current_value; } light: - platform: esp32_rmt_led_strip id: rgb_light name: "RGB Light" pin: GPIO3 default_transition_length: 0s chipset: WS2812 num_leds: 1 rmt_symbols: 48 channel_colors: 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 - platform: template name: "Firmware Update" id: update_firmware icon: mdi:cloud-download entity_category: "config" on_press: - logger.log: "Applying firmware update for the selected channel" - delay: 3s - script.execute: apply_ota_source - script.wait: apply_ota_source # The manifest fetch runs in its own task; give it a fixed window to land # (update.is_available stays false for same-version switches). - delay: 5s - lambda: id(update_http_request).perform(true); switch: - platform: ld2410 bluetooth: name: "Radar Control 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 - platform: template name: "Reduce DB Reporting" id: reduce_db_reporting icon: mdi:database restore_mode: RESTORE_DEFAULT_OFF optimistic: true entity_category: "config" - platform: template name: "Bluetooth Proxy" id: bluetooth_proxy_switch icon: mdi:bluetooth entity_category: "config" restore_mode: ${bluetooth_proxy_restore_mode} optimistic: true on_turn_on: - esp32_ble_tracker.start_scan: continuous: true on_turn_off: - esp32_ble_tracker.stop_scan: text_sensor: - platform: ld2410 version: name: "Radar Firmware Version" - platform: wifi_info ip_address: name: "IP Address" id: wifi_ip entity_category: "diagnostic" - platform: version name: "ESPHome Version" hide_timestamp: true entity_category: "diagnostic" - platform: template name: "Apollo Firmware Version" id: apollo_firmware_version update_interval: never entity_category: "diagnostic" select: - platform: ld2410 distance_resolution: name: "Radar Distance Resolution" disabled_by_default: true - platform: template name: "Firmware Channel" id: firmware_channel icon: mdi:source-branch entity_category: "config" optimistic: true restore_value: true options: - "Stable" - "Beta" initial_option: "Stable" on_value: then: - script.execute: apply_ota_source script: - id: apply_ota_source # Sets the OTA manifest URL from the Firmware Channel select (Stable/Beta). # The manifest base is per-variant (ota_*_manifest substitutions) so legacy # MSR-1_BLE builds keep their firmware-ble manifest. then: - lambda: |- const bool beta = id(firmware_channel).current_option() == "Beta"; const char *url = beta ? "${ota_beta_manifest}" : "${ota_stable_manifest}"; ESP_LOGI("firmware", "OTA manifest set to: %s", url); id(update_http_request).set_source_url(url); - component.update: update_http_request # LED shows connection state for 5 s: blue = connected to Home Assistant, # green = on the network only, yellow = no network. - id: statusCheck then: - if: condition: - lambda: 'return id(ink_ha_connected).state;' then: - logger.log: "Apollo Automation: Connected To HA" - light.turn_on: id: rgb_light brightness: 100% red: 0% green: 0% blue: 100% else: - if: condition: - wifi.connected: then: - logger.log: "Apollo Automation: Connected To Network" - light.turn_on: id: rgb_light brightness: 100% red: 0% green: 100% blue: 0% else: - logger.log: "Apollo Automation: Not Connected To Network" - light.turn_on: id: rgb_light brightness: 100% red: 100% green: 100% blue: 0% - delay: 5s - light.turn_off: rgb_light # Self-test: checks each sensor reports within 5 s, then LED green # (all passed) or red (something failed) for 5 s. - id: testScript then: if: condition: - lambda: "return id(runTest) == true;" then: - lambda: |- id(runTest) = false; id(testCycleCount) = 0; id(bme280Passed) = false; id(scd40Passed) = false; id(lightSensorPassed) = false; id(uvIndexPassed) = false; id(ld2410Passed) = false; - while: condition: - lambda: "return id(testCycleCount) < 5;" then: - lambda: |- if (!id(bme280Passed) && id(bme280pressure).state > 0) id(bme280Passed) = true; if (!id(scd40Passed) && id(co2).state > 0) id(scd40Passed) = true; if (!id(lightSensorPassed) && id(ltr390light).state > 10) id(lightSensorPassed) = true; if (!id(uvIndexPassed) && !isnan(id(ltr390uvindex).state)) id(uvIndexPassed) = true; if (!id(ld2410Passed) && id(radar_has_target).state && id(radar_detection_distance).state > 10) id(ld2410Passed) = true; if (id(bme280Passed) && id(scd40Passed) && id(lightSensorPassed) && id(uvIndexPassed) && id(ld2410Passed)) { id(testCycleCount) = 100; // All passed: end the loop early } - delay: 1s - lambda: "id(testCycleCount) += 1;" #Check If Test Passed To Trigger Lights - if: condition: - lambda: "return id(bme280Passed) && id(scd40Passed) && id(lightSensorPassed) && id(uvIndexPassed) && id(ld2410Passed);" then: - light.turn_on: id: rgb_light red: 0% green: 100% blue: 0% else: - light.turn_on: id: rgb_light red: 100% green: 0% blue: 0% - delay: 5s - light.turn_off: rgb_light #Used To Control RGB Light On Startup. Tells User Status Of Device interval: - interval: 1s then: - if: condition: - binary_sensor.is_off: ink_ha_connected - lambda: 'return id(cycleCounter) < 30;' - switch.is_on: startup_light_blink then: - light.toggle: id: rgb_light - lambda: 'id(cycleCounter) += 1;' - interval: 1s then: - if: condition: - binary_sensor.is_off: ink_ha_connected - lambda: 'return id(cycleCounter) > 30;' - lambda: 'return id(cycleCounter) < 31;' - switch.is_on: startup_light_blink then: - light.turn_off: id: rgb_light - lambda: 'id(cycleCounter) += 1;' - interval: 1s then: - lambda: |- uint32_t current_time = millis() / 1000; // Convert to seconds uint32_t last_update = id(ltr390_last_update); float configured_interval = id(ltr390_update_interval).state; uint32_t interval = (configured_interval >= 1.0f) ? (uint32_t)configured_interval : 60u; // Immediate update on boot (when last_update is still 0) if (last_update == 0) { id(ltr_390).update(); id(ltr390_last_update) = current_time; return; } // Check if enough time has passed if (current_time - last_update >= interval) { id(ltr_390).update(); id(ltr390_last_update) = current_time; }