@paul53 sagte in Auslöser ermitteln:
@michihorn sagte: Ja String,
Dann muss mit "true" verglichen und "false" gesetzt werden.
Ja das ist der Plan.
Das Projekt soll eine Anwesenheitüberwachung für meine 3 Familienmitglieder im Geo Umkreis von 500 Meter machen, das klappt auch. Ich habe zwei weitere Dienste im IOT hinterlegt "Ankunft" triggert an der Grenze zu Holland und schaltet schon mal den Kühlschrank im Ferienhaus ein, stellt die Heizung/Klima auf 21Grad. 1h 20 min reichen aus.
Ein weiter Dienst heisst Heimreise und der löst schon 30 km nach dem Verlassen des FH aus, Kühlschrank aus, Heizung auf 10 Grad. Der Hintergrund meiner Anfrage ist das Gegeseitige verriegeln von Anreise und Heimreise. Wenn ich z.B Heimreise soll falls meine Frau oder der Sohn noch vor Ort bleiben, nur mein Dienst "Anreise" auf false gesetzt werden.
Das Script für Anreise sieht so aus:
/*****GEOfancy ANREISE *****************************************
** Januar 2022
** IOT, EgiGeo
** (true), (false)
** erstellt: 24.01.22,
** geändert: 14.06.23
***********************************************************************/
var logging = true;
const idFrigo = "tuya.0.bfce754681c6e2c8faowag.2"
const idMedia = "tuya.0.bf292a4c8b62843697ntvv.1"
const idTempIn = "tuya.0.73103057e868e768284a.3"
const idHeizung = "tuya.0.73103057e868e768284a.2"
const idAirCo = "daikin.0.control.power"
const idAW = "0_userdata.0.Giethoorn.AW.AW"
const ids = $('iot.*.services.custom_Anreise');
const idCnt = "0_userdata.0.Giethoorn.AW.Anreise"
var text
function cntAnreise() {
let cnt = 0;
ids.each(function (id, i) {
if (getState(id).val == 'true') cnt++;
});
setState(idCnt, cnt, true);
if (getState(idCnt).val >= 1) {
log("Anreise erkannt")
setState(idFrigo, true)
setState(idMedia, true)
setState(idHeizung, 22)
text = '\ud83d\ude98 Anreise von 🇩🇪 nach 🇳🇱 erkannt '
createEventlog("GTHRN", text)
if (logging) sendTo('whatsapp-cmb.0', 'send', { text, phone: '+491xxxxx' });
if ((getState(idTempIn).val >= 30)) {
setState(idAirCo, true)
}
}
};
cntAnreise(); // Skriptstart
ids.on(cntAnreise);
EDIT: Anbei der Objektbaum vom IOT
Screenshot 2023-10-16 152935.png
Als Lösung funktioniert nun folgendes Script:
/*****GEOfancy ANREISE *****************************************
** Januar 2022
** IOT, EgiGeo
** (true), (false)
** erstellt: 24.01.22,
** geändert: 14.06.23
***********************************************************************/
var logging = true;
const idFrigo = "tuya.0.bfce754681c6e2c8faowag.2"
const idMedia = "tuya.0.bf292a4c8b62843697ntvv.1"
const idTempIn = "tuya.0.73103057e868e768284a.3"
const idHeizung = "tuya.0.73103057e868e768284a.2"
const idAirCo = "daikin.0.control.power"
const ids = $('iot.*.services.custom_Anreise');
const idCnt = "0_userdata.0.Giethoorn.AW.Anreise"
var text
function cntAnreise() {
let cnt = 0;
ids.each(function (id, i) {
if (getState(id).val == 'true') cnt++;
});
setState(idCnt, cnt, true);
if (getState(idCnt).val >= 1) {
log("Anreise erkannt")
setState(idFrigo, true)
setState(idMedia, true)
setState(idHeizung, 22)
text = '\ud83d\ude98 Anreise von 🇩🇪 nach 🇳🇱 erkannt '
createEventlog("GTHRN", text)
if (logging) sendTo('whatsapp-cmb.0', 'send', { text, phone: '+491xxxx149' });
if ((getState(idTempIn).val >= 30)) {
setState(idAirCo, true)
}
}
};
cntAnreise(); // Skriptstart
ids.on(cntAnreise);
var newstring
ids.each(function (id) { // Skriptstart
if (getState(id).val)
setState(id, true);
});
ids.on(function (dp) {
if (dp.state.val) {
log("INFO: " + dp.id);
var string = dp.id
newstring = string.replace("custom_Anreise", "custom_Heimreise");
log("Ergebnis: " + newstring)
setState(newstring, "false")
}
});
Und für die Heimreise sieht das Script dann so aus.
/*****GEOfancy HEIMREISE *****************************************
** Januar 2022
** IOT, EgiGeo
** (true), (false)
** erstellt: 24.01.22,
** geändert: 14.6.23
***********************************************************************/
var logging = true;
const idFrigo = "tuya.0.bfce754681c6e2c8faowag.2"
const idMedia = "tuya.0.bf292a4c8b62843697ntvv.1"
const idTempIn = "tuya.0.73103057e868e768284a.3"
const idHeizung = "tuya.0.73103057e868e768284a.2"
const idAirCo = "daikin.0.control.power"
const idAW = "0_userdata.0.Giethoorn.AW.AW"
const ids = $("iot.*.services.custom_Heimreise");
const idCnt = "0_userdata.0.Giethoorn.AW.Heimreise"
var text
function cntHeimreise() {
let cnt = 0;
ids.each(function (id, i) {
if (getState(id).val == 'true') cnt++;
});
setState(idCnt, cnt, true);
if (getState(idCnt).val >= 1) {
log("Heimreise erkannt")
setState(idFrigo, false)
setState(idMedia, false)
setState(idHeizung, 10)
setState(idAirCo, false)
text = '\ud83d\ude98 Heimreise von 🇳🇱 nach 🇩🇪 erkannt '
createEventlog("GTHRN", text)
if (logging) sendTo('whatsapp-cmb.0', 'send', { text, phone: '+49xxxxx149' });
}
};
cntHeimreise(); // Skriptstart
ids.on(cntHeimreise);
var newstring
ids.each(function (id) { // Skriptstart
if (getState(id).val)
setState(id, true);
});
ids.on(function (dp) {
if (dp.state.val) {
log("INFO: " + dp.id);
var string = dp.id
newstring = string.replace("custom_Heimreise", "custom_Anreise");
log("Ergebnis: " + newstring)
setState(newstring, "false")
}
});