Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Alexa Shopping List mit Bring synchronisieren

    NEWS

    • Wir empfehlen: Node.js 22.x

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker goes Matter ... Matter Adapter in Stable

    Alexa Shopping List mit Bring synchronisieren

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

      @martin_olw also bei mir geht alles. Lies mal unter folgendem Link, ob du im Adapter auch den Haken gesetzt hast: https://github.com/Apollon77/ioBroker.alexa2/issues/1223

      M 1 Reply Last reply Reply Quote 0
      • M
        martin_olw @Heimweh last edited by

        @heimweh Ich habe den Adapter noch einmal neu installiert und konfiguriert. Jetzt kommen auch wieder Daten in den history-Datenpunkt. Und immerhin jeden zweiten bis dritten Artikel setzt es auch auf die Einkaufsliste in ToDoist.
        Was mich wundert - die Alexa-interne Einkaufsliste füllt sich zuverlässig.

        1 Reply Last reply Reply Quote 0
        • Der-Jeti
          Der-Jeti last edited by

          Mit der neuen Version vom Alexa Adapter 3.27.0 und dem Script funktioniert das Synchronisieren auf beiden Seiten wieder.

          const bringBaseId = 'bring.0.xxxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxxx';
          const alexa2BaseId = 'alexa2.0.Lists.SHOP';
          
          const bringListId = bringBaseId + '.content';
          const bringListCompletedId = bringBaseId + '.recentContent';
          const bringAddToList = bringBaseId + '.saveItem';
          const bringCompleteItem = bringBaseId + '.moveToRecentContent';
          const alexaAddToList = alexa2BaseId + '.#New';
          const alexaListId = alexa2BaseId + '.json';
          
          const printDebug = true;
          function debug(msg) {
              if (printDebug) log(msg);
          }
          
          const TodoItemStatus = {
              NeedsAction: 'needs_action',
              Completed: 'completed',
          };
          
          function ListCleaner(Eintrag = '') {
              return Eintrag
                  .split(' ')
                  .map(w => w.charAt(0).toUpperCase() + w.slice(1))
                  .join(' ');
          }
          
          function compareCompleted(alexaItem, bringItem) {
              return (
                  (alexaItem.completed && bringItem.status === TodoItemStatus.Completed) ||
                  (!alexaItem.completed && bringItem.status === TodoItemStatus.NeedsAction)
              );
          }
          
          function eliminateDuplicated() {
              const raw = getState(alexaListId).val;
              if (!raw) return;
              const list = JSON.parse(raw);
              const seen = {};
              for (const item of list) {
                  const cleaned = ListCleaner(item.value);
                  if (seen[cleaned]) {
                      debug(`Delete duplicate Alexa item: ${item.value}`);
                      setState(`${alexa2BaseId}.items.${item.id}.#delete`, true);
                  } else {
                      seen[cleaned] = true;
                  }
              }
          }
          
          function syncLists(alexaList, bringList, timestampBring, source, recentList) {
              for (const alexaItem of alexaList) {
                  const cleanedName = ListCleaner(alexaItem.value);
                  alexaItem.found = false;
          
                  // Suche im aktiven Bring-Einträgen
                  for (const bringItem of bringList) {
                      if (ListCleaner(bringItem.name) === cleanedName) {
                          alexaItem.found = true;
                          bringItem.found = true;
          
                          if (alexaItem.updatedDateTime > timestampBring) {
                              if (!compareCompleted(alexaItem, bringItem)) {
                                  if (source === 'Alexa' && alexaItem.completed) {
                                      debug(`Markiere "${bringItem.name}" als erledigt in Bring (von Alexa)`);
                                      setState(bringCompleteItem, cleanedName);
                                  }
                              }
                          } else {
                              if (!compareCompleted(alexaItem, bringItem)) {
                                  if (source === 'Bring') {
                                      debug(`Aktualisiere "${alexaItem.value}" in Alexa (von Bring)`);
                                      setState(`${alexa2BaseId}.items.${alexaItem.id}.completed`, bringItem.status === TodoItemStatus.Completed);
                                  }
                              }
                          }
                      }
                  }
          
                  // Suche im "recentContent" von Bring
                  for (const bringItem of recentList) {
                      if (ListCleaner(bringItem.name) === cleanedName) {
                          alexaItem.found = true;
                          bringItem.found = true;
          
                          if (alexaItem.updatedDateTime > timestampBring) {
                              if (source === 'Alexa' && !compareCompleted(alexaItem, bringItem)) {
                                  debug(`Füge "${bringItem.name}" erneut zu Bring hinzu (von Alexa)`);
                                  setState(bringAddToList, cleanedName);
                              }
                          } else {
                              if (!compareCompleted(alexaItem, bringItem)) {
                                  if (source === 'Bring') {
                                      debug(`Lösche Alexa-Eintrag "${alexaItem.value}" (von Bring)`);
                                      setState(`${alexa2BaseId}.items.${alexaItem.id}.#delete`, true);
                                  }
                              }
                          }
                      }
                  }
          
                  // Alexa-Item nicht gefunden in Bring
                  if (!alexaItem.found) {
                      if (alexaItem.completed) {
                          debug(`Lösche erledigten Alexa-Eintrag "${alexaItem.value}", nicht in Bring gefunden.`);
                          setState(`${alexa2BaseId}.items.${alexaItem.id}.#delete`, true);
                      } else if (source === 'Alexa') {
                          debug(`Füge neuen Alexa-Eintrag "${alexaItem.value}" zu Bring hinzu`);
                          setState(bringAddToList, cleanedName);
                      }
                  }
              }
          
              // Bring-Einträge, die nicht in Alexa sind
              for (const bringItem of bringList) {
                  if (!bringItem.found && bringItem.status !== TodoItemStatus.Completed && source === 'Bring') {
                      debug(`Füge Bring-Eintrag "${bringItem.name}" zu Alexa hinzu`);
                      setState(alexaAddToList, ListCleaner(bringItem.name));
                  }
              }
          }
          
          function doSync(source) {
              eliminateDuplicated();
          
              const rawAlexa = getState(alexaListId).val;
              const rawBring = getState(bringListId).val;
              const rawCompleted = getState(bringListCompletedId).val;
          
              if (!rawAlexa || !rawBring || !rawCompleted) {
                  debug('Datenpunkte unvollständig');
                  return;
              }
          
              const alexaList = JSON.parse(rawAlexa);
              const bringList = JSON.parse(rawBring);
              const bringCompleted = JSON.parse(rawCompleted);
              const timestamp = getState(bringListId).ts;
          
              syncLists(alexaList, bringList, timestamp, source, bringCompleted);
          }
          
          on({ id: bringListId, change: 'any' }, () => {
              debug('Änderung durch Bring erkannt');
              doSync('Bring');
          });
          
          on({ id: alexaListId, change: 'any' }, () => {
              debug('Änderung durch Alexa erkannt');
              doSync('Alexa');
          });
          
          // Initial Sync beim Start
          doSync('Startup');
          
          
          M 1 Reply Last reply Reply Quote 0
          • M
            MCU @Der-Jeti last edited by MCU

            @der-jeti 3.27.0 gibt es nicht
            5a708cda-cfe8-4011-a13e-69b8288ea640-image.png
            EDIT: anscheinend doch
            "version": "3.27.0",

            T mcBirne 2 Replies Last reply Reply Quote 0
            • T
              thorschtn @MCU last edited by

              @mcu Funktioniert einwandfrei. Lediglich die noch nicht offiziell releaste 3.27.0 laden und im Javascript die const alexa2BaseId ändern.

              1 Reply Last reply Reply Quote 0
              • mcBirne
                mcBirne @MCU last edited by

                @mcu Wo findest du die v3.27.0? Ich finde nur die v3.26.7

                Der-Jeti M 2 Replies Last reply Reply Quote 0
                • Der-Jeti
                  Der-Jeti @mcBirne last edited by

                  @mcbirne mit der Katze von github laden.

                  1 Reply Last reply Reply Quote 1
                  • M
                    MCU @mcBirne last edited by

                    @mcbirne
                    https://github.com/Apollon77/ioBroker.alexa2/blob/9baece37d4796b88d8debb7af9cbfef50cfc92c8/io-package.json#L4

                    M 1 Reply Last reply Reply Quote 1
                    • M
                      martin_olw @MCU last edited by

                      @Heimweh - kann mit der neuen Version vom Alexa Adapter 3.27.x über die Datenpunkte in alexa2.0.Lists.SHOP mit TODOIST gesycnt oder zuverlässig nach TODOIST geschrieben werden? Aktuell klappt das bei mir mit deinem Skript nur in 30 % der Fälle.
                      Danke!
                      VG Martin

                      Heimweh 3 Replies Last reply Reply Quote 0
                      • Heimweh
                        Heimweh @martin_olw last edited by Heimweh

                        @martin_olw bei mir hat das zu 100% funktioniert. Ich habe mir zuletzt einen eigenen Alexa Skill gebastelt für Einkaufs und Todoliste mit Todoist. Es hat auch geklappt allerdings blöd zum aufrufen. Bsp.: Alexa sag meinen Projekten, ich muss Fenster putzen. - bei dem Script den ich online gestellt hatte war bei mir öfters das Problem der summary Datenpunkt der zeitweise nicht funktioniert. Ich kann Dir derzeit nicht helfen weil ich noch 3 Wochen im Urlaub bin, habe aber interessiert hier mitgelesen und wollte mir das nach Rückkehr mal anschauen..... Ich denke schon dass man das wieder verknüpfen kann so das es mit Todoist läuft

                        aruttkamp 1 Reply Last reply Reply Quote 0
                        • aruttkamp
                          aruttkamp @Heimweh last edited by

                          Das läuft jetzt wieder wie geschmiert !
                          Danke an alle beteiligten !

                          aruttkamp 1 Reply Last reply Reply Quote 0
                          • aruttkamp
                            aruttkamp @aruttkamp last edited by aruttkamp

                            @Heimweh
                            Mir ist aufgefallen, dass das Skript jede Minute eine Änderung durch Bring! erkennt.
                            Dabei ist es egal ob etwas geändert wurde oder nicht. Hat das schon mal jemand beleuchtet warum dies passiert und wie das evtl. unterbunden werden kann ?

                            Heimweh 1 Reply Last reply Reply Quote 0
                            • Heimweh
                              Heimweh @aruttkamp last edited by

                              @aruttkamp - Du meinst Todoist? Kannst Du mir näher beschreiben was Du genau meinst? Vielleicht wird er Summary Datenpunkt minütlich abgefragt? Aber das dürfte nicht relevant sein solange sich der Wert nicht ändert? Bei mir läuft der Skript seit Erstellung problemlos.... Habe mich daher auch nicht mehr damit befasst.....

                              aruttkamp 1 Reply Last reply Reply Quote 0
                              • aruttkamp
                                aruttkamp @Heimweh last edited by

                                @heimweh
                                ich meine Diese Protokolleinträge :
                                c808b55c-11f1-45cf-851a-c6ce0d66fe54-image.png

                                ja, es sind nur infos und ich kann sie abstellen. aber es passiert ja doch ein permanentes schreiben Rtg. Alexa. ich bin nicht sicher ob das nicht zu viel traffic dort führt und die uns das irgendwann übel nehmen 😉

                                Heimweh mcBirne 2 Replies Last reply Reply Quote 0
                                • Heimweh
                                  Heimweh @aruttkamp last edited by

                                  @aruttkamp bei mir ist das nicht so. Hast Du den Bring Teil in meinen Script reingebastelt? Was ich mir gerade noch überlege - der Listen Teil soll ja wieder funktionieren (s.o.) - hat es damit evtl zu tun?

                                  1 Reply Last reply Reply Quote 0
                                  • mcBirne
                                    mcBirne @aruttkamp last edited by

                                    @aruttkamp
                                    Bei mir funktioniert es seit heute nicht mehr. Allerdings werden auch keine Alexa IOT Befehle erkannt oder die Alexa Summary aktualisiert. Auch Ankündigungen sind nicht mehr möglich. Hat das noch jemand? Hat Amazon da ein Problem?

                                    Heimweh aruttkamp 2 Replies Last reply Reply Quote 0
                                    • Heimweh
                                      Heimweh @mcBirne last edited by

                                      @mcbirne ist bei mir auch so. bzw. IOT Geräte lassen sich steuern aber summary und die Listen gehen nicht mehr

                                      1 Reply Last reply Reply Quote 1
                                      • aruttkamp
                                        aruttkamp @mcBirne last edited by aruttkamp

                                        @Heimweh
                                        Nein. Dein Scrikt ist das von hier - 1:1 kopiert und nur oben im Kopf die entspr. ID´s geändert

                                        Heimweh 1 Reply Last reply Reply Quote 0
                                        • Heimweh
                                          Heimweh @aruttkamp last edited by Heimweh

                                          @aruttkamp ich habe gar kein Bring sondern Todoist. Hoffe Du hast jetzt nichts gemischt. Der Todoist Script mit viel weniger Logeinträgen wäre der hier (bitte selber testen - hab leider keine Zeit gefunden):

                                          const axios = require('axios');
                                          
                                          // Konfiguration
                                          const todoistShoppingListId = 'XXXXXXXXXXX'; // <- Deine Projekt-ID
                                          const todoistToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // <- Dein API-Token
                                          
                                          on({ id: 'alexa2.0.History.summary', change: 'any' }, function (obj) {
                                              const inputRaw = obj.state.val;
                                          
                                              if (typeof inputRaw !== 'string') {
                                                  console.warn('[ToDoist] ⚠️ Kein String erkannt in alexa2.0.History.summary:', inputRaw);
                                                  return;
                                              }
                                          
                                              const input = inputRaw.trim();
                                          
                                              const match = input.match(/^setze (.+) auf (?:meine|die) (einkaufsliste|todo[\s-]?liste)/i);
                                          
                                              if (match && match.length >= 3) {
                                                  const rohAufgabe = match[1];
                                                  const ziel = match[2].replace(/\s|-/g, '').toLowerCase();
                                          
                                                  const mitZiffern = wordsToNumbersSmart(rohAufgabe);
                                                  const aufgabe = capitalizeFirst(mitZiffern);
                                          
                                                  let projektId = null;
                                                  if (ziel === 'einkaufsliste') {
                                                      projektId = todoistShoppingListId;
                                                  }
                                          
                                                  console.log(`[ToDoist] 🧠 Alexa erkannt → "${aufgabe}" für Projekt: ${ziel}`);
                                                  addTaskToTodoist(aufgabe, projektId);
                                              }
                                          });
                                          
                                          function addTaskToTodoist(text, projectId = null) {
                                              const todoistData = { content: text };
                                              if (projectId) todoistData.project_id = projectId;
                                          
                                              axios.post('https://api.todoist.com/rest/v2/tasks', todoistData, {
                                                  headers: {
                                                      'Content-Type': 'application/json',
                                                      'Authorization': `Bearer ${todoistToken}`
                                                  }
                                              })
                                              .then(() => {
                                                  console.log(`[ToDoist] ✅ Aufgabe "${text}" erfolgreich zu Todoist hinzugefügt.`);
                                              })
                                              .catch(error => {
                                                  console.error('[ToDoist] ❌ Fehler beim Hinzufügen zu Todoist:', error.message || error.response?.data || error);
                                              });
                                          }
                                          
                                          function capitalizeFirst(text) {
                                              if (!text || typeof text !== 'string') return '';
                                              return text.charAt(0).toUpperCase() + text.slice(1);
                                          }
                                          
                                          function wordsToNumbersSmart(text) {
                                              const ones = {
                                                  'null': 0, 'eins': 1, 'eine': 1, 'einen': 1,
                                                  'zwei': 2, 'drei': 3, 'vier': 4, 'fünf': 5,
                                                  'sechs': 6, 'sieben': 7, 'acht': 8, 'neun': 9,
                                                  'zehn': 10, 'elf': 11, 'zwölf': 12, 'dreizehn': 13,
                                                  'vierzehn': 14, 'fünfzehn': 15, 'sechzehn': 16,
                                                  'siebzehn': 17, 'achtzehn': 18, 'neunzehn': 19
                                              };
                                          
                                              const tens = {
                                                  'zwanzig': 20, 'dreißig': 30, 'vierzig': 40,
                                                  'fünfzig': 50, 'sechzig': 60, 'siebzig': 70,
                                                  'achtzig': 80, 'neunzig': 90
                                              };
                                          
                                              const multipliers = {
                                                  'hundert': 100,
                                                  'tausend': 1000
                                              };
                                          
                                              const skipWords = ['und', 'oder', 'mit', 'für', 'pro'];
                                          
                                              const words = text.toLowerCase().split(/\s+/);
                                              const finalText = [];
                                              let i = 0;
                                              let capitalizeNext = 0;
                                          
                                              while (i < words.length) {
                                                  const word = words[i];
                                          
                                                  if (ones[word] !== undefined) {
                                                      if (i + 2 < words.length && words[i + 1] === 'und' && tens[words[i + 2]]) {
                                                          const value = ones[word] + tens[words[i + 2]];
                                                          finalText.push(value.toString());
                                                          capitalizeNext = 2;
                                                          i += 3;
                                                          continue;
                                                      }
                                          
                                                      if (i + 1 < words.length && multipliers[words[i + 1]]) {
                                                          const value = ones[word] * multipliers[words[i + 1]];
                                                          finalText.push(value.toString());
                                                          capitalizeNext = 2;
                                                          i += 2;
                                                          continue;
                                                      }
                                          
                                                      finalText.push(ones[word].toString());
                                                      capitalizeNext = 2;
                                                      i++;
                                                  } else if (tens[word] !== undefined) {
                                                      finalText.push(tens[word].toString());
                                                      capitalizeNext = 2;
                                                      i++;
                                                  } else if (!isNaN(word)) {
                                                      finalText.push(word);
                                                      capitalizeNext = 2;
                                                      i++;
                                                  } else {
                                                      if (capitalizeNext > 0 && !skipWords.includes(word)) {
                                                          finalText.push(word.charAt(0).toUpperCase() + word.slice(1));
                                                          capitalizeNext--;
                                                      } else {
                                                          finalText.push(word);
                                                      }
                                                      i++;
                                                  }
                                              }
                                          
                                              return finalText.join(' ');
                                          }
                                          
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • Heimweh
                                            Heimweh @martin_olw last edited by

                                            @martin_olw sorry das ich mir so lange Zeit gelassen habe. Wenn ich das jetzt richtig gesehen habe - funktioniert mit der neuen Adapter Version der Datenpunkt alexa2.0.Lists.SHOP.json wieder - dann wäre ja alles wieder beim alten und mein erster Script den ich zum Thema Todoist reingestellt habe, müsste wieder funktionieren wie "früher" - ich hab jetzt den Script von damals nochmal korrigiert (er hat auf eine Testliste verwiesen) aber nicht getestet (mir fehlt die Zeit)

                                            const axios = require('axios');
                                            
                                            // Todoist API-Konfiguration
                                            const todoistProjectId = '12345678'; // Todoist-Projekt-ID
                                            const todoistToken = 'xXxXxXxXxXxXxXxXxXxXxXxX'; // Todoist-API-Token
                                            
                                            let previousList = [];
                                            
                                            // 1. Überwachen der Änderungen in der Alexa-Liste
                                            on({ id: 'alexa2.0.Lists.SHOP.json', change: 'any' }, function (obj) {
                                                try {
                                                    console.log('Änderung in der Alexa Liste erkannt.');
                                            
                                                    // Alexa-Liste als JSON parsen
                                                    const currentList = JSON.parse(obj.state.val);
                                                    console.log('Alexa-Liste erfolgreich geparst.');
                                            
                                                    if (currentList && currentList.length > 0) {
                                                        console.log(`Alexa-Liste enthält ${currentList.length} Einträge.`);
                                            
                                                        // Neues Item zur Todoist-Liste hinzufügen, wenn die Liste gewachsen ist
                                                        if (previousList.length < currentList.length) {
                                                            const newItem = currentList.find(item => !previousList.some(prevItem => prevItem.id === item.id));
                                                            if (newItem) {
                                                                console.log(`Neues Item erkannt: "${newItem.value}" mit ID: ${newItem.id}`);
                                                                addTaskToTodoist(newItem.value);
                                                            }
                                                        }
                                            
                                                        // Aktualisiere die vorherige Liste
                                                        previousList = currentList;
                                                    } else {
                                                        console.log('Alexa-Liste ist leer oder nicht verfügbar.');
                                                    }
                                                } catch (e) {
                                                    console.error('Fehler beim Parsen der Alexa-Liste:', e.message || e);
                                                }
                                            });
                                            
                                            // 2. Periodische Synchronisierung mit Todoist (alle 1 Minute)
                                            schedule('*/1 * * * *', function () {
                                                console.log("Todoist-Aufgaben werden abgefragt...");
                                            
                                                // Abrufen der aktiven Todoist-Aufgaben
                                                axios.get(`https://api.todoist.com/rest/v2/tasks`, {
                                                    headers: {
                                                        'Authorization': `Bearer ${todoistToken}`
                                                    }
                                                })
                                                .then(response => {
                                                    const activeTasks = response.data.map(task => task.content); // Extrahiere die Inhalte der aktiven Aufgaben
                                                    console.log('Aktive Todoist-Aufgaben erfolgreich abgerufen.');
                                            
                                                    // Vergleich der aktiven Todoist-Aufgaben mit der Alexa-Liste
                                                    syncAlexaWithTodoist(activeTasks);
                                                })
                                                .catch(error => {
                                                    console.error('Fehler beim Abrufen der Todoist-Aufgaben:', error.message || error.response.data);
                                                });
                                            });
                                            
                                            // 3. Hilfsfunktion zum Hinzufügen von Aufgaben zu Todoist
                                            function addTaskToTodoist(itemValue) {
                                                const todoistData = {
                                                    content: itemValue,
                                                    project_id: todoistProjectId
                                                };
                                            
                                                axios.post('https://api.todoist.com/rest/v2/tasks', todoistData, {
                                                    headers: {
                                                        'Content-Type': 'application/json',
                                                        'Authorization': `Bearer ${todoistToken}`
                                                    }
                                                })
                                                .then(response => {
                                                    console.log(`Item "${itemValue}" erfolgreich zu Todoist hinzugefügt.`);
                                                })
                                                .catch(error => {
                                                    console.error('Fehler beim Hinzufügen zu Todoist:', error.message || error);
                                                });
                                            }
                                            
                                            // 4. Hilfsfunktion zur Synchronisierung der Alexa-Liste mit Todoist
                                            function syncAlexaWithTodoist(activeTasks) {
                                                const alexaList = JSON.parse(getState('alexa2.0.Lists.SHOP.json').val);
                                            
                                                alexaList.forEach(item => {
                                                    if (!activeTasks.includes(item.value)) {
                                                        // Markiere das Item in Alexa als "completed", wenn es nicht mehr in Todoist aktiv ist
                                                        const completeState = `alexa2.0.Lists.SHOP.items.${item.id}.completed`;
                                                        setState(completeState, true, function(err) {
                                                            if (err) {
                                                                console.error(`Fehler beim Setzen von "completed" für "${item.value}" in Alexa:`, err.message || err);
                                                            } else {
                                                                console.log(`Item "${item.value}" in Alexa erfolgreich als "completed" markiert.`);
                                                            }
                                                        });
                                                    }
                                                });
                                            }
                                            
                                            
                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            528
                                            Online

                                            32.0k
                                            Users

                                            80.4k
                                            Topics

                                            1.3m
                                            Posts

                                            26
                                            163
                                            21017
                                            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