update Illuminance at least every 60 seconds, even if value not changed

This commit is contained in:
Lanea Lucy S 2023-10-13 01:59:22 +02:00
parent 4f6a13ee3d
commit 4e3dd082fb

View File

@ -60,6 +60,10 @@ globals:
type: float type: float
restore_value: no restore_value: no
initial_value: "-1" initial_value: "-1"
- id: last_illuminance_timestamp
type: int
restore_value: no
initial_value: "-1"
improv_serial: improv_serial:
@ -686,17 +690,25 @@ sensor:
update_interval: 1s update_interval: 1s
filters: filters:
- lambda: !lambda |- - lambda: !lambda |-
auto time = id(time_now).utcnow().timestamp;
if (id(last_illuminance) == x){ if (id(last_illuminance) == x){
if (time >= (id(last_illuminance_timestamp) + 60)){
id(last_illuminance_timestamp) = time;
return x;
} else {
return {}; return {};
} }
}
if (id(bh1750_fast_update).state){ if (id(bh1750_fast_update).state){
id(last_illuminance) = x; id(last_illuminance) = x;
// ESP_LOGD("custom", "Fast Update BH1850"); // ESP_LOGD("custom", "Fast Update BH1850");
id(last_illuminance_timestamp) = time;
return x; return x;
} }
if (abs(id(last_illuminance) - x) > 1){ if (abs(id(last_illuminance) - x) > 1){
id(last_illuminance) = x; id(last_illuminance) = x;
id(last_illuminance_timestamp) = time;
return x; return x;
} }
return {}; return {};