From 4d3fcd8826169818f246352c5a02d263ce2f1791 Mon Sep 17 00:00:00 2001 From: Gilles Grandou Date: Tue, 6 Sep 2022 21:33:32 +0200 Subject: [PATCH] save temp_today in KVS --- pool.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pool.js b/pool.js index acc8d4b..f4c2b64 100644 --- a/pool.js +++ b/pool.js @@ -110,6 +110,13 @@ function update_new_day() { 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)); + } + ); } // call a chain of API calls @@ -220,7 +227,18 @@ function update_temp(temp) { status.lock_update = true; status.temp = Math.round(temp * 10) / 10; - 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); print("[POOL] update_temp - max:", status.temp_max, "today:", status.temp_today, "yesterday:", status.temp_yesterday);