Mit dem Datenpunkt "Summary" hab ich hier einen Script der es wieder ermöglicht mit TODOIST zu synchronisieren. Allerdings nur noch in eine Richtung - die Punkte bleiben alle in den Alexa Listen bestehen....
Was macht das Skript?
Dieses ioBroker-Skript überwacht den Alexa-Datenpunkt alexa2.0.History.summary und erkennt Sätze wie:
„Setze Milch auf die Einkaufsliste“
„Setze zwei Packungen Nudeln auf meine Einkaufsliste“
„Setze Wasser holen auf die To-do Liste“
„Setze fünf hundert Gramm Hackfleisch auf die Einkaufsliste“
„Setze 1 x Tomaten auf die Einkaufsliste“
Erkannte Aufgaben werden automatisch als neue Todoist-Tasks erstellt – entweder:
in deiner Einkaufsliste (Todoist-Projekt-ID wird angegeben)
oder in der Inbox (wenn „To-do-Liste“ erkannt wird)
const axios = require('axios');
// Konfiguration
const todoistShoppingListId = 'XXXXXXXXXXX';
const todoistToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
on({ id: 'alexa2.0.History.summary', change: 'any' }, function (obj) {
const inputRaw = obj.state.val;
if (typeof inputRaw !== 'string') {
console.warn('⚠️ Kein String erkannt in alexa2.0.History.summary:', inputRaw);
return;
}
const input = inputRaw.trim();
console.log(`🔁 Neue Alexa-Eingabe erkannt: "${input}"`);
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);
console.log(`🧠 Erkannt: Aufgabe = "${aufgabe}", Ziel = "${ziel}"`);
let projektId = null;
if (ziel === 'einkaufsliste') {
projektId = todoistShoppingListId;
}
addTaskToTodoist(aufgabe, projektId);
} else {
console.log('👂 Kein Todoist-Befehl erkannt. Erwartet: "Setze xyz auf [meine/die] Einkaufsliste" oder "To-do-Liste".');
}
});
function addTaskToTodoist(text, projectId = null) {
const todoistData = { content: text };
if (projectId) todoistData.project_id = projectId;
console.log(`📤 Sende an Todoist: "${text}" → ${projectId ? `Projekt-ID ${projectId}` : 'Inbox'}`);
axios.post('https://api.todoist.com/rest/v2/tasks', todoistData, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${todoistToken}`
}
})
.then(() => {
console.log(`✅ Aufgabe "${text}" erfolgreich zu Todoist hinzugefügt.`);
})
.catch(error => {
console.error('❌ 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);
}
// Zahlworte + Nach-Zahl-Großschreibung + Multiplikatoren
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];
// Fall: Zahlwort + "und" + Zehner
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;
}
// Fall: Zahlwort + "hundert"/"tausend"
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(' ');
}
Auch ich hinterfrage den Sinn meiner 10 Echos täglich. Außer Lichter / Geräte damit schalten wird es immer weniger.