Compare commits
3 Commits
3e37639213
...
ee0983fe3a
Author | SHA1 | Date |
---|---|---|
Gilles Grandou | ee0983fe3a | |
Gilles Grandou | b79084c01b | |
Gilles Grandou | ef11c67ecd |
66
pool.js
66
pool.js
|
@ -28,27 +28,37 @@ let status = {
|
||||||
tick_day: 0,
|
tick_day: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
// compute duration of filtration for a given max temperature
|
// temperature->duration chart
|
||||||
|
let filt_time = [
|
||||||
|
[ 5, 1.0 ], // at 5°C, 1 hour of filtering
|
||||||
|
[ 10, 2.0 ],
|
||||||
|
[ 12, 4.0 ],
|
||||||
|
[ 16, 6.0 ],
|
||||||
|
[ 24, 8.0 ],
|
||||||
|
[ 27, 12.0 ],
|
||||||
|
[ 30, 24.0 ]
|
||||||
|
];
|
||||||
|
|
||||||
|
// compute filtration time for a given max temperature
|
||||||
// duration is returned in float format (1.25 -> 1h 15mn)
|
// duration is returned in float format (1.25 -> 1h 15mn)
|
||||||
|
|
||||||
function compute_duration_filt(t) {
|
function compute_filtration_time(t) {
|
||||||
if (t < 5)
|
let len = filt_time.length;
|
||||||
return 1;
|
|
||||||
if (t < 10)
|
if (t < filt_time[0][0])
|
||||||
return (t/5); // 1 -> 2
|
return filt_time[0][1];
|
||||||
if (t < 12)
|
|
||||||
return (t-8); // 2 -> 4
|
for (let i = 0; i < len-1; i++) {
|
||||||
if (t < 16)
|
if (t >= filt_time[i][0] && t < filt_time[i+1][0]) {
|
||||||
return (t/2-2); // 4 -> 6
|
// linear interpolation between two points
|
||||||
if (t < 24)
|
return filt_time[i][1] + (filt_time[i+1][1] - filt_time[i][1]) / (filt_time[i+1][0] - filt_time[i][0]) * (t - filt_time[i][0]);
|
||||||
return (t/4+2); // 6 -> 8
|
}
|
||||||
if (t < 27)
|
}
|
||||||
return (t*4/3-24) // 8 -> 12
|
|
||||||
if (t < 30)
|
return filt_time[len-1][1];
|
||||||
return (t*4 - 96); // 12 -> 24
|
|
||||||
return 24;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// compute the pump schedule for a given duration
|
// compute the pump schedule for a given duration
|
||||||
// returns an array of start/stop times in float
|
// returns an array of start/stop times in float
|
||||||
// [ start1, stop1, start2, stop2, ... ]
|
// [ start1, stop1, start2, stop2, ... ]
|
||||||
|
@ -92,6 +102,14 @@ function update_new_day() {
|
||||||
print("[POOL] update_new_day", status.tick_day);
|
print("[POOL] update_new_day", status.tick_day);
|
||||||
status.temp_yesterday = status.temp_today;
|
status.temp_yesterday = status.temp_today;
|
||||||
status.temp_today = null;
|
status.temp_today = null;
|
||||||
|
|
||||||
|
Shelly.call(
|
||||||
|
"KVS.Set",
|
||||||
|
{ key: "pool.temp_yesterday", value: status.temp_yesterday },
|
||||||
|
function (result) {
|
||||||
|
print("[POOL] KVS set: ", JSON.stringify(result));
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// call a chain of API calls
|
// call a chain of API calls
|
||||||
|
@ -127,7 +145,7 @@ function update_pump(temp, max, time) {
|
||||||
status.tick_pump++;
|
status.tick_pump++;
|
||||||
print("[POOL] update_pump", status.tick_pump, "- temp:", temp, "max:", max, "time:", time);
|
print("[POOL] update_pump", status.tick_pump, "- temp:", temp, "max:", max, "time:", time);
|
||||||
|
|
||||||
let duration = compute_duration_filt(max);
|
let duration = compute_filtration_time(max);
|
||||||
let schedule = compute_schedule_filt(duration);
|
let schedule = compute_schedule_filt(duration);
|
||||||
|
|
||||||
print("[POOL] update_pump - duration:", duration);
|
print("[POOL] update_pump - duration:", duration);
|
||||||
|
@ -242,6 +260,18 @@ function update_temp(temp) {
|
||||||
status.lock_update = false;
|
status.lock_update = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set initial yesterday temp from KVS
|
||||||
|
Shelly.call (
|
||||||
|
"KVS.Get",
|
||||||
|
{ key: "pool.temp_yesterday" },
|
||||||
|
function (result) {
|
||||||
|
if (result) {
|
||||||
|
status.temp_yesterday = result.value;
|
||||||
|
print("[POOL] Restore from KVS: temp_yesterday:", status.temp_yesterday);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// receives update from Pool Sensor
|
// receives update from Pool Sensor
|
||||||
// - trigger all temperature and pump updates
|
// - trigger all temperature and pump updates
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue