-
Autor
moin
ich mache hier mal eine neue Anfrage auf da die letzten Reaktionen zu dem in Folge benannten Skript von Ostfriese aus 2023 sind
erst einmal danke für den Skript, ich habe ihn durch Zufall entdeckt und es ist genau das was ich seit langem gesucht habe.
Bin zwar überzeugter und aktiver shelly Nutzer der ersten Stunden (> 80 Komponenten mit App / ifttt / Alexa etc. im System ) aber das Thema Skript ist leider nicht so meins.
Auch bei ibroker und homatic etc. möchte ich ( over 70 ) eigentlich nicht mehr einsteigen also sind Skripts für meine Anwendungen eigentlich eine gute Ergänzung
Habe das Skript von Ostfriese mit zwei Handys für unsere Alarmanlage in Funktion und es läuft perfekt bis auf die Nachtschaltung. Wenn wir die Anlage zur Nacht aktivieren möchten sind ja beide Handys im Haus und der Skript schaltet korrekt sofort wieder aus. Jeweils beide Handys jeden Abend aus dem WLAN nehmen ist sicher eine Lösung macht aber nicht wirklich Sinn.
Ergo hoffe ich hier einen Profi zu finden der hier eine Ergänzung des Skripts erstellt oder eine andere praktikable Idee um eine Zeitspanne zu schaffen in der der trotz Anwesenheit beider Handys eine Aktivierung der Alarmanlage möglich ist.
Jetzt schon mal danke an alle die sich hier Gedanken machen und vielleicht eine Lösung finden
Damit nicht gesucht werden muss füge den Skript von Ostfriese hier nochmalig an
Gruß Detlev
Code
//GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
//More information: https://www.gnu.org/licenses/gpl-3.0.txt
//ABSOLUTELY NO WARRANTY!!!
//Made by Ostfriese
//############################## Config ############################
let Config = {
ips: ["172.16.0.193", "172.16.0.199", "172.16.0.132", "172.16.0.153","172.16.0.185"],
names: ["Peter", "Paul", "Marie", "Otto", "Willy"],
first_user_in_action : "http://172.16.0.102/relay/0?turn=on",
last_user_out_action : "http://172.16.0.52/relay/0?turn=off",
user_action_online : ["http://172.16.0.48/relay/0?turn=on&timer=25",
"http://172.16.0.59/relay/0?turn=on&timer=5",
"",
"",
""],
user_action_offline : ["",//"http://172.16.0.100/relay/0?turn=off",
"",//"http://172.16.0.10/relay/0?turn=off",
"",
"",
""],
timeout : 1,
verbose : false,
buffer : 30
}
//############################## Config end ############################
let busy = false;
let users_online_array = [];
let offline_buffer_array = [];
let empty_house = true;
let i = 0;
function log(to_log) {
if(Config.verbose) {
print(to_log);
}
}
function count_absent() {
// count absent users
false_count = 0;
for(let k = 0; k < Config.ips.length; k++) {
if(users_online_array[k] === false) {
false_count += 1;
}
}
// if all users are absent
if(false_count === Config.ips.length) {
log("Config.last_user_out_action :", Config.last_user_out_action);
// call last_user_out_action
Shelly.call("http.get", {url: Config.last_user_out_action, timeout: Config.timeout});
// set house to empty
empty_house = true;
return;
}
// if house was empty
if (empty_house) {
log("Config.first_user_in_action :", Config.first_user_in_action);
// call first_user_in_action
Shelly.call("http.get", {url: Config.first_user_in_action, timeout: Config.timeout});
// set house to 'someone in'
empty_house = false;
}
}
// find next index
function iterate_index() {
if(i < Config.ips.length - 1) {
i += 1;
return;
}
i = 0;
}
function ping() {
try {
// return if already busy
if (busy === true) {
return;
}
busy = true;
ip = Config.ips[i];
// do a ping
Shelly.call("http.get", {url: ip, timeout: Config.timeout},
function(result, error_code, error_message) {
if(error_message === "-1: Connection error: -14") {;
// check if status changed from absent to present
if(users_online_array[i] === false || users_online_array[i] === '') {
print(Config.names[i], "online");
log("Config.user_action_online[" + i + "] :", Config.user_action_online[i]);
// call specific user action for present
Shelly.call("http.get", {url: Config.user_action_online[i], timeout: Config.timeout});
// set user to present in users_online_array
users_online_array[i] = true;
// check how much users present
count_absent();
}
users_online_array[i] = true;
offline_buffer_array[i] = Shelly.getComponentStatus("sys").unixtime;
// get index of next user
iterate_index();
busy = false;
return;
}
// check if user offline for longer than buffer seconds
t = Shelly.getComponentStatus("sys").unixtime - offline_buffer_array[i];
if((users_online_array[i] === true && t > 60) || users_online_array[i] === '') {
print(Config.names[i], "offline");
log("Config.user_action_offline[" + i + "] :", Config.user_action_offline[i]);
// call specific user action for absent
Shelly.call("http.get", {url: Config.user_action_offline[i], timeout: Config.timeout});
// set user to absent in users_online_array
users_online_array[i] = false;
// check how much users absent
count_absent();
}
// get index of next user
iterate_index();
busy = false;
return;
})
// catch errors
} catch(err) {
busy = false;
}
}
// set ping timer
function start() {
Timer.set(10,true,ping);
}
// set all users to absent
for(let j = 0; j < Config.ips.length; j++) {
users_online_array.push('');
offline_buffer_array.push(Shelly.getComponentStatus("sys").unixtime);
//print(Config.names[j], "offline");
}
// wait 1 second before start to avoid error after reboot
Timer.set(1000,false,start);
Alles anzeigen