@coyote @SidM
Mit dieser Version bin ich fast zufrieden. Die E-Mails kommen noch doppelt an, ohne dass ich den Grund erkenne.
var fs = require('fs');
var dest_path = '/var/lib/iobroker_files/';
var whole_path = '';
function extractEventData(message) {
const parsedMessage = JSON.parse(message);
let extractedJSON = {};
extractedJSON.eventtype = parsedMessage.type;
extractedJSON.beforecamera = parsedMessage.before.camera;
extractedJSON.beforelabel = parsedMessage.before.label;
extractedJSON.beforeid = parsedMessage.before.id;
extractedJSON.beforecurrentzones = parsedMessage.before.current_zones;
extractedJSON.beforeenteredzones = parsedMessage.before.entered_zones;
extractedJSON.beforeframetime = parsedMessage.before.frame_time;
extractedJSON.beforesnapshottime = parsedMessage.before.snapshot_time;
extractedJSON.aftercamera = parsedMessage.after.camera;
extractedJSON.afterlabel = parsedMessage.after.label;
extractedJSON.aftersnapshot_time = parsedMessage.after.snapshot_time;
extractedJSON.afterid = parsedMessage.after.id;
//extractedJSON.before.entered_zones {};
//parsedMessage.before.entered_zones.forEach(zone => {
// extractedJSON.before.entered_zones[zone.ZoneName] = zone.value.value;
//});
return extractedJSON;
}
on({id: [].concat(['mqtt.0.frigate.events']), change: "ne" }, function (obj) {
var value = obj.state.val;
var oldValue = obj.oldState.val;
const extractedJSON = extractEventData(obj.state.val);
const beforecamera = extractedJSON.beforecamera;
const beforelabel = extractedJSON.beforelabel;
const beforeid = extractedJSON.beforeid;
const beforeframetime = extractedJSON.beforeframetime;
const beforesnapshottime = extractedJSON.beforesnapshottime;
const aftercamera = extractedJSON.aftercamera;
const afterlabel = extractedJSON.afterlabel;
const aftersnapshot_time = extractedJSON.aftersnapshot_time;
const afterid = extractedJSON.afterid;
const eventtype = extractedJSON.eventtype;
//var data = getState('mqtt.0.frigate.carport.person.snapshot').val;
if (eventtype == 'update') {console.log('Script: Status_cctv Event: | '+eventtype+' | '+beforecamera+' | '+beforeid+' | '+beforelabel+' | '+beforeframetime+' | '+beforesnapshottime);}
if (eventtype == 'new') {console.log('Script: Status_cctv Event: | '+eventtype+' | '+beforecamera+' | '+beforeid+' | '+beforelabel+' | '+beforeframetime+' | '+beforesnapshottime);}
if (eventtype == 'end') {
exec('wget -O '+dest_path+beforeid+'.jpg http://cctv-prod.fritz.box:5000/api/events/'+beforeid+'/snapshot.jpg');
exec('wget -O '+dest_path+beforecamera+'-'+beforeid+'.jpg http://cctv-prod.fritz.box:5000/clips/'+beforecamera+'-'+beforeid+'.jpg');
//getBinaryState(idPic, async function (err, data){
// fs.writeFile('test.jpg', data, function (err) {
// if(err) log('Fehler!');
// });
//});
whole_path = dest_path;
whole_path += beforecamera;
whole_path += '-';
whole_path += beforeid;
whole_path += '.jpg';
//fs.writeFile(whole_path, data, (err) => {if (err) throw err;console.log('File written ' + whole_path);});
sendTo("email", "send", {
text: (['Script: Status_cctv Event: '+eventtype,'\n','Label:'+beforelabel,'\n','Camera:'+beforecamera,'\n','Eventtype:'+eventtype,'\n','Frame Time:'+beforeframetime,'\n','Snapshot Time:'+beforesnapshottime].join('')),
to: 'john@doe.cc',
subject: 'Script: Status_cctv Event: '+eventtype+' Camera:'+beforecamera+' Label:'+beforelabel+' v9',
attachments:[
{path: dest_path+beforecamera+'-'+beforeid+'.jpg', cid: "file1"}
//{path: dest_path+beforeid+'.jpg', cid: "file2"},
]
});
console.log('Script: Status_cctv Event: | '+eventtype+' | '+beforecamera+' | '+beforeid+' | '+beforelabel+' | '+beforeframetime+' | '+beforesnapshottime);
exec('/usr/bin/rm -f '+dest_path+beforecamera+'-'+beforeid+'.jpg');
exec('/usr/bin/rm -f '+dest_path+beforeid+'.jpg');
//sendTo("pushover.0", "send", {
// message: 'Script: Status_cctv Event: changed',
// sound: ""
//});
}
});