Compare commits

..

12 Commits

Author SHA1 Message Date
531acd4d05 cleaned filtration time
* filtration time is now fixed inside each range, instead
  of trying to follow linear curve
* don't bother being super accurate, that's too much
  over-engineering after all ;)
2024-07-21 15:33:52 +02:00
5c7b06ff86 fixup empty MQTT message 2024-05-10 18:50:33 +02:00
0971368482 git ignore 2022-11-02 17:38:58 +01:00
d7c56585b4 use synchronous call to read system time 2022-11-02 17:38:58 +01:00
4b968ca944 reactivate disable_temp during 10mn after switch on 2022-11-02 17:38:58 +01:00
e1f6561331 remove all update disables 2022-11-02 17:38:51 +01:00
c927997d69 0.5C granularity is enough and reduce number of KVS updates 2022-09-07 10:26:46 +02:00
13e59a2615 update_temp at startup from restored temp_today 2022-09-07 09:54:39 +02:00
3096846e0d restore temp_today from KVS at startup 2022-09-07 09:54:39 +02:00
4d3fcd8826 save temp_today in KVS 2022-09-07 09:54:39 +02:00
d072d29fba kvs tools 2022-09-07 09:54:39 +02:00
657a1b38e3 fixup kvs yesteday 2022-09-06 21:33:08 +02:00
5 changed files with 120 additions and 69 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
shelly.conf
*.log *.log
.inspect.json
shelly.conf

