Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3e2dbb7
Update for ESPHome 2025.8.0 release
kbx81 Aug 13, 2025
d4ffac9
Update version
kbx81 Aug 13, 2025
bcb98f3
Fix reporting of initial values when reduce_db_reporting=true
fedorka Sep 29, 2025
23d658b
Increase reporting for lux and UV index
fedorka Sep 30, 2025
cd4abbe
Merge branch 'main' into fix-initial-reporting
fedorka Sep 30, 2025
746e182
Add logger configuration to MSR-2.yaml
bharvey88 Oct 25, 2025
c8788bf
Merge pull request #46 from ApolloAutomation/add-logger-to-msr-2yaml
TrevorSchirmer Oct 25, 2025
d8e37d9
Merge pull request #43 from fedorka/fix-initial-reporting
TrevorSchirmer Oct 25, 2025
b6ed584
Add general occupancy sensor
paradox460 Nov 20, 2025
eea9485
Merge branch 'beta' into 20250812-update-ld2410-throttle
TrevorSchirmer Dec 3, 2025
e5d868c
Merge pull request #40 from kbx81/20250812-update-ld2410-throttle
TrevorSchirmer Dec 3, 2025
2aa81ee
Rename general occupancy sensor based on discussion in discord
paradox460 Dec 7, 2025
be70ff5
Merge pull request #47 from paradox460/main
TrevorSchirmer Jan 24, 2026
9dd9982
Add configurable update interval for LTR390 sensor
bharvey88 Jan 31, 2026
2bb306f
Fix: Ensure immediate LTR390 reading on boot
bharvey88 Feb 2, 2026
196c738
Add IP address text sensor via wifi_info platform
bharvey88 Feb 24, 2026
0cefd9f
Rename API services to actions (play_buzzer, calibrate_co2_value, set…
bharvey88 Feb 24, 2026
d7d33ac
Modernise board spec and remove legacy platformio/BLE config
bharvey88 Feb 24, 2026
797d75e
fix: remove unused id, add entity_category diagnostic to IP address s…
bharvey88 Feb 25, 2026
0bcb5b7
fix: restore id: wifi_ip (needed for ESPHome automations)
bharvey88 Feb 25, 2026
2466690
Merge pull request #61 from ApolloAutomation/esphome-modernisation
TrevorSchirmer Feb 27, 2026
b8ef637
Merge pull request #60 from ApolloAutomation/api-actions-rename
TrevorSchirmer Feb 27, 2026
afa8570
Merge pull request #58 from ApolloAutomation/wifi-info-ip-address
TrevorSchirmer Feb 27, 2026
e128ea1
feat: apply DPS310 pressure offset in filter lambda
bharvey88 Feb 26, 2026
796b4f9
feat: add DPS310 Pressure Offset configurable number entity
bharvey88 Feb 26, 2026
b8dcd6d
Add ESPHome version and Apollo firmware version text sensors
bharvey88 Feb 24, 2026
3420441
fix: add entity_category diagnostic to ESPHome Version sensor
bharvey88 Feb 26, 2026
e349e0c
fix: add update_interval: never to static Apollo Firmware Version sensor
bharvey88 Feb 26, 2026
2268d77
fix: remove duplicate entity_category keys in ESPHome Version sensor
bharvey88 Feb 26, 2026
1f5d0ae
feat: disable LTR390 update interval entity by default
bharvey88 Feb 27, 2026
329a6ee
Merge pull request #59 from ApolloAutomation/version-sensors
TrevorSchirmer Feb 28, 2026
3fb5fba
Fix: remove pressure offset from non-DPS310 sensor lambdas
bharvey88 Mar 1, 2026
21084d1
Merge pull request #62 from ApolloAutomation/dps310-pressure-offset
bharvey88 Mar 2, 2026
0a5b139
Merge pull request #56 from ApolloAutomation/feature/ltr390-configura…
bharvey88 Mar 2, 2026
a6d74c1
Fix LTR390 interval lambda: handle NAN state, remove boot timing guard
bharvey88 Mar 2, 2026
543e299
Bump version to 26.3.2.1
bharvey88 Mar 2, 2026
b41288e
Bump version to 26.3.2.1
bharvey88 Mar 2, 2026
c04f0f2
Fix LTR390 interval lambda: handle NAN state, remove boot timing guard
bharvey88 Mar 3, 2026
9ef21bc
Fix Apollo Firmware Version sensor showing unknown
bharvey88 Mar 6, 2026
c459a08
Fix Apollo Firmware Version sensor showing unknown
bharvey88 Mar 6, 2026
e6bd10f
fix: publish firmware version once on boot instead of polling
bharvey88 Mar 6, 2026
db71fea
fix: move firmware version publish to priority 500 for all variants
bharvey88 Mar 7, 2026
e4c7f95
Fix: publish firmware version once on boot instead of polling
bharvey88 Mar 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 123 additions & 31 deletions Integrations/ESPHome/Core.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
substitutions:
name: apollo-msr-2
version: "25.8.6.1"
version: "26.3.2.1"
device_description: ${name} made by Apollo Automation - version ${version}.

esp32:
board: esp32-c3-devkitm-1
variant: esp32c3
flash_size: 4MB
framework:
type: esp-idf

Expand Down Expand Up @@ -43,20 +44,24 @@ globals:
restore_value: no
type: bool
initial_value: "false"
- id: ltr390_last_update
restore_value: no
type: uint32_t
initial_value: '0'

# Enable Home Assistant API
# Also Add Buzzer Service Connection
# Also Add Buzzer Action Connection
api:
services:
- service: play_buzzer
actions:
- action: play_buzzer
variables:
song_str: string
then:
- rtttl.play:
rtttl: !lambda 'return song_str;'

#Co2 Calibration Service
- service: calibrate_co2_value
#Co2 Calibration Action
- action: calibrate_co2_value
variables:
co2_ppm: float
then:
Expand All @@ -65,7 +70,7 @@ api:
id: scd40

#Setting HLK Password
- service: set_ld2410_bluetooth_password
- action: set_ld2410_bluetooth_password
variables:
password: string
then:
Expand Down Expand Up @@ -144,6 +149,21 @@ number:
name: g8 still threshold


- platform: template
name: "DPS310 Pressure Offset"
id: dps310_pressure_offset
disabled_by_default: true
restore_value: true
initial_value: 0.0
min_value: -100.0
max_value: 100.0
entity_category: "CONFIG"
unit_of_measurement: "hPa"
optimistic: true
update_interval: never
step: 0.1
mode: box

- platform: template
name: DPS Temperature Offset
id: dps310_temperature_offset
Expand All @@ -157,6 +177,20 @@ number:
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"
Expand Down Expand Up @@ -320,6 +354,17 @@ binary_sensor:
id(testScript).execute();
}

