diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 25de204..9eae713 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -53,6 +53,10 @@ globals: restore_value: no type: uint32_t initial_value: '0' + - id: ltr390_last_update + restore_value: no + type: uint32_t + initial_value: '0' i2c: sda: GPIO1 @@ -147,6 +151,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" @@ -525,6 +543,7 @@ sensor: - platform: ltr390 id: ltr_390 + update_interval: never light: name: "LTR390 Light" id: ltr390light @@ -704,3 +723,24 @@ interval: - 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; + }