Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Zones, Reduce DB Writes, Split YAML #26

Merged
merged 22 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
191 changes: 187 additions & 4 deletions Integrations/ESPHome/Core.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
substitutions:
name: apollo-msr-2
version: "25.2.19.1"
version: "25.2.21.1"
device_description: ${name} made by Apollo Automation - version ${version}.

esp32:
Expand Down Expand Up @@ -248,14 +248,19 @@ binary_sensor:
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))){
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;
Expand All @@ -266,7 +271,10 @@ binary_sensor:
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))) {
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;
Expand All @@ -277,7 +285,10 @@ binary_sensor:
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))) {
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;
Expand Down Expand Up @@ -316,6 +327,26 @@ sensor:
- platform: internal_temperature
name: "ESP Temperature"
id: sys_esp_temperature
filters:
- lambda: |-
static float last_reported_value = 0.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) >= 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;
}

- platform: uptime
name: Uptime
Expand All @@ -338,23 +369,107 @@ sensor:
measurement_mode: "periodic"
i2c_id: bus_a
ambient_pressure_compensation_source: dps310pressure


- 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
Expand Down Expand Up @@ -424,15 +539,75 @@ sensor:
light:
name: "LTR390 Light"
id: ltr390light
filters:
- lambda: |-
static float last_reported_value = 0.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) {
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;
}
uv_index:
name: "LTR390 UV Index"
id: ltr390uvindex
filters:
- lambda: |-
static float last_reported_value = 0.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) {
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;
}

- platform: dps310
id: dps_310
pressure:
name: "DPS310 Pressure"
id: dps310pressure
filters:
- lambda: |-
static float last_reported_value = 0.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) >= 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;
}
temperature:
name: "DPS310 Temperature"
id: dps310temperature
Expand Down Expand Up @@ -508,6 +683,14 @@ switch:
- 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"


text_sensor:
- platform: ld2410
Expand Down
Loading
Loading