Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [Vorlage] Simple Anrufer-Ansage via Alexa/tr-064

    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

    [Vorlage] Simple Anrufer-Ansage via Alexa/tr-064

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

      Anbei ein kleines Javascript für eine Ansage des Anrufers bzw. der Nummer über den Alexa2-Adapter.
      Benötigt wird auch der tr-064-Adapter (aktuelle 3.x Version) für das Empfangen der Fritz!Box-Daten.

      //* Insert own numbers with description
      const numbers = {
          '01234512345': 'privat',
          '01234522222': 'Büro'
      };
      
      function tellMeWhoCalls(sayattention) {
          let curtime = new Date();
          //* not between 21pm and 7am UTC
          if(curtime.getHours() < 7 || curtime.getHours() > 21) {
              return;
          }
          let targ = getState('tr-064.0.callmonitor.inbound.callee').val;
          let src = getState('tr-064.0.callmonitor.inbound.caller').val;
          let srcName = getState('tr-064.0.callmonitor.inbound.callerName').val;
      
          let targName = numbers[targ];
          if(!targName) {
              targName = 'unbekannt';
          }
      
          let text = (sayattention ? 'Achtung! ' : '') + 'Anruf für ' + targName + ' von ';
          if(srcName) {
              text += srcName;
          } else if(src) {
              text += '<say-as interpret-as="digits">' + src + '</say-as>';
          } else {
              text += 'unbekannter Nummer';
          }
          text += '.';
      
          text = '<speak>' + text + '</speak>';
      
          //* replace XXXXX by your echo device id and add further lines for more devices
          setState('alexa2.0.Echo-Devices.XXXXXXX.Commands.ssml', text);
      
          if(targName === 'privat') {
              //* replace YYYYYY by your echo device id or delete this part if you don't need it
              setState('alexa2.0.Echo-Devices.YYYYYYYY.Commands.ssml', text);
          }
      }
      
      let ringInterval = null;
      
      on({id: 'tr-064.0.callmonitor.ringing', change: 'ne'}, function(obj) {
          if(obj.state.val !== true) {
              //* no longer ringing
              if(ringInterval) {
                  clearInterval(ringInterval);
                  ringInterval = null;
              }
              return;
          }
      
          if(ringInterval) {
              clearInterval(ringInterval);
          }
          //* repeat caller anouncement each 10 secs
          ringInterval = setInterval(function() {
              tellMeWhoCalls();
          }, 10000);
      
          //* first time add "Achtung!" in front of the text
          setTimeout(function() {
              tellMeWhoCalls(true);
          }, 1000);
      });
      
      B 1 Reply Last reply Reply Quote 0
      • J
        jensus11 last edited by

        Ich habe dein Script importiert, doch leider sagt Alexa nichts.
        tr-064 und Alexa2 sind natürlich installiert.
        Angepasst im Script habe ich die XXXXX für Alexa und die Nummer für privat.
        Den zweiten für ein zweites Alexa Gerät habe ich gelöscht.
        Was könnte ich denn verkehrt gemacht haben?

        J 1 Reply Last reply Reply Quote 0
        • J
          jensus11 @jensus11 last edited by

          @jensus11 sagte in [Vorlage] Simple Anrufer-Ansage via Alexa/tr-064:

          Ich habe dein Script importiert, doch leider sagt Alexa nichts.
          tr-064 und Alexa2 sind natürlich installiert.
          Angepasst im Script habe ich die XXXXX für Alexa und die Nummer für privat.
          Den zweiten für ein zweites Alexa Gerät habe ich gelöscht.
          Was könnte ich denn verkehrt gemacht haben?

          Habe es selber hinbekommen. Lag am alten tr-064. Mit der 3.1.4 läuft das.

          1 Reply Last reply Reply Quote 0
          • B
            bergbock @StrathCole last edited by

            Hat auch 3 Jahre später noch gut funktioniert! 🙂

            Vielen Dank 👍

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

            Support us

            ioBroker
            Community Adapters
            Donate

            891
            Online

            31.8k
            Users

            80.0k
            Topics

            1.3m
            Posts

            communication javascript
            3
            4
            1259
            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