substitutions: version: "26.11.12.1" device_description: TEMP_PRO-1 made by Apollo Automation - version ${version}. esphome: name: temp-pro-1 on_boot: # Publish the firmware version once per boot - priority: 500 then: - text_sensor.template.publish: id: apollo_firmware_version state: "${version}" - priority: -100 then: - delay: 2s - lambda: |- id(deep_sleep_1).set_sleep_duration(id(deep_sleep_sleep_duration).state * 60 * 60 * 1000); - if: condition: or: - binary_sensor.is_on: ota_mode - switch.is_on: prevent_sleep then: - lambda: |- ESP_LOGW("Apollo", "Preventing Deep Sleep Due To OTA Or Switch On Boot"); id(deep_sleep_1).prevent_deep_sleep(); - lambda: |- // Force initial updates on boot id(sht_temperature).publish_state(id(sht_temperature_raw).state); id(sht_humidity).publish_state(id(sht_humidity_raw).state); id(last_temp_update) = millis(); id(last_humidity_update) = millis(); esp32: board: esp32-s3-devkitc-1 variant: esp32s3 flash_size: 8MB framework: type: esp-idf # EXPERIMENTAL: Include custom component for SEN5x particle number concentration external_components: - source: type: local path: local_components - source: github://ApolloAutomation/esphome-battery-component components: [max17048] api: services: - service: play_buzzer variables: song_str: string then: - rtttl.play: rtttl: !lambda 'return song_str;' reboot_timeout: 0s on_client_connected: then: - if: condition: or: - binary_sensor.is_on: ota_mode - switch.is_on: prevent_sleep then: - lambda: |- ESP_LOGW("Apollo", "Preventing Deep Sleep Due To OTA Or Switch"); else: - switch.turn_on: accessory_power - delay: 5s - lambda: |- id(reportAllValues).execute(); - delay: 5s - lambda: |- // Check alarm conditions directly id(alarm_triggered_on_wake) = false; // Check temperature alarm (only if value is valid) if (id(alarm_outside_temp_range).state && !std::isnan(id(sht_temperature).state) && (id(sht_temperature).state > id(max_temp).state || id(sht_temperature).state < id(min_temp).state)) { id(alarm_triggered_on_wake) = true; ESP_LOGW("Apollo", "Temperature alarm triggered"); } // Check humidity alarm (only if value is valid) if (id(alarm_outside_humidity_range).state && !std::isnan(id(sht_humidity).state) && (id(sht_humidity).state > id(max_humidity).state || id(sht_humidity).state < id(min_humidity).state)) { id(alarm_triggered_on_wake) = true; ESP_LOGW("Apollo", "Humidity alarm triggered"); } // Check PM mass alarm (only if value is valid) if (id(alarm_outside_total_pm_range).state && !std::isnan(id(pm_10_0).state) && id(pm_10_0).state >= id(max_total_pm).state) { id(alarm_triggered_on_wake) = true; ESP_LOGW("Apollo", "PM mass alarm triggered"); } // Check PM count alarm (only if value is valid) if (id(alarm_outside_total_pm_count_range).state && !std::isnan(id(total_pm_count).state) && id(total_pm_count).state >= id(max_total_pm_count).state) { id(alarm_triggered_on_wake) = true; ESP_LOGW("Apollo", "PM count alarm triggered: %.0f >= %.0f", id(total_pm_count).state, id(max_total_pm_count).state); } if (id(alarm_triggered_on_wake)) { ESP_LOGW("Apollo", "Alarm Active - Staying Awake"); id(deep_sleep_1).prevent_deep_sleep(); // Trigger alarm sound and light id(rgb_light).turn_on().set_effect("Fast Pulse").perform(); id(rgb_light).turn_on().set_rgb(1, 0, 0).set_transition_length(0).perform(); id(rtttl_buzzer).play("siren:d=8,o=5,b=100:d,e,d,e,d,e,d,e;"); } - if: condition: and: - lambda: 'return !id(alarm_triggered_on_wake);' - switch.is_off: prevent_sleep - binary_sensor.is_off: ota_mode then: - deep_sleep.enter: id: deep_sleep_1 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: alarm_triggered_on_wake type: bool restore_value: no initial_value: 'false' - id: last_temp_update type: uint32_t restore_value: no initial_value: '0' - id: last_humidity_update type: uint32_t restore_value: no initial_value: '0' i2c: sda: GPIO16 scl: GPIO17 id: bus_a web_server: port: 80 deep_sleep: id: deep_sleep_1 sleep_duration: 1h run_duration: 90s one_wire: - platform: gpio pin: GPIO6 uart: - id: uart_ld2412 tx_pin: GPIO39 rx_pin: GPIO40 baud_rate: 115200 parity: NONE stop_bits: 1 ld2412: id: ld2412_radar uart_id: uart_ld2412 # Buzzer output: - platform: ledc pin: GPIO8 id: buzzer rtttl: id: rtttl_buzzer output: buzzer binary_sensor: - platform: status name: Online id: ink_ha_connected disabled_by_default: true - platform: gpio pin: number: GPIO0 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) >= 10000) { // Remove Wifi id(factory_reset_switch).turn_on(); } else { // StatusCheck id(statusCheck).execute(); } - platform: ld2412 dynamic_background_correction_status: name: "LD2412 Dynamic Background Correction Status" id: ld2412_dynamic_background_correction_status disabled_by_default: true has_target: name: "LD2412 Presence" id: ld2412_presence has_moving_target: name: "LD2412 Moving Target" id: ld2412_moving_target disabled_by_default: true has_still_target: name: "LD2412 Still Target" id: ld2412_still_target disabled_by_default: true - platform: template name: Alarm Temperature Within Range id: temp_within_range disabled_by_default: true lambda: 'return std::isnan(id(sht_temperature).state) || ((id(sht_temperature).state <= id(max_temp).state) && (id(sht_temperature).state >= id(min_temp).state));' - platform: template name: Alarm Humidity Within Range id: humidity_within_range disabled_by_default: true lambda: 'return std::isnan(id(sht_humidity).state) || ((id(sht_humidity).state <= id(max_humidity).state) && (id(sht_humidity).state >= id(min_humidity).state));' - platform: template name: Alarm Total PM Within Range id: total_pm_within_range disabled_by_default: true lambda: 'return std::isnan(id(pm_10_0).state) || (id(pm_10_0).state < id(max_total_pm).state);' - platform: template name: Alarm Total PM Count Within Range id: total_pm_count_within_range disabled_by_default: true lambda: 'return std::isnan(id(total_pm_count).state) || (id(total_pm_count).state < id(max_total_pm_count).state);' - platform: template name: Alarm Active id: alarm_active disabled_by_default: true lambda: 'return (id(alarm_outside_temp_range).state && !id(temp_within_range).state) || (id(alarm_outside_humidity_range).state && !id(humidity_within_range).state) || (id(alarm_outside_total_pm_range).state && !id(total_pm_within_range).state) || (id(alarm_outside_total_pm_count_range).state && !id(total_pm_count_within_range).state);' on_release: then: - light.turn_off: rgb_light - if: condition: and: - switch.is_off: prevent_sleep - binary_sensor.is_off: ota_mode then: - lambda: |- ESP_LOGW("Apollo", "Alarm cleared - going back to sleep"); id(deep_sleep_1).allow_deep_sleep(); - delay: 2s - deep_sleep.enter: id: deep_sleep_1 - platform: homeassistant name: "OTA Mode" id: ota_mode entity_id: input_boolean.apollo_ota_mode disabled_by_default: true on_press: then: - lambda: |- id(deep_sleep_1).prevent_deep_sleep(); on_release: then: - if: condition: switch.is_off: prevent_sleep then: - lambda: |- id(deep_sleep_1).allow_deep_sleep(); sensor: - platform: internal_temperature name: "ESP Temperature" id: sys_esp_temperature disabled_by_default: true - platform: uptime name: Uptime id: sys_uptime update_interval: 60s disabled_by_default: true - platform: sht3xd id: sht3xd_sensor temperature: name: "Temperature Raw" id: sht_temperature_raw internal: true humidity: name: "Relative Humidity Raw" id: sht_humidity_raw internal: true update_interval: 10s # Template sensors with configurable intervals - platform: template name: "Temperature" id: sht_temperature lambda: 'return id(sht_temperature_raw).state;' unit_of_measurement: "°C" device_class: temperature state_class: measurement accuracy_decimals: 1 update_interval: never - platform: template name: "Relative Humidity" id: sht_humidity lambda: 'return id(sht_humidity_raw).state;' unit_of_measurement: "%" device_class: humidity state_class: measurement accuracy_decimals: 1 update_interval: never - platform: sen5x id: sen55 pm_1_0: name: "PM <1µm Weight concentration" id: pm_1_0 disabled_by_default: true accuracy_decimals: 1 filters: - sliding_window_moving_average: window_size: 9 send_every: 1 pm_2_5: name: "PM <2.5µm Weight concentration" id: pm_2_5 disabled_by_default: true accuracy_decimals: 1 filters: - sliding_window_moving_average: window_size: 9 send_every: 1 pm_4_0: name: "PM <4µm Weight concentration" id: pm_4_0 disabled_by_default: true accuracy_decimals: 1 pm_10_0: name: "PM <10µm Weight concentration" id: pm_10_0 accuracy_decimals: 1 nox: name: "NOX Index" id: sen_nox disabled_by_default: true accuracy_decimals: 1 voc: name: "VOC Index" id: sen_voc disabled_by_default: true algorithm_tuning: index_offset: 100 learning_time_offset_hours: 12 learning_time_gain_hours: 12 gating_max_duration_minutes: 180 std_initial: 50 gain_factor: 230 filters: - sliding_window_moving_average: window_size: 9 send_every: 1 temperature_compensation: offset: 0 normalized_offset_slope: 0 time_constant: 0 store_baseline: true update_interval: 10s - platform: template name: "PM 0.3 To 1 µm" id: pm0_3_to_1 disabled_by_default: true lambda: return id(pm_1_0).state; unit_of_measurement: "µg/m³" state_class: measurement icon: mdi:air-filter update_interval: 10s - platform: template name: "PM 1 To 2.5 µm" id: pm1_to_2_5 disabled_by_default: true lambda: return std::max(0.0f, id(pm_2_5).state - id(pm_1_0).state); unit_of_measurement: "µg/m³" state_class: measurement icon: mdi:air-filter update_interval: 10s - platform: template name: "PM 2.5 To 4 µm" id: pm2_5_to_4 disabled_by_default: true lambda: return std::max(0.0f, id(pm_4_0).state - id(pm_2_5).state); unit_of_measurement: "µg/m³" state_class: measurement icon: mdi:air-filter update_interval: 10s - platform: template name: "PM 4 To 10 µm" id: pm4_to_10 disabled_by_default: true lambda: return std::max(0.0f, id(pm_10_0).state - id(pm_4_0).state); unit_of_measurement: "µg/m³" state_class: measurement icon: mdi:air-filter update_interval: 10s # EXPERIMENTAL: SEN5x Particle Number Concentration Sensors # Uses undocumented I2C command 0x0413 # Reference: Sensirion_SEN5x_Read_Mass_and_Number_Concentrations.pdf - platform: sen5x_number id: sen5x_number_component address: 0x69 update_interval: 10s pm_0_5_number: name: "PM <0.5µm Number concentration" id: pm_0_5_number accuracy_decimals: 0 disabled_by_default: true pm_1_0_number: name: "PM <1µm Number concentration" id: pm_1_0_number accuracy_decimals: 0 disabled_by_default: true pm_2_5_number: name: "PM <2.5µm Number concentration" id: pm_2_5_number accuracy_decimals: 0 disabled_by_default: true pm_4_0_number: name: "PM <4µm Number concentration" id: pm_4_0_number accuracy_decimals: 0 disabled_by_default: true pm_10_0_number: name: "PM <10µm Number concentration" id: pm_10_0_number accuracy_decimals: 0 disabled_by_default: true typical_particle_size: name: "PM Typical Particle Size" id: typical_particle_size accuracy_decimals: 2 disabled_by_default: true # Particle number concentration ranges (EXPERIMENTAL) - platform: template name: "PM 0.3 To 0.5 µm Number" id: pm0_3_to_0_5_number disabled_by_default: true lambda: return id(pm_0_5_number).state; unit_of_measurement: "#/m³" state_class: measurement icon: mdi:air-filter update_interval: 10s accuracy_decimals: 0 - platform: template name: "PM 0.5 To 1 µm Number" id: pm0_5_to_1_number disabled_by_default: true lambda: return std::max(0.0f, id(pm_1_0_number).state - id(pm_0_5_number).state); unit_of_measurement: "#/m³" state_class: measurement icon: mdi:air-filter update_interval: 10s accuracy_decimals: 0 - platform: template name: "PM 1 To 2.5 µm Number" id: pm1_to_2_5_number disabled_by_default: true lambda: return std::max(0.0f, id(pm_2_5_number).state - id(pm_1_0_number).state); unit_of_measurement: "#/m³" state_class: measurement icon: mdi:air-filter update_interval: 10s accuracy_decimals: 0 - platform: template name: "PM 2.5 To 4 µm Number" id: pm2_5_to_4_number disabled_by_default: true lambda: return std::max(0.0f, id(pm_4_0_number).state - id(pm_2_5_number).state); unit_of_measurement: "#/m³" state_class: measurement icon: mdi:air-filter update_interval: 10s accuracy_decimals: 0 - platform: template name: "PM 4 To 10 µm Number" id: pm4_to_10_number disabled_by_default: true lambda: return std::max(0.0f, id(pm_10_0_number).state - id(pm_4_0_number).state); unit_of_measurement: "#/m³" state_class: measurement icon: mdi:air-filter update_interval: 10s accuracy_decimals: 0 - platform: template name: "PM Total Count" id: total_pm_count disabled_by_default: true lambda: |- return id(pm0_3_to_0_5_number).state + id(pm0_5_to_1_number).state + id(pm1_to_2_5_number).state + id(pm2_5_to_4_number).state + id(pm4_to_10_number).state; unit_of_measurement: "#/m³" state_class: measurement icon: mdi:air-filter update_interval: 10s accuracy_decimals: 0 # Dallas probes: up to 4 via the 3.5mm splitter (probes 2-4 disabled by default) - platform: dallas_temp name: "Temperature Probe (Dallas)" id: dallas_temp_probe index: 0 update_interval: 60s - platform: dallas_temp name: "Temperature Probe 2 (Dallas)" id: dallas_temp_probe_2 index: 1 update_interval: 60s disabled_by_default: true - platform: dallas_temp name: "Temperature Probe 3 (Dallas)" id: dallas_temp_probe_3 index: 2 update_interval: 60s disabled_by_default: true - platform: dallas_temp name: "Temperature Probe 4 (Dallas)" id: dallas_temp_probe_4 index: 3 update_interval: 60s disabled_by_default: true - platform: ld2412 light: name: LD2412 Light id: ld2412_light disabled_by_default: true moving_distance: name: LD2412 Moving Distance id: ld2412_moving_distance disabled_by_default: true filters: - throttle: 500ms still_distance: name: LD2412 Still Distance id: ld2412_still_distance disabled_by_default: true filters: - throttle: 500ms moving_energy: name: LD2412 Move Energy id: ld2412_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 Still Energy id: ld2412_still_energy disabled_by_default: true filters: - throttle: 500ms detection_distance: name: LD2412 Detection Distance id: ld2412_detection_distance disabled_by_default: true filters: - throttle: 500ms gate_0: move_energy: name: LD2412 g00 move energy id: ld2412_g00_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g00 still energy id: ld2412_g00_still_energy disabled_by_default: true filters: - throttle: 500ms gate_1: move_energy: name: LD2412 g01 move energy id: ld2412_g01_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g01 still energy id: ld2412_g01_still_energy disabled_by_default: true filters: - throttle: 500ms gate_2: move_energy: name: LD2412 g02 move energy id: ld2412_g02_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g02 still energy id: ld2412_g02_still_energy disabled_by_default: true filters: - throttle: 500ms gate_3: move_energy: name: LD2412 g03 move energy id: ld2412_g03_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g03 still energy id: ld2412_g03_still_energy disabled_by_default: true filters: - throttle: 500ms gate_4: move_energy: name: LD2412 g04 move energy id: ld2412_g04_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g04 still energy id: ld2412_g04_still_energy disabled_by_default: true filters: - throttle: 500ms gate_5: move_energy: name: LD2412 g05 move energy id: ld2412_g05_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g05 still energy id: ld2412_g05_still_energy disabled_by_default: true filters: - throttle: 500ms gate_6: move_energy: name: LD2412 g06 move energy id: ld2412_g06_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g06 still energy id: ld2412_g06_still_energy disabled_by_default: true filters: - throttle: 500ms gate_7: move_energy: name: LD2412 g07 move energy id: ld2412_g07_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g07 still energy id: ld2412_g07_still_energy disabled_by_default: true filters: - throttle: 500ms gate_8: move_energy: name: LD2412 g08 move energy id: ld2412_g08_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g08 still energy id: ld2412_g08_still_energy disabled_by_default: true filters: - throttle: 500ms gate_9: move_energy: name: LD2412 g09 move energy id: ld2412_g09_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g09 still energy id: ld2412_g09_still_energy disabled_by_default: true filters: - throttle: 500ms gate_10: move_energy: name: LD2412 g10 move energy id: ld2412_g10_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g10 still energy id: ld2412_g10_still_energy disabled_by_default: true filters: - throttle: 500ms gate_11: move_energy: name: LD2412 g11 move energy id: ld2412_g11_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g11 still energy id: ld2412_g11_still_energy disabled_by_default: true filters: - throttle: 500ms gate_12: move_energy: name: LD2412 g12 move energy id: ld2412_g12_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g12 still energy id: ld2412_g12_still_energy disabled_by_default: true filters: - throttle: 500ms gate_13: move_energy: name: LD2412 g13 move energy id: ld2412_g13_move_energy disabled_by_default: true filters: - throttle: 500ms still_energy: name: LD2412 g13 still energy id: ld2412_g13_still_energy disabled_by_default: true filters: - throttle: 500ms # Battery monitoring - platform: max17048 id: max_17048 battery_voltage: name: Battery voltage id: batt_v disabled_by_default: true battery_level: name: Battery level id: batt_pct disabled_by_default: true filters: - lambda: | if (x > 100) return 100; else return (x); light: - platform: esp32_rmt_led_strip id: rgb_light name: "RGB Light" pin: GPIO4 default_transition_length: 0s chipset: WS2812 num_leds: 4 rgb_order: grb effects: - pulse: name: "Slow Pulse" transition_length: 1000ms update_interval: 1000ms min_brightness: 0% max_brightness: 100% - pulse: name: "Fast Pulse" transition_length: 100ms update_interval: 100ms min_brightness: 50% max_brightness: 100% button: - platform: template name: "Update Firmware" id: update_firmware entity_category: config on_press: then: - logger.log: "Applying firmware update for the selected firmware type" - lambda: |- id(deep_sleep_1).prevent_deep_sleep(); - script.execute: install_selected_channel - 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: ld2412 factory_reset: name: "LD2412 Factory Reset" id: ld2412_factory_reset_btn disabled_by_default: true query_params: name: "LD2412 Query params" id: ld2412_query_params_btn disabled_by_default: true restart: name: "LD2412 Restart" id: ld2412_restart_btn disabled_by_default: true start_dynamic_background_correction: name: "LD2412 Start Dynamic Background Correction" id: ld2412_start_dynamic_background_correction_btn disabled_by_default: true number: - platform: template id: min_temp name: Min Temperature min_value: -60 max_value: 100 step: 0.1 unit_of_measurement: '°C' initial_value: -20 optimistic: true update_interval: never mode: box entity_category: config disabled_by_default: true - platform: template id: max_temp name: Max Temperature min_value: -60 max_value: 100 step: 0.1 unit_of_measurement: '°C' initial_value: 200 optimistic: true update_interval: never mode: box entity_category: config disabled_by_default: true - platform: template id: min_humidity name: Min Humidity min_value: 0 max_value: 100 step: 0.1 unit_of_measurement: '%' initial_value: 0 optimistic: true update_interval: never mode: box entity_category: config disabled_by_default: true - platform: template id: max_humidity name: Max Humidity min_value: 0 max_value: 100 step: 0.1 unit_of_measurement: '%' initial_value: 100 optimistic: true update_interval: never mode: box entity_category: config disabled_by_default: true # Configurable temperature and humidity intervals (in minutes) - platform: template id: temperature_update_interval name: "Temperature Update Interval" min_value: 1 max_value: 1000 step: 1 unit_of_measurement: 'm' initial_value: 1 optimistic: true restore_value: true mode: box entity_category: config disabled_by_default: true on_value: then: - lambda: |- // Force immediate temperature update when interval changes id(sht_temperature).publish_state(id(sht_temperature_raw).state); id(last_temp_update) = millis(); - platform: template id: humidity_update_interval name: "Humidity Update Interval" min_value: 1 max_value: 1000 step: 1 unit_of_measurement: 'm' initial_value: 1 optimistic: true restore_value: true mode: box entity_category: config disabled_by_default: true on_value: then: - lambda: |- // Force immediate humidity update when interval changes id(sht_humidity).publish_state(id(sht_humidity_raw).state); id(last_humidity_update) = millis(); # Total PM min/max settings - platform: template id: max_total_pm name: Max Total PM min_value: 0 max_value: 500 step: 0.1 unit_of_measurement: 'µg/m³' initial_value: 50 optimistic: true update_interval: never mode: box entity_category: config disabled_by_default: true - platform: template id: max_total_pm_count name: Max Total PM Count min_value: 0 max_value: 10000000000 step: 1000000 unit_of_measurement: '#/m³' initial_value: 1000000000 optimistic: true restore_value: true update_interval: never mode: box entity_category: config disabled_by_default: true # Deep sleep duration configuration - platform: template name: "Sleep Duration" id: deep_sleep_sleep_duration min_value: 0.01 max_value: 24 step: 0.01 mode: box update_interval: never optimistic: true restore_value: true initial_value: 1 icon: "mdi:arrow-collapse-right" entity_category: CONFIG unit_of_measurement: "h" disabled_by_default: true on_value: then: - lambda: |- id(deep_sleep_1).set_sleep_duration(x * 60 * 60 * 1000); - platform: ld2412 light_threshold: name: "LD2412 Light Threshold" id: ld2412_light_threshold disabled_by_default: true timeout: name: "LD2412 Timeout" id: ld2412_timeout disabled_by_default: true min_distance_gate: name: "LD2412 min distance gate" id: ld2412_min_distance_gate disabled_by_default: true max_distance_gate: name: "LD2412 max distance gate" id: ld2412_max_distance_gate disabled_by_default: true gate_0: move_threshold: name: LD2412 g00 move threshold id: ld2412_g00_move_threshold disabled_by_default: true still_threshold: name: LD2412 g00 still threshold id: ld2412_g00_still_threshold disabled_by_default: true gate_1: move_threshold: name: LD2412 g01 move threshold id: ld2412_g01_move_threshold disabled_by_default: true still_threshold: name: LD2412 g01 still threshold id: ld2412_g01_still_threshold disabled_by_default: true gate_2: move_threshold: name: LD2412 g02 move threshold id: ld2412_g02_move_threshold disabled_by_default: true still_threshold: name: LD2412 g02 still threshold id: ld2412_g02_still_threshold disabled_by_default: true gate_3: move_threshold: name: LD2412 g03 move threshold id: ld2412_g03_move_threshold disabled_by_default: true still_threshold: name: LD2412 g03 still threshold id: ld2412_g03_still_threshold disabled_by_default: true gate_4: move_threshold: name: LD2412 g04 move threshold id: ld2412_g04_move_threshold disabled_by_default: true still_threshold: name: LD2412 g04 still threshold id: ld2412_g04_still_threshold disabled_by_default: true gate_5: move_threshold: name: LD2412 g05 move threshold id: ld2412_g05_move_threshold disabled_by_default: true still_threshold: name: LD2412 g05 still threshold id: ld2412_g05_still_threshold disabled_by_default: true gate_6: move_threshold: name: LD2412 g06 move threshold id: ld2412_g06_move_threshold disabled_by_default: true still_threshold: name: LD2412 g06 still threshold id: ld2412_g06_still_threshold disabled_by_default: true gate_7: move_threshold: name: LD2412 g07 move threshold id: ld2412_g07_move_threshold disabled_by_default: true still_threshold: name: LD2412 g07 still threshold id: ld2412_g07_still_threshold disabled_by_default: true gate_8: move_threshold: name: LD2412 g08 move threshold id: ld2412_g08_move_threshold disabled_by_default: true still_threshold: name: LD2412 g08 still threshold id: ld2412_g08_still_threshold disabled_by_default: true gate_9: move_threshold: name: LD2412 g09 move threshold id: ld2412_g09_move_threshold disabled_by_default: true still_threshold: name: LD2412 g09 still threshold id: ld2412_g09_still_threshold disabled_by_default: true gate_10: move_threshold: name: LD2412 g10 move threshold id: ld2412_g10_move_threshold disabled_by_default: true still_threshold: name: LD2412 g10 still threshold id: ld2412_g10_still_threshold disabled_by_default: true gate_11: move_threshold: name: LD2412 g11 move threshold id: ld2412_g11_move_threshold disabled_by_default: true still_threshold: name: LD2412 g11 still threshold id: ld2412_g11_still_threshold disabled_by_default: true gate_12: move_threshold: name: LD2412 g12 move threshold id: ld2412_g12_move_threshold disabled_by_default: true still_threshold: name: LD2412 g12 still threshold id: ld2412_g12_still_threshold disabled_by_default: true gate_13: move_threshold: name: LD2412 g13 move threshold id: ld2412_g13_move_threshold disabled_by_default: true still_threshold: name: LD2412 g13 still threshold id: ld2412_g13_still_threshold disabled_by_default: true switch: - platform: factory_reset id: factory_reset_switch internal: true - platform: gpio pin: GPIO7 name: "Accessory Power" id: accessory_power restore_mode: ALWAYS_ON setup_priority: 1100 internal: true - platform: template name: "Alarm Outside Temp Range" id: alarm_outside_temp_range optimistic: true restore_mode: RESTORE_DEFAULT_OFF disabled_by_default: true - platform: template name: "Alarm Outside Humidity Range" id: alarm_outside_humidity_range optimistic: true restore_mode: RESTORE_DEFAULT_OFF disabled_by_default: true - platform: template name: "Alarm Outside Total PM Range" id: alarm_outside_total_pm_range optimistic: true restore_mode: RESTORE_DEFAULT_OFF disabled_by_default: true - platform: template name: "Alarm Outside Total PM Count Range" id: alarm_outside_total_pm_count_range optimistic: true restore_mode: RESTORE_DEFAULT_OFF disabled_by_default: true - platform: ld2412 bluetooth: name: "LD2412 Bluetooth" id: ld2412_bluetooth disabled_by_default: true engineering_mode: name: "LD2412 Engineering Mode" id: ld2412_engineering_mode disabled_by_default: true - platform: template name: "Prevent Sleep" id: prevent_sleep icon: mdi:sleep restore_mode: RESTORE_DEFAULT_ON optimistic: true entity_category: "config" on_turn_on: then: - lambda: |- id(deep_sleep_1).prevent_deep_sleep(); on_turn_off: then: - if: condition: binary_sensor.is_off: ota_mode then: - lambda: |- id(deep_sleep_1).allow_deep_sleep(); interval: - interval: 10s startup_delay: 60s then: - if: condition: lambda: !lambda |- return id(alarm_active).state; then: - lambda: !lambda |- id(rgb_light).turn_on().set_effect("Fast Pulse").perform(); id(rgb_light).turn_on().set_rgb(1, 0, 0).set_transition_length(0).perform(); id(rtttl_buzzer).play("siren:d=8,o=5,b=100:d,e,d,e,d,e,d,e;"); # Temperature and humidity configurable intervals - interval: 10s then: - lambda: |- // Temperature update check (min to milliseconds) uint32_t temp_interval_ms = id(temperature_update_interval).state * 60 * 1000; if (millis() - id(last_temp_update) >= temp_interval_ms) { id(sht_temperature).publish_state(id(sht_temperature_raw).state); id(last_temp_update) = millis(); } // Humidity update check (min to milliseconds) uint32_t humidity_interval_ms = id(humidity_update_interval).state * 60 * 1000; if (millis() - id(last_humidity_update) >= humidity_interval_ms) { id(sht_humidity).publish_state(id(sht_humidity_raw).state); id(last_humidity_update) = millis(); } script: # The update component drops a check requested while another one is running, # so keep asking until install_selected_channel has what it needs. - id: request_channel_manifest mode: restart then: - repeat: count: 4 then: - component.update: update_http_request - delay: 5s # Forced install, but only of a manifest fetched after this press from the # selected firmware type. mode single: a second press while this runs is ignored. - id: install_selected_channel mode: single then: # Mark the cached firmware URL as old. Only a successful check replaces it. - lambda: |- std::string &fw = const_cast(id(update_http_request).update_info.firmware_url); if (fw.rfind('!', 0) != 0) fw.insert(0, "!"); - script.execute: request_channel_manifest # Wait for a check without error whose firmware sits in the directory of # the selected manifest (relative paths are merged with the manifest URL). - wait_until: timeout: 20s condition: lambda: |- const char *src = id(update_http_request).get_source_url(); const size_t dir = strrchr(src, '/') - src + 1; return !id(update_http_request).status_has_error() && strncmp(id(update_http_request).update_info.firmware_url.c_str(), src, dir) == 0; - script.stop: request_channel_manifest - lambda: |- std::string &fw = const_cast(id(update_http_request).update_info.firmware_url); const char *src = id(update_http_request).get_source_url(); const size_t dir = strrchr(src, '/') - src + 1; const bool err = id(update_http_request).status_has_error(); const char *why = nullptr; if (fw.rfind('!', 0) == 0) { why = err ? "the manifest check failed" : "no manifest arrived within 20s"; fw.erase(0, 1); // put the old URL back for the update entity } else if (err || strncmp(fw.c_str(), src, dir) != 0) { why = "the manifest that arrived is not for the selected firmware type"; } if (why != nullptr) { ESP_LOGW("firmware", "Firmware Update: %s (%s); not installing", why, src); // Nothing is being flashed: let the unit sleep again, unless something // else is holding it awake (prevent_sleep, OTA mode, an active alarm). if (!id(prevent_sleep).state && !id(ota_mode).state && !id(alarm_triggered_on_wake)) id(deep_sleep_1).allow_deep_sleep(); return; } ESP_LOGI("firmware", "Installing %s", fw.c_str()); id(deep_sleep_1).prevent_deep_sleep(); id(update_http_request).perform(true); - id: reportAllValues then: # sen5x_number must run before sen55: run second, its blocking read # corrupts sen55's pending read of the same SEN55. - component.update: sen5x_number_component - component.update: sen55 - component.update: sht3xd_sensor - component.update: dallas_temp_probe - component.update: dallas_temp_probe_2 - component.update: dallas_temp_probe_3 - component.update: dallas_temp_probe_4 - component.update: max_17048 - delay: 2s - lambda: |- // Publish SHT temperature and humidity values id(sht_temperature).publish_state(id(sht_temperature_raw).state); id(sht_humidity).publish_state(id(sht_humidity_raw).state); id(last_temp_update) = millis(); id(last_humidity_update) = millis(); // Publish total PM count using raw sensor values directly // pm_0_5_number = 0.3-0.5 range (cumulative <0.5) // Ranges: 0.3-0.5, 0.5-1, 1-2.5, 2.5-4, 4-10 float pm_0_3_to_0_5 = id(pm_0_5_number).state; float pm_0_5_to_1 = std::max(0.0f, id(pm_1_0_number).state - id(pm_0_5_number).state); float pm_1_to_2_5 = std::max(0.0f, id(pm_2_5_number).state - id(pm_1_0_number).state); float pm_2_5_to_4 = std::max(0.0f, id(pm_4_0_number).state - id(pm_2_5_number).state); float pm_4_to_10 = std::max(0.0f, id(pm_10_0_number).state - id(pm_4_0_number).state); float total_count = pm_0_3_to_0_5 + pm_0_5_to_1 + pm_1_to_2_5 + pm_2_5_to_4 + pm_4_to_10; if (!std::isnan(total_count)) { id(total_pm_count).publish_state(total_count); ESP_LOGI("Apollo", "Total PM Count: %.0f", total_count); } else { ESP_LOGW("Apollo", "Total PM Count is NaN, skipping publish"); } select: - platform: ld2412 out_pin_level: name: 'LD2412 Hardware output pin level' id: ld2412_out_pin_level disabled_by_default: true light_function: name: 'LD2412 Light Function' id: ld2412_light_function disabled_by_default: true distance_resolution: name: 'LD2412 Distance resolution' id: ld2412_distance_resolution disabled_by_default: true baud_rate: name: "LD2412 baud rate" id: ld2412_baud_rate disabled_by_default: true on_value: - delay: 3s - lambda: |- id(uart_ld2412).flush(); uint32_t new_baud_rate = stoi(x); ESP_LOGD("change_baud_rate", "Changing baud rate from %i to %i", id(uart_ld2412).get_baud_rate(), new_baud_rate); if (id(uart_ld2412).get_baud_rate() != new_baud_rate) { id(uart_ld2412).set_baud_rate(new_baud_rate); id(uart_ld2412).load_settings(); } text_sensor: - platform: ld2412 version: name: "LD2412 Firmware" id: ld2412_firmware disabled_by_default: true mac_address: name: "LD2412 BT MAC" id: ld2412_bt_mac disabled_by_default: true # Diagnostics (network ones are in the W/ETH files) - platform: version name: "ESPHome Version" id: esphome_version hide_timestamp: true entity_category: "diagnostic" - platform: template name: "Apollo Firmware Version" id: apollo_firmware_version update_interval: never entity_category: "diagnostic" - platform: template name: "OTA URL" id: ota_url entity_category: "diagnostic" internal: true