13
kvs_delete Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
source $(dirname $0)/shelly.conf
if [ $# -ne 1 ]; then
echo "usage: $0 <key> <value>"
exit 1
fi
key=$1
curl -s $SHELLY_RPC/KVS.Delete'?key="'$key'"' | jq .

6
kvs_list Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
source $(dirname $0)/shelly.conf
curl -s $SHELLY_RPC/KVS.GetMany'?key="*"' | jq .

14
kvs_set Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
source $(dirname $0)/shelly.conf
if [ $# -ne 2 ]; then
echo "usage: $0 <key> <value>"
exit 1
fi
key=$1
value=$2
curl -s $SHELLY_RPC/KVS.Set'?key="'$key'"&value='$value'' | jq .

119
pool.js
View File

@ -7,7 +7,6 @@ let status = {
temp_yesterday: null, temp_yesterday: null,
update_time: null, update_time: null,
update_time_last: 0,
update_temp_max_last: null, update_temp_max_last: null,
disable_temp: null, disable_temp: null,
@ -24,18 +23,27 @@ let status = {
tick_temp: 0, tick_temp: 0,
tick_lock: 0, tick_lock: 0,
tick_pump: 0, tick_pump: 0,
tick_pump_skip: 0,
tick_day: 0, tick_day: 0,
}; };
// temperature->duration chart // temperature->duration chart
let filt_time = [ let filt_time = [
[ 5, 1.0 ], // at 5°C, 1 hour of filtering [ 5, 2.0 ], // at 5°C, 2 hours of filtering
[ 10, 2.0 ], [ 8, 3.0 ],
[ 12, 4.0 ], [ 10, 4.0 ],
[ 16, 6.0 ], [ 11, 5.0 ],
[ 24, 8.0 ], [ 12, 6.0 ],
[ 27, 12.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 ] [ 30, 24.0 ]
]; ];
@ -64,23 +72,17 @@ function compute_filtration_time(t) {
// [ start1, stop1, start2, stop2, ... ] // [ start1, stop1, start2, stop2, ... ]
function compute_schedule_filt(d) { function compute_schedule_filt(d) {
let s = null; let start = 17 - d/2;
if (d < 2) { let stop = 17 + d/2;
s = [ 9, 9+d ];
} else if (d < 8) { while (stop >= 24)
s = [ 9, 10, 14, 14+d-1 ]; stop = stop - 24;
} else if (d < 11) {
s = [ 9, 11, 14, 14+d-2 ]; if (d < 24) {
} else if (d < 14) { let s = [ start, stop ];
s = [ 9, 9+d-9, 14, 23]; }
} else if (d < 15) { else {
s = [ 9, 9+d ]; let s = [ start ];
} else if (d < 18) {
s = [ 24-d, 0 ];
} else if (d < 24) {
s = [ 6, d-18 ];
} else {
s = [ 6 ];
} }
return s; return s;
@ -107,7 +109,14 @@ function update_new_day() {
"KVS.Set", "KVS.Set",
{ key: "pool.temp_yesterday", value: status.temp_yesterday }, { key: "pool.temp_yesterday", value: status.temp_yesterday },
function (result) { function (result) {
print("[POOL] KVS set: ", JSON.stringify(result)); print("[POOL] KVS set temp_yesterday: ", JSON.stringify(result));
}
);
Shelly.call(
"KVS.Set",
{ key: "pool.temp_today", value: null },
function (result) {
print("[POOL] KVS set temp_today: ", JSON.stringify(result));
} }
); );
} }
@ -137,7 +146,6 @@ function do_call(calls) {
} }
// compute & configure pump schedule // compute & configure pump schedule
// TODO force on when duration==24
// TODO force off when duration==0 // TODO force off when duration==0
// TODO freeze mode if cur < 1 // TODO freeze mode if cur < 1
@ -219,17 +227,24 @@ function update_temp(temp) {
} }
status.lock_update = true; status.lock_update = true;
status.temp = Math.round(temp * 10) / 10; status.temp = Math.round(temp * 2) / 2;
status.temp_today = Math.max(status.temp_today, status.temp);
if (status.temp > status.temp_today || status.temp_today === null) {
status.temp_today = status.temp;
Shelly.call (
"KVS.Set",
{ key: "pool.temp_today", value: status.temp_today },
function (result) {
print("[POOL] KVS set temp_today: ", JSON.stringify(result));
}
);
}
status.temp_max = Math.max(status.temp_today, status.temp_yesterday); status.temp_max = Math.max(status.temp_today, status.temp_yesterday);
print("[POOL] update_temp - max:", status.temp_max, "today:", status.temp_today, "yesterday:", status.temp_yesterday); print("[POOL] update_temp - max:", status.temp_max, "today:", status.temp_today, "yesterday:", status.temp_yesterday);
Shelly.call ( let time = Shelly.getComponentStatus("sys").time; // "HH:MM"
"Sys.GetStatus",
{},
function (result) {
let time = result.time; // "HH:MM"
print("[POOL] time", time); print("[POOL] time", time);
// compute current time in float format (12h45 -> 12.75) // compute current time in float format (12h45 -> 12.75)
@ -241,26 +256,17 @@ function update_temp(temp) {
status.update_time = t; status.update_time = t;
if ((status.temp_max !== null) && (status.temp_max !== status.update_temp_max_last)) { 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); update_pump(status.temp, status.temp_max, t);
status.update_time_last = t;
status.update_temp_max_last = status.temp_max; 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 { else {
print("[POOL] no temp change, skip update_pump"); print("[POOL] no temp change, skip update_pump");
} }
}
);
status.lock_update = false; status.lock_update = false;
} }
// Set initial yesterday temp from KVS // Set initial temps from KVS
Shelly.call ( Shelly.call (
"KVS.Get", "KVS.Get",
{ key: "pool.temp_yesterday" }, { key: "pool.temp_yesterday" },
@ -272,6 +278,19 @@ Shelly.call (
} }
) )
Shelly.call (
"KVS.Get",
{ key: "pool.temp_today" },
function (result) {
if (result) {
status.temp_today = result.value;
print("[POOL] Restore from KVS: temp_today:", status.temp_today);
if (status.temp_today !== null)
update_temp(status.temp_today);
}
}
)
// receives update from Pool Sensor // receives update from Pool Sensor
// - trigger all temperature and pump updates // - trigger all temperature and pump updates
@ -279,7 +298,10 @@ MQTT.subscribe(
"zigbee2mqtt/Piscine", "zigbee2mqtt/Piscine",
function (topic, msg) { function (topic, msg) {
status.tick_mqtt++; status.tick_mqtt++;
print("[POOL] mqtt", topic); print("[POOL] mqtt", topic, msg);
if (msg == "") {
return;
}
let obj = JSON.parse(msg); let obj = JSON.parse(msg);
if (obj.temperature === undefined) { if (obj.temperature === undefined) {
return; return;
@ -319,15 +341,10 @@ Timer.set(
true, true,
function() { function() {
status.tick++; status.tick++;
Shelly.call ( let result = Shelly.getComponentStatus("sys");
"Sys.GetStatus",
{},
function (result) {
print("[POOL] tick", result.time); print("[POOL] tick", result.time);
status.time = result.time; status.time = result.time;
status.uptime = result.uptime; status.uptime = result.uptime;
} }
); );
}
);