@Horst-Böttcher das "Uhula-Script" geht gut. Hier auch mit motion eye Bild:
// -------------------------------------------------------------------------
// Dieses Script überwaht den Zustand eines Bewegungsmelders und speichert bei
// Aktivierung ein Bild einer Überwachnungskamera in einem Vereichnis und sendet
// dieses via Telegram.0-Adapter. Nach 10 Sek wird ein weiteres Bild erstellt und
// gesendet.
// Die Speicherung der Bilder erfolgt als "Stack", d.h. das aktuellste Bild bekommt
// immer den Suffix "0" und es werden n Bilder mit den Suffixen 1..n-1 vorgehalten
// Uhula 2017.11
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Konfiguration
// -------------------------------------------------------------------------
//Edimax Detection Variable anlegen:
//createState('javascript.0.Variablen.Edimax-detection2', false, //Edimax-detection für VIS-Darstellung
//{type: 'boolean', name: 'Edimax-detection', min: false, max: true, read: true, write: true, role: 'javascript' });
// Objekt-ID des Bewegungsmelders
const oidLichtBewmelderTuer = '0_userdata.0.Cam.tapo_C200.motion_detected_extern'/*motion detected extern*/;
// URL zur Kamera umn ein Image (jpg) zu erhalten
const cam_url = "http://192.168.1.25:8765/picture/2/current/";
// Pfadangabe für die Speicherung der Bilder, der Pfad muss existieren
const dest_path = '/opt/iobroker/iobroker-data/files/vis.0/cams/edimax/';
// Anzahl der Bilder, die vorgehalten werden sollen
const imageCountMax = 8;
// Prefix für die Bildnamen
const imageNamePre = "tapo_";
// -------------------------------------------------------------------------
// Scriptteil
// -------------------------------------------------------------------------
var request = require('request');
var fs = require('fs');
// 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.1', {
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 4 Sek erneut
function onEvent() {
saveImage();
setTimeout(function() { saveImage(); }, 4 * 1000);
// setTimeout(function() { saveImage(); }, 9 * 1000);
}
// Ereignisroutine
on({id: oidLichtBewmelderTuer, val: true}, function (obj) {
onEvent( obj );
});
// manuelle Ausführung (Test)
onEvent();