Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Initial support for Shelly Script comes with firmware version 0.9, September
## 2025-11
- Add script that allows to monitor data from Victron's Smartsolar charge controller.
## 2025-05

- Add examples of how to send and receive messages using the LoRa Addon.

## 2025-02
- Catch additional error conditions in n-way dimmer
## 2024-12
- Update some legacy code to the latest version.
## 2024-11
Expand Down
32 changes: 22 additions & 10 deletions n-way-dimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ function updateLocalKVS(currentState, cb) {
value: createLightValue(currentState),
}

Shelly.call("KVS.Set", kvpData, cb);
try {
Shelly.call("KVS.Set", kvpData, cb);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an async method, so it doesnt throw. Instead, any error is returned through the callback.

Copy link
Copy Markdown
Contributor Author

@tscofield tscofield Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spamming the buttons on two switches, after fixing the error that occurs from line 205/213, I get this exception

Exception shown by UI
✕ Uncaught Error: Too many calls in progress at Shelly.call("KVS.Set", kvpData, cb); ^ in function "updateLocalKVS" called from updateLocalKVS(currentStatus); ^ in function called from system

Additional details from logs output
Running setLocalDimmerStatus 01:03:30 {"on":true,"brightness":3} 01:03:30 Error: Set light status: Error: Error: Too many calls in progress 01:03:30 Status Handler intercept : {"component":"sys","name":"sys","id":-1,"delta":{"kvs_rev":188}} 01:03:30 Key Value Store has been updated 01:03:30 Update local setting 01:03:30 Running UpdateLightState: 01:03:30 ^ 01:03:30 in function "updateLocalKVS" called from updateLocalKVS(currentStatus); 01:03:30 ^ 01:03:30 in function called from system

} catch (err) {
console.log(err)
}
}


Expand Down Expand Up @@ -113,13 +117,17 @@ function syncKVSToDimmer(currentItem) {
// Loop through all the dimmers and send the KVS update
// This should only be called once a value has changed
function syncKVSToAll(currentStatus) {
for (let i = 0; i < CONFIG.dimmerGroup.length; i++) {
// Send data to all remote (skip the local IP)
if (CONFIG.dimmerGroup[i] !== CONFIG.wifiIP) {
currentStatus.ip = CONFIG.dimmerGroup[i];
syncKVSToDimmer(currentStatus);
try {
for (let i = 0; i < CONFIG.dimmerGroup.length; i++) {
// Send data to all remote (skip the local IP)
if (CONFIG.dimmerGroup[i] !== CONFIG.wifiIP) {
currentStatus.ip = CONFIG.dimmerGroup[i];
syncKVSToDimmer(currentStatus);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have those detail any longer. I'll have to see if I can reproduce, most of the testing that revealed where to add the try statements dealt with hitting multiple switches repeatedly.

}
}
} catch (err) {
console.log(err);
}
}
}

// ******************************************************************
Expand Down Expand Up @@ -202,7 +210,7 @@ function setLocalDimmerStatus(value) {
}
);
} catch (err) {
console.log("Error: Set light status: ", err)
console.log("Error: Set light status: ", err);
}
}

Expand All @@ -215,7 +223,11 @@ function createHandler() {

if (event.name === 'light' && event.delta && event.delta.brightness !== undefined) {
console.log("Someone changed the brightness or pressed the light switch, syncing with the other switches");
updateKVSState()
try {
updateKVSState();
} catch (err) {
console.log(err);
}
}

// Update dimmer control data
Expand All @@ -225,7 +237,7 @@ function createHandler() {
try {
updateLightState();
} catch (err) {
console.log(err)
console.log(err);
}
}
}
Expand Down