Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. [Frage BLOCKLY ] Klingel Bild per Telegram versenden / Snapshot von Cam per Telegram versenden

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [Frage BLOCKLY ] Klingel Bild per Telegram versenden / Snapshot von Cam per Telegram versenden

    This topic has been deleted. Only users with topic management privileges can see it.
    • dslraser
      dslraser Forum Testing Most Active @davimas last edited by

      @davimas
      Der von Dir verlinkte Beitrag ist wohl bei der Forumumstellung kaputt gegangen, das Blockly steht da in zwei teilen. Ich habe das mal zusammen kopiert und dann importiert, dabei kommt dann das hier raus:

      <xml xmlns="http://www.w3.org/1999/xhtml">
       <variables>
         <variable type="undefined" id="timeout">timeout</variable>
         <variable type="undefined" id="timeout2">timeout2</variable>
         <variable type="undefined" id="timeout3">timeout3</variable>
       </variables>
       <block type="on_ext" id="jj8??y8iv{!Fb0^jZ!" x="-438" y="-262">
         <mutation items="1"></mutation>
         <field name="CONDITION">ne</field>
         <field name="ACK_CONDITION"></field>
         <value name="OID0">
           <shadow type="field_oid" id="XEKh|+XF~3OC@EHY5{8{">
             <field name="oid">mihome.0.devices.sensor_motion_aq2_158d0001e514d4.state</field>
           </shadow>
         </value>
         <statement name="STATEMENT">
           <block type="controls_if" id="xXlCTj)t?n*Gg:j44f#Y">
             <value name="IF0">
               <block type="logic_compare" id="pMPW|b)g/=L3!yP`vsW6">
                 <field name="OP">EQ</field>
                 <value name="A">
                   <block type="get_value" id="5c7%aB|)K}(rNJ)#Jzd1">
                     <field name="ATTR">val</field>
                     <field name="OID">mihome.0.devices.sensor_motion_aq2_158d0001e514d4.state</field>
                   </block>
                 </value>
                 <value name="B">
                   <block type="logic_boolean" id="Lhj]yTw*W`/`leEqri.g">
                     <field name="BOOL">TRUE</field>
                   </block>
                 </value>
               </block>
             </value>
             <statement name="DO0">
               <block type="comment" id="eogMqz*f:xk9TWEY/!4#">
                 <field name="COMMENT">Speichert das erste Bild bei Erkennung einer Bewegung</field>
                 <next>
                   <block type="exec" id="BEjD=u,#e-;T;d-e9D;r">
                     <mutation with_statement="false"></mutation>
                     <field name="WITH_STATEMENT">FALSE</field>
                     <field name="LOG"></field>
                     <value name="COMMAND">
                       <shadow type="text" id="p+g^=?Sl15wP.0/4C~~B">
                         <field name="TEXT">wget --output-document /opt/iobroker/ipcam/alarm.jpg 'http://benutzer:passwort@192.168.0.55/Streaming/channels/1/picture'</field>
                       </shadow>
                     </value>
                     <next>
                       <block type="comment" id="qm0bnl/,Dq4PjA`4!8ao">
                         <field name="COMMENT">Es wird 2500ms gewartet um dieses speichern auszuführen</field>
                         <next>
                           <block type="timeouts_settimeout" id="e=c#~E)j;S+#onaowS77">
                             <field name="NAME">timeout</field>
                             <field name="DELAY">2500</field>
                             <field name="UNIT">ms</field>
                             <statement name="STATEMENT">
                               <block type="comment" id="cLfsL/.hZGyA%n?O!-:5">
                                 <field name="COMMENT">Und hier wird es versendet</field>
                                 <next>
                                   <block type="telegram" id="FbkrL,IGK%]5xBi#Yj,=">
                                     <field name="INSTANCE">.0</field>
                                     <field name="LOG"></field>
                                     <field name="SILENT">FALSE</field>
                                     <field name="PARSEMODE">default</field>
                                     <value name="MESSAGE">
                                       <shadow type="text" id="wXLWD;.*8||`3_5J8(UB">
                                         <field name="TEXT">/opt/iobroker/ipcam/alarm.jpg</field>
                                       </shadow>
                                     </value>
                                   </block>
                                 </next>
                               </block>
                             </statement>
                             <next>
                               <block type="comment" id="Fu=MNqw/7gDC_n{i|=UN">
                                 <field name="COMMENT">Nach dem ersten Bild wird nach 4000ms das nächste Bild gespeichert</field>
                                 <next>
                                   <block type="timeouts_settimeout" id="f55+L@!5F9d*i7)8.z}-">
                                     <field name="NAME">timeout2</field>
                                     <field name="DELAY">4000</field>
                                     <field name="UNIT">ms</field>
                                     <statement name="STATEMENT">
                                       <block type="exec" id="d~FCu]aLbH_s[eN3oB3H">
                                         <mutation with_statement="false"></mutation>
                                         <field name="WITH_STATEMENT">FALSE</field>
                                         <field name="LOG"></field>
                                         <value name="COMMAND">
                                           <shadow type="text" id="q^pJl9(1bxjm4FLFJFlT">
                                             <field name="TEXT">wget --output-document /opt/iobroker/ipcam/alarm.jpg 'http://benutzer:passwort@192.168.0.55/Streaming/channels/1/picture'</field>
                                           </shadow>
                                         </value>
                                         <next>
                                           <block type="comment" id="KW^QIsb%Axd:Sp^9@vZ%">
                                             <field name="COMMENT">Es wird 2500ms gewartet um dieses speichern auszuführen</field>
                                             <next>
                                               <block type="timeouts_settimeout" id="kqLD0XWHPVb*R%96uP;%">
                                                 <field name="NAME">timeout3</field>
                                                 <field name="DELAY">2500</field>
                                                 <field name="UNIT">ms</field>
                                                 <statement name="STATEMENT">
                                                   <block type="comment" id="Vo3{l~+:~RYcTronq]q*">
                                                     <field name="COMMENT">Und hier wird es versendet</field>
                                                     <next>
                                                       <block type="telegram" id="3p`vo?Dq*N;FLI4BR{`q">
                                                         <field name="INSTANCE">.0</field>
                                                         <field name="LOG"></field>
                                                         <field name="SILENT">FALSE</field>
                                                         <field name="PARSEMODE">default</field>
                                                         <value name="MESSAGE">
                                                           <shadow type="text" id="GsAgr]aq}s-1MR0mg|-W">
                                                             <field name="TEXT">/opt/iobroker/ipcam/alarm.jpg</field>
                                                           </shadow>
                                                         </value>
                                                       </block>
                                                     </next>
                                                   </block>
                                                 </statement>
                                               </block>
                                             </next>
                                           </block>
                                         </next>
                                       </block>
                                     </statement>
                                     <next>
                                       <block type="comment" id="ma^~d4aFY-ahr*7)hhQy">
                                         <field name="COMMENT">ab hier so oft wiederholen wie man es möchte</field>
                                       </block>
                                     </next>
                                   </block>
                                 </next>
                               </block>
                             </next>
                           </block>
                         </next>
                       </block>
                     </next>
                   </block>
                 </next>
               </block>
             </statement>
           </block>
         </statement>
       </block>
      </xml>
      

      D 1 Reply Last reply Reply Quote 0
      • D
        davimas @dslraser last edited by davimas

        @dslraser

        Danke Dir.
        Arbeite mich da erst vor kurzem rein, in Blockly und sehe erst jetzt dass der "Aufbau" des Textes passen muss. Gerade eben erfolgreich deinen Fensterzählscript mit Telegramm eingebunden und auf meine Installation abgeändert 👍
        Ist echt einfacher als Javascripts :-))

        1 Reply Last reply Reply Quote 0
        • R
          Roelli last edited by

          Nabend!

          Also ein GIF von der Kamera ist echt bisher das geilste was im Bereich Smarthome gesehen habe. (besser als Push-Nachrichten und emails von Fotos auf's Handy)

          Aber ich bekomme es nicht stabil hin.
          ffmpeg hab ich installiert, ich kann auch einwandfrei ein Bild erzeugen. Aber nur EIN mal. Wenn ich danach den gleichen Befehl wieder abrufe - dann kommt kein Bild. (nur ein Gif ohne Bild, aber mit richtiger Uhrzeit drin)

          Ich komme einfach nicht drauf was das Problem ist. Jemand eine Idee?
          (Telegram-Nachricht habe ich 1000mS verzögert damit ffmpeg Zeit hat das GIF zu erzeugen)

          Danke!

          1 Reply Last reply Reply Quote 0
          • Knallochse
            Knallochse last edited by

            @Uhula Ich habe dein Script gerade ausprobiert. Die Bilder lasse ich mir unter Vis.0 in Unterordnern abspeichern (welche ich mit dem Vis Editor erzeugt habe - wegen Rechte).
            Diese Snapshots werden auch erzeugt. Nur leider kann ich mit dem Widget basicImage keine der Snapshots auswählen (Ordner wird leer angezeigt)
            Eine Idee wie ich die Snapshots in meine Vis bekomme?

            crunchip 1 Reply Last reply Reply Quote 0
            • crunchip
              crunchip Forum Testing Most Active @Knallochse last edited by

              @Knallochse das geht nicht mehr siehe https://forum.iobroker.net/post/309472
              siehe auch hier https://forum.iobroker.net/topic/25541/gelöst-wie-writefile-in-js-script-nutzen
              vllt kannst du dieses gebrauchen https://forum.iobroker.net/post/349575

              Knallochse 1 Reply Last reply Reply Quote 1
              • Knallochse
                Knallochse @crunchip last edited by

                @crunchip Dankeschön 👍

                1 Reply Last reply Reply Quote 0
                • Knallochse
                  Knallochse last edited by

                  Ich habe mich jetzt mal in die Problematik mit dem Speichern von Bildern reingelesen.
                  Eigentlich sollte das speichern in den Vis.0 Ordner ja noch funktionieren.
                  Ich habe aber keine Programmierkenntnisse, deshalb die Bitte ob mir bitte jemand bei dem Umschreiben des Scriptes von @Uhula helfen könnte.

                  // -------------------------------------------------------------------------
                  // 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
                  // -------------------------------------------------------------------------
                     // Objekt-ID des Bewegungsmelders
                  const oidLichtBewmelderTuer = "shelly.0.SHSW-1#2C6E3A#1.Relay0.Switch";
                     // URL zur Kamera umn ein Image (jpg) zu erhalten
                  const cam_url = "http://admin:XXXXXXXX@192.168.178.51:80/tmpfs/auto.jpg";
                     // Pfadangabe für die Speicherung der Bilder, der Pfad muss existieren
                  const dest_path = '/opt/iobroker/iobroker-data/files/vis.0/Kameras/ParkplatzStrasse/';
                     // Anzahl der Bilder, die vorgehalten werden sollen
                  const imageCountMax = 8;                
                     // Prefix für die Bildnamen
                  const imageNamePre = "ParkplatzStrasse_"; 
                  // -------------------------------------------------------------------------
                  // 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.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 8 Sek erneut
                  function onEvent() {
                      saveImage();
                      setTimeout(function() { saveImage(); }, 8 * 1000); 
                  }
                  // Ereignisroutine
                  on({id: oidLichtBewmelderTuer, val: true}, function (obj) {
                      onEvent( obj );
                  });
                  // manuelle Ausführung (Test)
                  onEvent();
                  
                  
                  crunchip Glasfaser 2 Replies Last reply Reply Quote 0
                  • crunchip
                    crunchip Forum Testing Most Active @Knallochse last edited by

                    @Knallochse kann dir zwar nicht direkt behilflich sein. Jedoch kannst du auf die schnelle einfach ausserhalb von "/opt/iobroker/iobroker-data/files/vis.0/" deine Bilder ablegen. Also z.b. "/opt/iobroker/Kameras/"
                    Dann würde es normal funktionieren. Nachteil, ... BackitUp, da die Daten ausserhalb von ...data/files liegen, würden diese verloren gehn
                    Da ich, wenn mal nötig ein Backup mittels Proxmox zurück spiele, spielt es in meinem Fall keine Rolle.

                    1 Reply Last reply Reply Quote 0
                    • Glasfaser
                      Glasfaser @Knallochse last edited by

                      @Knallochse

                      Ich habe das hier so bei mir angepasst (Vorlage von Chaot) :

                      Es werde 4 Screenshot´s erstellt , per Telegramm versendet und in vis.0/klingelbild zur weiteren Verwendung hinterlegt .

                      Datenpunkt in const idklingel und die vier URL anpassen .

                      const idklingel = ["hm-rpc.2.00145709AED72D.8.PRESS_SHORT", "hm-rpc.2.00145709AED72D.8.PRESS_LONG", "ID5", "ID4"];
                      
                      var sperre = false;  //verhindert das doppeltes Drücken das Script stoppt
                      
                      var timeout1, timeout2, timeout3, timeout4, timeout5, timeout6, timeout7, timeout8, timeout9, timeout10, timeout11;
                      
                      var fs = require('fs');
                      
                      
                      
                      
                      on({id: idklingel, change: "any"}, function (obj) {
                      
                       if(!sperre) {
                      
                         sperre = true;
                      
                         
                      
                          // Speichert das erste Bild bei Klingeln
                      
                         exec('wget --output-document /tmp/haustuer1.jpg \'http://user:passwort@192.168.178.53/streaming/channels/101/picture\'');
                      
                         
                          // Nach dem ersten Bild wird nach 2000ms das nächste Bild gespeichert
                         timeout1 = setTimeout(function () {
                      
                           exec('wget --output-document /tmp/haustuer2.jpg \'http://user:passwort@192.168.178.53/streaming/channels/101/picture\''); 
                      
                         }, 2000);
                      
                         
                          // Nach dem zweiten Bild wird nach 2000ms das nächste Bild gespeichert
                         timeout2 = setTimeout(function () {
                      
                           exec('wget --output-document /tmp/haustuer3.jpg \'http://user:passwort@192.168.178.53/streaming/channels/101/picture\'');
                      
                         }, 4000);
                      
                        
                          // Nach dem dritten Bild wird nach 2000ms das nächste Bild gespeichert
                         timeout3 = setTimeout(function () {
                      
                           exec('wget --output-document /tmp/haustuer4.jpg \'http://user:passwort@192.168.178.53/streaming/channels/101/picture\'');
                      
                         }, 6000);
                      
                      
                          // Telegram versenden
                         timeout4 = setTimeout(function(){
                      
                             sendTo('telegram.0', {text: '/tmp/haustuer1.jpg', caption: 'Jemand klingelt an der Haustür !!!'});
                      
                                     //log ('__ Klingel-Bild wurde versendet __');
                      
                         }, 8000); 
                         timeout5 = setTimeout(function(){
                      
                             sendTo('telegram.0', {text: '/tmp/haustuer2.jpg', caption: 'Jemand klingelt an der Haustür !!!'});
                      
                                     //log ('__ Klingel-Bild wurde versendet __');
                      
                         }, 9000); 
                      
                      
                         }
                                
                      
                         timeout6 = setTimeout(function() {
                      
                            sperre = false;
                      
                         }, 5000); //Zeit für Klingelsperre 1.Zeile
                      
                      
                          // Bilder werden nach vis gespeichert
                         timeout7 = setTimeout(function () {
                      
                              const bild1 = fs.readFileSync('/tmp/haustuer1.jpg');
                      
                              writeFile('vis.0','/klingelbild/haustuer1.jpg', bild1);
                      
                              const bild2 = fs.readFileSync('/tmp/haustuer2.jpg');
                      
                              writeFile('vis.0','/klingelbild/haustuer2.jpg', bild2);
                      
                              const bild3 = fs.readFileSync('/tmp/haustuer3.jpg');
                      
                              writeFile('vis.0','/klingelbild/haustuer3.jpg', bild3);
                      
                              const bild4 = fs.readFileSync('/tmp/haustuer4.jpg');
                      
                              writeFile('vis.0','/klingelbild/haustuer4.jpg', bild4);
                      
                         }, 20000); 
                      
                      });
                      
                      
                      
                      

                      Knallochse 1 Reply Last reply Reply Quote 1
                      • Knallochse
                        Knallochse @Glasfaser last edited by

                        @Glasfaser Erstmal danke für dein Script.
                        Wenn ich dieses in Javascript importiere (ohne jegliche Änderung) wird ein Fehler bei den 4 Zeilen angezeigt

                        writeFile('vis.0','/klingelbild/haustuer1.jpg', bild1);
                        

                        Expected 4 arguments, but got 3.

                        Glasfaser 1 Reply Last reply Reply Quote 0
                        • Glasfaser
                          Glasfaser @Knallochse last edited by Glasfaser

                          @Knallochse

                          Nicht beachten … das Skript funktioniert !

                          Du meinst das hier :

                          1.JPG

                          Knallochse 1 Reply Last reply Reply Quote 0
                          • Knallochse
                            Knallochse @Glasfaser last edited by

                            @Glasfaser Nochmals vielen Dank. Ich werde es nächste Woche mal probieren.
                            Den Rest des Wochenendes wurde Familienaktivitäten eingefordert 😀

                            1 Reply Last reply Reply Quote 1
                            • Negalein
                              Negalein Global Moderator last edited by Negalein

                              Hallo

                              Ich habe das Script hier aus dem Thread angepasst.

                              Es wird kein Bild unter dem angegebenen Pfad gespeichert.

                              Könnte bitte jemand drüberschaun?

                              // -------------------------------------------------------------------------
                              // 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
                              // -------------------------------------------------------------------------
                                 // Objekt-ID des Bewegungsmelders
                              const oidLichtBewmelderTuer = "doorbird.0.Motion.trigger";
                                 // URL zur Kamera umn ein Image (jpg) zu erhalten
                              const cam_url = "http://user:password@10.0.1.84/bha-api/image.cgi";
                                 // Pfadangabe für die Speicherung der Bilder, der Pfad muss existieren
                              const dest_path = '/opt/iobroker/iobroker-data/files/vis.0/Camsnapshot';
                                 // Anzahl der Bilder, die vorgehalten werden sollen
                              const imageCountMax = 8;                
                                 // Prefix für die Bildnamen
                              const imageNamePre = "sprechanlage_"; 
                              // -------------------------------------------------------------------------
                              // 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.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 8 Sek erneut
                              function onEvent() {
                                  saveImage();
                                  setTimeout(function() { saveImage(); }, 8 * 1000); 
                              }
                              // Ereignisroutine
                              on({id: oidLichtBewmelderTuer, val: true}, function (obj) {
                                  onEvent( obj );
                              });
                              // manuelle Ausführung (Test)
                              onEvent();
                              
                              K 1 Reply Last reply Reply Quote 0
                              • chucky666
                                chucky666 last edited by chucky666

                                Hallo zusammen,
                                ich benutze dieses Script schon sehr lange , es funktioniert super.
                                was muss ich ändern um mehr Bilder zu bekommen ? zb 3

                                // -------------------------------------------------------------------------
                                // 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
                                // -------------------------------------------------------------------------
                                      // Objekt-ID des Bewegungsmelders
                                const oidLichtBewmelderTuer = "deconz.0.Sensors.54.open";
                                      // URL zur Kamera umn ein Image (jpg) zu erhalten
                                const cam_url = "http://192.168.178.88/tmpfs/auto.jpg?usr=";
                                      // Pfadangabe für die Speicherung der Bilder, der Pfad muss existieren
                                const dest_path = '/home/test/';
                                      // Anzahl der Bilder, die vorgehalten werden sollen
                                const imageCountMax = 4;                
                                      // Prefix für die Bildnamen
                                const imageNamePre = "test_"; 
                                
                                // -------------------------------------------------------------------------
                                // 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.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); }, 1000); 
                                            }
                                        }); 
                                    });
                                }
                                
                                // sofort ein Bild senden und nach 10 Sek erneut
                                function onEvent() {
                                    saveImage();
                                    setTimeout(function() { saveImage(); }, 2 * 1000); 
                                }
                                
                                // Ereignisroutine
                                on({id: oidLichtBewmelderTuer, val: true}, function (obj) {
                                    onEvent( obj );
                                });
                                
                                // manuelle Ausführung (Test)
                                onEvent();
                                
                                S K 2 Replies Last reply Reply Quote 0
                                • S
                                  Stoni @chucky666 last edited by

                                  @chucky666 Kann Dir leider keine Antwort auf Deine Frage geben, aber vielleicht kannst Du mir helfen. Wollte Dein Script auch mal testen, aber ich glaube, es fehlt mir an Berechtigungen.

                                  Folgende Fehlermeldung kommt:

                                  javascript.0
                                  2020-02-01 15:54:22.135
                                  warn
                                  (793) script.js.common.Telegram_Bilder: Fehler beim Bild speichern: Error: EACCES: permission denied, open '/home/test_0.jpg
                                  

                                  Ich konnte unter /Home/ auch keinen neuen Ordner erstellen, wo die Bilder temporär gespeichert werden sollen. Irgendwie muss ich die Berechtigung erlangen über root oder ähnliches. Wie geht das?

                                  Viele Grüße

                                  1 Reply Last reply Reply Quote 0
                                  • chucky666
                                    chucky666 last edited by

                                    Den Ordner habe ich mit Root erstellt und eine 775 Berechtigung .

                                    S 1 Reply Last reply Reply Quote 0
                                    • S
                                      Stoni @chucky666 last edited by

                                      @chucky666 sagte in [Frage BLOCKLY ] Klingel Bild per Telegram versenden / Snapshot von Cam per Telegram versenden:

                                      Den Ordner habe ich mit Root erstellt und eine 775 Berechtigung .

                                      Wie hast du das gemacht?

                                      1 Reply Last reply Reply Quote 0
                                      • K
                                        klaus88 @chucky666 last edited by klaus88

                                        @chucky666 : Du musst im Abschnitt:

                                        // sofort ein Bild senden und nach 10 Sek erneut
                                        function onEvent() {
                                            saveImage();
                                            setTimeout(function() { saveImage(); }, 2 * 1000); 
                                        }
                                        

                                        neue Zeiten eintragen !
                                        ich habe z.B. folgendes eingetragen:

                                        function onEvent() {
                                            saveImage();
                                            setTimeout(function() { saveImage(); }, 10 * 1000);
                                        	setTimeout(function() { saveImage(); }, 15 * 1000);
                                        	setTimeout(function() { saveImage(); }, 20 * 1000);
                                        	setTimeout(function() { saveImage(); }, 40 * 1000); 	
                                        }
                                        

                                        damit bekomme ich sofort und in 10, 15, 20 und 40 sek ein Bild.
                                        Hoffentlich gelingt es
                                        lg
                                        Klaus

                                        1 Reply Last reply Reply Quote 0
                                        • K
                                          klaus88 @Negalein last edited by klaus88

                                          @Negalein : Hallo!
                                          Hast du das Problem noch?
                                          Falls ja: Hast du Meldungen im iobroker Log zu diesem Script?

                                          Was du auf die schnelle noch probieren kannst: Ändere den Pfad wo es hingespeichert wird. ich habe oft Probleme mit dem VIS.0 Pfad - nehme daher immer den /home/pi/ Pfad!
                                          Schau mal unter: Link Text

                                          lg
                                          Klaus

                                          1 Reply Last reply Reply Quote 0
                                          • chucky666
                                            chucky666 @Alex1808 last edited by Negalein

                                            @Alex1808 sagte in [Frage BLOCKLY ] Klingel Bild per Telegram versenden / Snapshot von Cam per Telegram versenden:

                                            Ich versende stamt Bild eine kleine mp4 Datei die als Gif bei Telegram ankommt.

                                            einfach ffmpeg installieren und Befehl mit Blockly schicken.

                                            513_screenshot_at_juli_04_11-29-16.png

                                            Befehl URL:

                                            ffmpeg -y -i rtsp://kamera_ip:554/12 -t 5 -f mp4 -vcodec libx264 -pix_fmt yuv420p -an -vf scale=w=640:h=360:force_original_aspect_ratio=decrease -r 15 /opt/iobroker/out2.mp4
                                            

                                            (Muss zu eigene Kameras angepasst werden)

                                            Hallo
                                            Ich muss das hier mal etwas aufwärmen .
                                            Muss das Passwort von der Kamera auch mit darein ? Wenn ja wohin ?

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            721
                                            Online

                                            31.9k
                                            Users

                                            80.1k
                                            Topics

                                            1.3m
                                            Posts

                                            36
                                            157
                                            32358
                                            Loading More Posts
                                            • Oldest to Newest
                                            • Newest to Oldest
                                            • Most Votes
                                            Reply
                                            • Reply as topic
                                            Log in to reply
                                            Community
                                            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                            The ioBroker Community 2014-2023
                                            logo