Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Doorbird PlaySound

    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

    Doorbird PlaySound

    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      Basti189 last edited by Basti189

      Hallo zusammen,

      nach zwei Tagen des Testens und der Verzweiflung, kann ich euch nun ein Javascript-Skript anbieten, welches eine vorher konvertierte WAV auf eurer Doorbird abspielt.
      Die abzuspielende Sounddatei habe ich vorher auf der Seite https://g711.org/ mit den Parameter "u-law WAV (8Khz, Mono, CCITT u-law)" konvertiert.
      Anschließens muss die Datei nur unter "/opt/iobroker/iobroker-data/files/0_userdata.0/doorbird/" abgelegt werden. Sollte der Ordner doorbird nicht existieren, so kann er per Hand erstellt werden oder das Skript einmal laufen lassen, dann ist er auch da.
      Im JavaScript Order sollte nun auch das Verzeichnis Doorbird aufgetaucht sein, sowie zwei Datenpunkte PlaySound und StopSound.
      PlaySound einfach den Name der Datei ohne Endung übergeben, also heißt die Datei Ansage.wav, so schreibt ihr Ansage hinein.
      StopSound ist ein Button, der das Abspielen abbricht.
      Falls sich jemand dem Doorbird Adapter widmet, den Code gerne dort mit aufnehmen 😄
      Hat jemand Verbesserungsvorschläge, immer her damit.
      Vielleicht kann man sich auch nochmal Gedanken machen, Dateien on the fly in das ulaw format zu konvertieren, für TTs zum Beispiel...

      Liebe Grüße
      Basti

      Version: 1.0.1, update erfolgte am 20.11.2022

      /*
       * @Copyright 2022 Sebastian Wolf <wolfsline@googlemail.com>
       *
       * Skript Name:     Doorbird PlaySound
       * Skript Version:  1.0.1
       * Erstell-Datum:   19. November 2022
       *
       */
      
      // ------------ CHANGE HERE -------------
      const USERNAME = "xxxxxxxx0001";
      const PASSWORD = "xxxxxxxxxxxx";
      const IP_ADDRESS = "IP-ADRESSE";
      // --------------------------------------
      
      const AUTH = 'Basic ' + Buffer.from(USERNAME + ':' + PASSWORD).toString('base64');
      const PATH = "/opt/iobroker/iobroker-data/files/0_userdata.0/doorbird/";
      const VERSION = "v1.0.1";
      const API_VERSION = "v0.31"
      
      var fs = require("fs");
      var http = require("http");
      
      var credentialsValid = false;
      var isPlaying = false;
      var stopSound = false;
      
      function init() {
          console.log("Starting...");
          console.log("Script: " + VERSION + ", API: " + API_VERSION);
          if (!fs.existsSync(PATH)) {
              fs.mkdirSync(PATH);
          }
      
          // Create Datapoint
          createState("Doorbird.PlaySound", "", false, {
                  name: "PlaySound",
                  desc: "Sound auf deiner Doorbird abspielen",
                  type: "string",
                  role: "value"
              });
      
          createState("Doorbird.StopSound", false, {
              name: "StopSound",
              desc: "Beendet das Abspielen",
              type: "boolean",
              role: "button"
          });
      
          // Check credentials
          getInfo();
      }
      
      function scriptIsReadyForPlaying() {
          // playSound("Ansage");
          on({id: "javascript.0.Doorbird.PlaySound", change: "any"}, async function (obj) {
              var name = getState("javascript.0.Doorbird.PlaySound").val;
              await playSound(name)
          });
      
          on({id: "javascript.0.Doorbird.StopSound", val: true}, async function (obj) {
              setState("javascript.0.Doorbird.StopSound", false);
              if (isPlaying) {
                  stopSound = true;
              }
          });
      }
      
      function buildURL(endpoint, params) {
          return "http://" + IP_ADDRESS + "/bha-api/" + endpoint + ".cgi?" + params;
      }
      
      function buildURL(endpoint) {
          return "http://" + IP_ADDRESS + "/bha-api/" + endpoint + ".cgi";
      }
      
      async function playSound(name) {
          if (isPlaying || !credentialsValid) {
              return;
          }
          if (name == null || name == "") {
              return;
          }
          isPlaying = true;
          const options = {
              method: "POST",
              headers: {
                  "Authorization": AUTH,
                  "Content-Type": "audio/basic",
                  "Content-Length": "9999999",
                  "Connection": "Keep-Alive",
                  "Cache-Control": "no-cache"
              }
          };
          var req = http.request(buildURL("audio-transmit"), options);
          var file_stream = fs.createReadStream(PATH + name + ".wav", {highWaterMark: 128});
          
          var timeout = 750;
          file_stream.on("data", (data) => {
              if (stopSound) {
                  stopSound = false;
                  isPlaying = false;
                  file_stream.destroy();
                  return;
              }
              req.write(data);
              file_stream.pause();
              setTimeout(() => {
                  file_stream.resume();
                  timeout = 15;
              }, timeout);
          });
          file_stream.on('error', () => {
              isPlaying = false;
          });
           file_stream.on("close", () => {
              isPlaying = false;
          });
          req.on("error", () => {
              isPlaying = false;
          });
      }
      
      function getInfo() {
          const options = {
              headers: {
              "Authorization": AUTH
              }
          };
          let rawData = '';
          http.get(buildURL("info"), options, (res) => {
              res.on("data", (chunk) => { 
                  rawData += chunk; 
              });
              res.on("end", () => {
                  if (res.statusCode == 200) {
                      console.log("Authentication success");
                      credentialsValid = true;
                      scriptIsReadyForPlaying();
                  } else {
                      console.error("Error! Check ip, username and password");
                      console.error("Please restart script");
                  }
              });
              res.on("error", (e) => {    
                  console.error(`Got error: ${e.message}`);
              });
          });
      }
      init();
      
      M 1 Reply Last reply Reply Quote 1
      • G
        GreySkoda91 last edited by

        Kann man dann auch mehrere Sounds abspielen ? 😄
        oder nur die eine ?

        1 Reply Last reply Reply Quote 0
        • M
          maxpd @Basti189 last edited by maxpd

          @basti189 danke dir. Noch nicht probiert. Weil noch eine Frage: Hast du auch noch die original Vogelgezwitscherdatei, wenn man auf diese wieder zurückgreifen möchte?

          Update: ist in der App ebenfalls änderbar und der Standardsound bleibt dort weiterhin vorhanden. https://www.doorbird.com/de/faq-single?faq=241

          M 1 Reply Last reply Reply Quote 0
          • M
            micklafisch @maxpd last edited by

            @maxpd
            geht das bei dir über die App?

            Wenn ich versuche den Button Klingelton in der Doorbird App zu ändern, dann crasht die App. Über das Doorbird Admin Webinterface gibts die Einstellung nicht

            M 1 Reply Last reply Reply Quote 0
            • M
              maxpd @micklafisch last edited by

              @micklafisch hab es als admin exakt nach dem FAQ über die App gemacht. jetzt bimmeln die ersten Noten von Halloween

              M 1 Reply Last reply Reply Quote 0
              • M
                micklafisch @maxpd last edited by

                @maxpd
                bin ebenfalls direkt nach der Anleitung vorgegangen, hab auch zig Soundfiles probiert.

                Aktuell iOS 18.1, Doorbirdapp V5.42 und Doorbird V000148

                Es haut einfach nicht hin, die App schließt sich selbst sobald ich das Soundfile auswähle.

                1 Reply Last reply Reply Quote 0
                • M
                  micklafisch last edited by

                  Hab es jetzt aus lauter Verzweiflung mit einem Android-Simulator unter Windows versucht. Dort geht die App und ich kann den Ton hochladen ohne dass die App abstürzt.

                  Ziel erreicht. Danke!

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

                  Support us

                  ioBroker
                  Community Adapters
                  Donate

                  924
                  Online

                  31.9k
                  Users

                  80.2k
                  Topics

                  1.3m
                  Posts

                  4
                  7
                  2403
                  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