Compare commits

..

5 Commits

4 changed files with 67 additions and 3 deletions

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 .

37
pool.js
View File

@ -107,7 +107,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));
} }
); );
} }
@ -220,7 +227,18 @@ function update_temp(temp) {
status.lock_update = true; status.lock_update = true;
status.temp = Math.round(temp * 10) / 10; 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); 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);
@ -260,7 +278,7 @@ function update_temp(temp) {
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 +290,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