- 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;

ld2410:
id: ld2410_radar

Expand All @@ -329,17 +374,17 @@ sensor:
id: sys_esp_temperature
filters:
- lambda: |-
static float last_reported_value = 0.0;
static float last_reported_value = -6.0;
float current_value = x;

// 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
// Apply delta filter: only report if the value has changed by 5 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 the last reported value without updating if change is less than 5
return {}; // Discard the update
}
} else {
Expand Down Expand Up @@ -376,8 +421,9 @@ sensor:
name: Radar Moving Distance
id: moving_distance
filters:
- throttle_with_priority: 1000ms
- lambda: |-
static float last_reported_value = 0.0;
static float last_reported_value = -6.0;
float current_value = x;

// Check if the radar_has_moving_target sensor is off
Expand All @@ -387,12 +433,12 @@ sensor:

// 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
// Apply delta filter: only report if the value has changed by 5 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 the last reported value without updating if change is less than 5
return {}; // Discard the update
}
} else {
Expand All @@ -404,8 +450,9 @@ sensor:
name: Radar Still Distance
id: still_distance
filters:
- throttle_with_priority: 1000ms
- lambda: |-
static float last_reported_value = 0.0;
static float last_reported_value = -6.0;
float current_value = x;

// Check if the radar_has_still_target sensor is off
Expand All @@ -415,12 +462,12 @@ sensor:

// 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
// Apply delta filter: only report if the value has changed by 5 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 the last reported value without updating if change is less than 5
return {}; // Discard the update
}
} else {
Expand All @@ -432,22 +479,25 @@ sensor:
name: Radar Move Energy
id: radar_moving_energy
filters:
- throttle_with_priority: 1000ms
- lambda: |-
if (id(reduce_db_reporting).state) return {};
return x;
still_energy:
name: Radar Still Energy
id: radar_still_energy
filters:
- throttle_with_priority: 1000ms
- lambda: |-
if (id(reduce_db_reporting).state) return {};
return x;
detection_distance:
name: Radar Detection Distance
id: radar_detection_distance
filters:
- throttle_with_priority: 1000ms
- lambda: |-
static float last_reported_value = 0.0;
static float last_reported_value = -6.0;
float current_value = x;

// Check if the radar_has_target sensor is off
Expand All @@ -457,12 +507,12 @@ sensor:

// 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
// Apply delta filter: only report if the value has changed by 5 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 the last reported value without updating if change is less than 5
return {}; // Discard the update
}
} else {
Expand Down Expand Up @@ -536,22 +586,23 @@ sensor:

- platform: ltr390
id: ltr_390
update_interval: never
light:
name: "LTR390 Light"
id: ltr390light
filters:
- lambda: |-
static float last_reported_value = 0.0;
static float last_reported_value = -21.0;
float current_value = x;

// 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) >= 20.0) {
// Apply delta filter: only report if the value has changed by 5 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 the last reported value without updating if change is less than 20
return {}; // Discard the update
}
} else {
Expand All @@ -564,17 +615,17 @@ sensor:
id: ltr390uvindex
filters:
- lambda: |-
static float last_reported_value = 0.0;
static float last_reported_value = -21.0;
float current_value = x;

// 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) >= 20.0) {
// Apply delta filter: only report if the value has changed by 1 or more
if (abs(current_value - last_reported_value) >= 1.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 the last reported value without updating if change is less than 20
return {}; // Discard the update
}
} else {
Expand All @@ -590,17 +641,21 @@ sensor:
id: dps310pressure
filters:
- lambda: |-
static float last_reported_value = 0.0;
static float last_reported_value = -6.0;
float current_value = x;
float offset = id(dps310_pressure_offset).state;
if (!isnan(offset)) {
current_value += offset;
}

// 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
// Apply delta filter: only report if the value has changed by 5 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 the last reported value without updating if change is less than 5
return {}; // Discard the update
Comment on lines 643 to 659

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Do not let the delta filter swallow offset-only changes.

When reduce_db_reporting is on, a calibration change smaller than 5 hPa never reaches dps310pressure because the new offset is applied before the delta comparison. A stable sensor with a +1.0 hPa tweak will keep returning {}, so the displayed pressure — and the scd40 compensation source wired to it — stays stale.

Proposed fix
         - lambda: |-
             static float last_reported_value = -6.0;
+            static float last_offset = NAN;
             float current_value = x;
             float offset = id(dps310_pressure_offset).state;
+            bool offset_changed = isnan(last_offset) ||
+                                  (isnan(offset) != isnan(last_offset)) ||
+                                  (!isnan(offset) && fabsf(offset - last_offset) >= 0.001f);
             if (!isnan(offset)) {
               current_value += offset;
             }
+            if (offset_changed) {
+              last_offset = offset;
+              last_reported_value = current_value;
+              return current_value;
+            }
 
             // Check if the reduce_db_reporting switch is on
             if (id(reduce_db_reporting).state) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- lambda: |-
static float last_reported_value = 0.0;
static float last_reported_value = -6.0;
float current_value = x;
float offset = id(dps310_pressure_offset).state;
if (!isnan(offset)) {
current_value += offset;
}
// 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
// Apply delta filter: only report if the value has changed by 5 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 the last reported value without updating if change is less than 5
return {}; // Discard the update
- lambda: |-
static float last_reported_value = -6.0;
static float last_offset = NAN;
float current_value = x;
float offset = id(dps310_pressure_offset).state;
bool offset_changed = isnan(last_offset) ||
(isnan(offset) != isnan(last_offset)) ||
(!isnan(offset) && fabsf(offset - last_offset) >= 0.001f);
if (!isnan(offset)) {
current_value += offset;
}
if (offset_changed) {
last_offset = offset;
last_reported_value = current_value;
return current_value;
}
// 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 5 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 5
return {}; // Discard the update
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Integrations/ESPHome/Core.yaml` around lines 643 - 659, The delta filter
currently compares the offset-adjusted value and can drop updates that are
actually only offset changes; modify the lambda used for dps310pressure to track
the last applied offset as well as last_reported_value (add a static float
last_reported_offset = NAN), compute current_value = x + offset as now, but if
id(reduce_db_reporting).state is true then also check whether the offset has
changed (considering isnan) — if the offset differs from last_reported_offset
then update last_reported_offset and last_reported_value and return
current_value so offset-only tweaks are reported; otherwise keep the existing
delta comparison against last_reported_value and return {} when below threshold.
Ensure you reference id(dps310_pressure_offset) and id(reduce_db_reporting) and
update the existing static last_reported_value accordingly.

}
} else {
Expand Down Expand Up @@ -666,6 +721,28 @@ button:
id: scd40


interval:
- 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;
}

switch:
- platform: ld2410
bluetooth:
Expand Down Expand Up @@ -697,6 +774,21 @@ text_sensor:
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:
Expand Down
10 changes: 7 additions & 3 deletions Integrations/ESPHome/MSR-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ esphome:
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: 500
then:
- text_sensor.template.publish:
id: apollo_firmware_version
state: "${version}"
- priority: -10
then:
- if:
Expand All @@ -29,6 +31,8 @@ dashboard_import:
package_import_url: github://ApolloAutomation/MSR-2/Integrations/ESPHome/MSR-2.yaml
import_full_config: false

logger:

ota:
- platform: esphome
id: ota_default
Expand Down
Loading
Loading