Compare commits
6 Commits
c927997d69
...
main
Author | SHA1 | Date | |
---|---|---|---|
531acd4d05 | |||
5c7b06ff86 | |||
0971368482 | |||
d7c56585b4 | |||
4b968ca944 | |||
e1f6561331 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
shelly.conf
|
||||
*.log
|
||||
.inspect.json
|
||||
shelly.conf
|
||||
|
114
pool.js
114
pool.js
@ -7,7 +7,6 @@ let status = {
|
||||
temp_yesterday: null,
|
||||
|
||||
update_time: null,
|
||||
update_time_last: 0,
|
||||
update_temp_max_last: null,
|
||||
|
||||
disable_temp: null,
|
||||
@ -24,18 +23,27 @@ let status = {
|
||||
tick_temp: 0,
|
||||
tick_lock: 0,
|
||||
tick_pump: 0,
|
||||
tick_pump_skip: 0,
|
||||
tick_day: 0,
|
||||
};
|
||||
|
||||
// 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 ],
|
||||
[ 5, 2.0 ], // at 5°C, 2 hours of filtering
|
||||
[ 8, 3.0 ],
|
||||
[ 10, 4.0 ],
|
||||
[ 11, 5.0 ],
|
||||
[ 12, 6.0 ],
|
||||
[ 14, 7.0 ],
|
||||
[ 16, 8.0 ],
|
||||
[ 18, 9.0 ],
|
||||
[ 20, 10.0 ],
|
||||
[ 22, 11.0 ],
|
||||
[ 24, 12.0 ],
|
||||
[ 25, 14.0 ],
|
||||
[ 26, 17.0 ],
|
||||
[ 27, 20.0 ],
|
||||
[ 28, 22.0 ],
|
||||
[ 29, 23.0 ],
|
||||
[ 30, 24.0 ]
|
||||
];
|
||||
|
||||
@ -64,25 +72,19 @@ function compute_filtration_time(t) {
|
||||
// [ start1, stop1, start2, stop2, ... ]
|
||||
|
||||
function compute_schedule_filt(d) {
|
||||
let s = null;
|
||||
if (d < 2) {
|
||||
s = [ 9, 9+d ];
|
||||
} else if (d < 8) {
|
||||
s = [ 9, 10, 14, 14+d-1 ];
|
||||
} else if (d < 11) {
|
||||
s = [ 9, 11, 14, 14+d-2 ];
|
||||
} else if (d < 14) {
|
||||
s = [ 9, 9+d-9, 14, 23];
|
||||
} else if (d < 15) {
|
||||
s = [ 9, 9+d ];
|
||||
} else if (d < 18) {
|
||||
s = [ 24-d, 0 ];
|
||||
} else if (d < 24) {
|
||||
s = [ 6, d-18 ];
|
||||
} else {
|
||||
s = [ 6 ];
|
||||
let start = 17 - d/2;
|
||||
let stop = 17 + d/2;
|
||||
|
||||
while (stop >= 24)
|
||||
stop = stop - 24;
|
||||
|
||||
if (d < 24) {
|
||||
let s = [ start, stop ];
|
||||
}
|
||||
|
||||
else {
|
||||
let s = [ start ];
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -144,7 +146,6 @@ function do_call(calls) {
|
||||
}
|
||||
|
||||
// compute & configure pump schedule
|
||||
// TODO force on when duration==24
|
||||
// TODO force off when duration==0
|
||||
// TODO freeze mode if cur < 1
|
||||
|
||||
@ -243,37 +244,24 @@ function update_temp(temp) {
|
||||
|
||||
print("[POOL] update_temp - max:", status.temp_max, "today:", status.temp_today, "yesterday:", status.temp_yesterday);
|
||||
|
||||
Shelly.call (
|
||||
"Sys.GetStatus",
|
||||
{},
|
||||
function (result) {
|
||||
let time = result.time; // "HH:MM"
|
||||
print("[POOL] time", time);
|
||||
let time = Shelly.getComponentStatus("sys").time; // "HH:MM"
|
||||
print("[POOL] time", time);
|
||||
|
||||
// compute current time in float format (12h45 -> 12.75)
|
||||
let t = JSON.parse(time.slice(0,2)) + JSON.parse(time.slice(3,5)) / 60;
|
||||
// compute current time in float format (12h45 -> 12.75)
|
||||
let t = JSON.parse(time.slice(0,2)) + JSON.parse(time.slice(3,5)) / 60;
|
||||
|
||||
if (t < status.update_time)
|
||||
update_new_day();
|
||||
if (t < status.update_time)
|
||||
update_new_day();
|
||||
|
||||
status.update_time = t;
|
||||
status.update_time = t;
|
||||
|
||||
if ((status.temp_max !== null) && (status.temp_max !== status.update_temp_max_last)) {
|
||||
if ((t - status.update_time_last) > 0.15) { // 9 minutes
|
||||
update_pump(status.temp, status.temp_max, t);
|
||||
status.update_time_last = t;
|
||||
status.update_temp_max_last = status.temp_max;
|
||||
}
|
||||
else {
|
||||
status.tick_pump_skip++;
|
||||
print("[POOL] to much update_pump, skipped", status.tick_pump_skip);
|
||||
}
|
||||
}
|
||||
else {
|
||||
print("[POOL] no temp change, skip update_pump");
|
||||
}
|
||||
}
|
||||
);
|
||||
if ((status.temp_max !== null) && (status.temp_max !== status.update_temp_max_last)) {
|
||||
update_pump(status.temp, status.temp_max, t);
|
||||
status.update_temp_max_last = status.temp_max;
|
||||
}
|
||||
else {
|
||||
print("[POOL] no temp change, skip update_pump");
|
||||
}
|
||||
|
||||
status.lock_update = false;
|
||||
}
|
||||
@ -310,7 +298,10 @@ MQTT.subscribe(
|
||||
"zigbee2mqtt/Piscine",
|
||||
function (topic, msg) {
|
||||
status.tick_mqtt++;
|
||||
print("[POOL] mqtt", topic);
|
||||
print("[POOL] mqtt", topic, msg);
|
||||
if (msg == "") {
|
||||
return;
|
||||
}
|
||||
let obj = JSON.parse(msg);
|
||||
if (obj.temperature === undefined) {
|
||||
return;
|
||||
@ -350,15 +341,10 @@ Timer.set(
|
||||
true,
|
||||
function() {
|
||||
status.tick++;
|
||||
Shelly.call (
|
||||
"Sys.GetStatus",
|
||||
{},
|
||||
function (result) {
|
||||
print("[POOL] tick", result.time);
|
||||
status.time = result.time;
|
||||
status.uptime = result.uptime;
|
||||
}
|
||||
);
|
||||
let result = Shelly.getComponentStatus("sys");
|
||||
print("[POOL] tick", result.time);
|
||||
status.time = result.time;
|
||||
status.uptime = result.uptime;
|
||||
}
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user