@asgothian ok das habe ich Versanden.
das Problem was ich jetzt habe ist wenn beide Bedingungen erfüllt sind würd die Aktion ausgeführt. So ball ich eine ändere ist die Aktion aktiv. Was sie eigentlich nich sein dürfte. Muss ich da was zurückstellen?
Meine Cod sieht aktuell so aus:
// Konfiguration
// -------------------------------------------------------------------------
//2. Bewerbungs angabe
const bewegung02 ="mqtt.1.Philipp_Lindner_Überwachung.arlamStatus";
// Objekt-ID des Bewegungsmelders
const bewegung01 = "mqtt.1.Philipp_Lindner_Überwachung.cameras.flurcam_01.motion";
// URL zur Kamera um ein Image (jpg) zu erhalten
const cam_url = "http://192.168.1.23:8090/grab.jpg?oid=2&size=1280x720";
// Pfadangabe für die Speicherung der Bilder, der Pfad muss existieren
const dest_path = '/opt/iobroker/temp/cam';
// Anzahl der Bilder, die vorgehalten werden sollen
const imageCountMax = 4;
// Prefix für die Bildnamen
const imageNamePre = "Flur_";
// -------------------------------------------------------------------------
// Scriptteil
// -------------------------------------------------------------------------
var request = require('request');
var fs = require('fs');
var Alarmanlage_status = getState(bewegung02).val;
// Bild an telegram schicken
function sendImage (path) {
try {
var stats = fs.statSync(path);
var msg = formatDate(stats.birthtime,"DD.MM.YYYY hh:mm:ss") + " " + path.substring(path.lastIndexOf('/')+1);
sendTo('telegram.0', {
text: path,
caption: msg,
disable_notification: true
});
}
catch(err) { if (err.code != "ENOENT") log(err); }
}
// löscht eine Datei synchron (wartet auf das Ergebnis)
function fsUnlinkSync(path) {
try {
var stats = fs.statSync(path);
try { fs.unlinkSync(path); }
catch(err) { if (err.code != "ENOENT") log(err); }
}
catch(err) { if (err.code != "ENOENT") log(err); }
}
// benennt eine Datei synchron um (wartet auf das Ergebnis)
function fsRenameSync(oldPath, newPath) {
try {
var stats = fs.statSync(oldPath);
try { fs.renameSync(oldPath, newPath); }
catch(err) { if (err.code != "ENOENT") log(err); }
}
catch(err) { if (err.code != "ENOENT") log(err); }
}
// Bild speichern und senden
function saveImage() {
// Bild imageCountMax-1 löschen
fsUnlinkSync( dest_path + imageNamePre + (imageCountMax-1) + ".jpg" );
// Bilder 0..imageCountMax-2 umbenennen
for (var i=imageCountMax-2; i >= 0; i-- ) {
fsRenameSync(dest_path + imageNamePre + i + ".jpg", dest_path + imageNamePre + (i+1) + ".jpg");
}
// Bild 0 löschen
var fname = imageNamePre + "0.jpg";
fsUnlinkSync( fname );
// Bild holen und speichern
request.get({url: cam_url, encoding: 'binary'}, function (err, response, body) {
fs.writeFile(dest_path + fname, body, 'binary', function(err) {
if (err) {
log('Fehler beim Bild speichern: ' + err, 'warn');
} else {
// dem Filesystem 2 Sek Zeit zum Speichern lassen
setTimeout(function() { sendImage(dest_path + fname); }, 2000);
}
});
});
}
// sofort ein Bild senden und nach 10 Sek erneut
function onEvent(t) {
saveImage();
setTimeout(function() { saveImage(t); }, 10 * 1000);
log('onEVenter go ('+t+')', 'info');
}
// Ereignisroutine
/*function auloeser(){
log('Überwachunbg test start', 'info');
on({id:bewegung02, change:'ne'}, function(obj) {Alarmanlage_status=obj.state.val;})
if (Alarmanlage_status =="1"){
log('Arlame Scharf!','info');
on({id:bewegung01, val:true}, function(obj){onEvent(obj); log ('BEWEGUNG!','info');})
}
log('test ende', 'info');
}*/
let Alarmanlage_status2 = 0;
on({id:bewegung02, change:'ne'}, function(obj) {Alarmanlage_status=obj.state.val;});
on({id:bewegung01, val:true}, function(obj){onEvent(obj); if (Alarmanlage_status == 1){log('BEWEGUNG!','info');}});
//schedule("*/5 * * * * *", function(){ auloeser()});
// manuelle Ausführung (Test)
onEvent("test");
Nachtrag: so das Problem habe ich jetzt gelöst, bin selber bescheuert umd habe den fehler nicht gesehen:
let Alarmanlage_status2 = 0;
on({id:bewegung02, change:'ne'}, function(obj) {Alarmanlage_status=obj.state.val;});
on({id:bewegung01, val:true}, function(obj){if (Alarmanlage_status == 1){onEvent(obj); log('BEWEGUNG!','info');}});
Danke an @Asgothian für die auf klährung.