init
parent
e2bec7304a
commit
1c6e0b0491
@ -0,0 +1,41 @@
|
||||
// Durchläuft alle Shelly-Geräte des Shelly-Adapters und setzt den definierten History-Block, damit die Datenpunkte in der History auftauchen. History-Adapter muss installiert sein.
|
||||
|
||||
addHistoryToState("online");
|
||||
stopScript("script.js.Shelly.AddShellyStatesToHistory");
|
||||
|
||||
function addHistoryToState(state) {
|
||||
let hist = { // read out from example
|
||||
"history.0": {
|
||||
"enabled": true,
|
||||
"aliasId": "",
|
||||
"debounceTime": 0,
|
||||
"blockTime": 0,
|
||||
"changesOnly": true,
|
||||
"changesRelogInterval": 10,
|
||||
"changesMinDelta": 0,
|
||||
"ignoreBelowNumber": "",
|
||||
"disableSkippedValueLogging": false,
|
||||
"retention": "31536000",
|
||||
"customRetentionDuration": 365,
|
||||
"maxLength": 960,
|
||||
"enableDebugLogs": false,
|
||||
"debounce": 0
|
||||
}
|
||||
};
|
||||
|
||||
$('[id=shelly.0.*.' + state + ']').each(function (id, i) {
|
||||
let obj = getObject(id);
|
||||
let custom = obj.common.custom;
|
||||
let combined = {
|
||||
...custom,
|
||||
...hist
|
||||
};
|
||||
|
||||
log(id);
|
||||
log("custom: " + JSON.stringify(custom));
|
||||
log("new: " + JSON.stringify(hist));
|
||||
log("combined: " + JSON.stringify(combined));
|
||||
obj.common.custom = combined;
|
||||
setObject(id, obj); // shows error but is no error
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
// Bezieht Onlinezeit %/24h aus History-Daten und speichert sie stündlich in Datenpunkten. Vorher muss AddShellyStatesToHistory ausgeführt worden sein. Sendet eine Benachrichtigung bei weniger als 95%-
|
||||
|
||||
run();
|
||||
|
||||
schedule('{"time":{"start":"00:00","end":"23:59","mode":"hours","interval":1},"period":{"days":1}}', async function () {
|
||||
run();
|
||||
});
|
||||
|
||||
function run()
|
||||
{
|
||||
$('[id=shelly.0.*.online]').each(function(id, i)
|
||||
{
|
||||
setOnlinePercentage(id);
|
||||
});
|
||||
}
|
||||
|
||||
function setOnlinePercentage(onlineId)
|
||||
{
|
||||
var name = getState(onlineId.replace("online", "name")).val;
|
||||
var objectIdOutput = "0_userdata.0.ShellyDebug.OnlineTime." + name;
|
||||
|
||||
createState(objectIdOutput, true, {
|
||||
"name": name,
|
||||
"type": "number",
|
||||
"desc": "",
|
||||
"read": true,
|
||||
"write": true,
|
||||
"unit": "%"
|
||||
});
|
||||
|
||||
addHistoryToState(objectIdOutput);
|
||||
|
||||
var end = Date.now();
|
||||
sendTo('history.0', 'getHistory', {
|
||||
id: onlineId,
|
||||
options: {
|
||||
start: end - 3600000*24,
|
||||
end: end,
|
||||
aggregate: 'none',
|
||||
count: 99999999
|
||||
}
|
||||
}, function (result) {
|
||||
//console.log("#Results: " + result.result.length);
|
||||
var numberGood = 0;
|
||||
var numberBad = 0;
|
||||
|
||||
for (var i = 0; i < result.result.length; i++) {
|
||||
if (result.result[i].val == true)
|
||||
{
|
||||
numberGood++;
|
||||
}
|
||||
else if (result.result[i].val == false)
|
||||
{
|
||||
numberBad++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//console.log(result.result[i]);
|
||||
}
|
||||
}
|
||||
//console.log("#good: " + numberGood);
|
||||
//console.log("#bad: " + numberBad);
|
||||
var percentageGood = numberGood / (numberGood + numberBad) * 100
|
||||
percentageGood = Math.round(percentageGood * 1000) / 1000;
|
||||
log(name + ": " + percentageGood + "%");
|
||||
|
||||
let stateBefore = getState(objectIdOutput).val;
|
||||
if (stateBefore >= 95 && percentageGood < 95)
|
||||
{
|
||||
sendTo("telegram", "send", {
|
||||
text: "Der Shelly " + name + " hat innerhalb der vergangenen 24 Stunden eine Onlinezeit von nur " + percentageGood + "%."
|
||||
});
|
||||
}
|
||||
setState(objectIdOutput, percentageGood, true);
|
||||
});
|
||||
}
|
||||
|
||||
function addHistoryToState(state) {
|
||||
let hist = {
|
||||
"history.0": {
|
||||
"enabled": true,
|
||||
"aliasId": "",
|
||||
"debounceTime": 0,
|
||||
"blockTime": 0,
|
||||
"changesOnly": true,
|
||||
"changesRelogInterval": 1800,
|
||||
"changesMinDelta": "0",
|
||||
"ignoreBelowNumber": "",
|
||||
"disableSkippedValueLogging": false,
|
||||
"retention": "31536000",
|
||||
"customRetentionDuration": 365,
|
||||
"maxLength": 48,
|
||||
"enableDebugLogs": false,
|
||||
"debounce": "0"
|
||||
}};
|
||||
|
||||
|
||||
let obj = getObject(state);
|
||||
let custom = obj.common.custom;
|
||||
let combined = {
|
||||
...custom,
|
||||
...hist
|
||||
};
|
||||
|
||||
log(state);
|
||||
log("custom: " + JSON.stringify(custom));
|
||||
log("new: " + JSON.stringify(hist));
|
||||
log("combined: " + JSON.stringify(combined));
|
||||
obj.common.custom = combined;
|
||||
setObject(state, obj); // shows error but is no error
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
// Führt auf allen Shellys Firmware-Updates durch. Zur Überprüfung der Versionen: ShowFirmware-Script
|
||||
|
||||
runFirmwareUpdates();
|
||||
stopScript("script.js.Shelly.RunFirmwareUpdates");
|
||||
|
||||
function runFirmwareUpdates() {
|
||||
$('[id=shelly.0.*.firmwareupdate]').each(function(id, i)
|
||||
{
|
||||
log("Running firmware update of " + id);
|
||||
setState(id, true);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue