Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Spülmaschinen Abfrage mit Ausgabe über Alexa Geräte

    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

    Spülmaschinen Abfrage mit Ausgabe über Alexa Geräte

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

      Hallo zusammen,

      ich habe ein Script mit Hilfe der Ai erstellt, welche den Status der Tür meiner Spülmaschine und den Programmfortschritt abfrägt. Status Tür (Open, Closed) und 100 als Wert zusammen soll eine Ausgabe Spülmaschine ist fertig ausgeben. Das Script schmeisst keinen Fehler aus aber die Alexas bleiben Stumm. Anbei das Script: Vielleicht hat ja jemand eine Idee. Damit das ganze nicht zu viele Ressourcen braucht soll die Abfrage alle Minute stattfinden erstmal zum testen, später reicht es alle 5-10 minuten.
      Ausserdem soll zwischen 21 und 8 uhr keine nachricht erfolgen.
      Beid er Spülmaschine handelt es sich um eine Siemens IQ300. Der Hintergrund warum ich den Programmfortschritt abgfrage ist da es keinen Wert gibt der mir sagt ob die Spülmaschine fertig ist oder nicht.

      vielen Dank schonmal für die Hilfe von Euch

      // Konfiguration
      const targetDevice = "homeconnect.0.014060394661007096";
      const doorStateId = `${targetDevice}.status.BSH_Common_Status_DoorState`;
      const programProgressId = `${targetDevice}.programs.active.options.BSH_Common_Option_ProgramProgress`;
      const alexaDevices = [
          "alexa2.0.Echo-Devices.G2A0U204838204UE",
          "alexa2.0.Echo-Devices.G090U610902505SE"
      ];
      
      // Zustand speichern, um Änderungen zu erkennen
      let lastDoorState = getState(doorStateId).val;
      
      // Funktion zum Senden einer Nachricht an Alexa
      function sendAlexaMessage(message) {
          try {
              alexa2.setState(alexaDevices, { text: message });
          } catch (error) {
              log.error(`Fehler beim Senden der Nachricht an Alexa: ${error}`);
          }
      }
      
      // Funktion zur Überprüfung der Uhrzeit
      function isBetweenHours(start, end) {
          const now = new Date();
          const hour = now.getHours();
          return hour >= start && hour < end;
      }
      
      // Hauptfunktion
      function checkSpuelmaschine() {
          try {
              const currentDoorState = getState(doorStateId).val;
              const programProgress = getState(programProgressId).val;
      
              // Nur reagieren, wenn sich der Türzustand von geschlossen auf geöffnet ändert und der Programmfortschritt bei 100% liegt
              if (currentDoorState === "Open" && lastDoorState === "Closed" && programProgress === 100) {
                  // Prüfe, ob die Uhrzeit zwischen 21:00 und 08:00 Uhr liegt
                  if (!isBetweenHours(21, 8)) {
                      sendAlexaMessage("Spülmaschine ist fertig");
                  }
              }
      
              // Aktuellen Türzustand speichern
              lastDoorState = currentDoorState;
          } catch (error) {
              log.error(`Fehler beim Überprüfen der Spülmaschine: ${error}`);
          }
      }
      
      // Skript alle 1 Minuten ausführen
      setInterval(checkSpuelmaschine, 1 * 60 * 1000);
      
      paul53 sigi234 3 Replies Last reply Reply Quote 0
      • paul53
        paul53 @d3adycool last edited by paul53

        @d3adycool sagte: Alexas bleiben Stumm.

        Man kann an setState(id, val) kein ID-Array übergeben, sondern man muss zwei setState() verwenden. Die Funktion alexa2.setState() kenne ich nicht, mit Alexa kenne ich mich allerdings nicht aus.

        Es wird geprüft, ob die Tür geöffnet wurde. Dafür verwendet man einen Trigger auf doorStateId anstelle eines Intervalls.

        Es gibt eine Funktion compareTime() des Javascript-Adapters.

        Bei "homeconnect" sind die Werte nicht "Open" und "Closed", sondern viel längere Strings. Schau die OBJEKTDATEN des Datenpunktes "Doorstate" an.

        D 1 Reply Last reply Reply Quote 0
        • D
          d3adycool @paul53 last edited by

          @paul53 Danke für diene schnelle Antwort aber ich setze ja nirgends einen Status ich frage diese ja nur mit einem getState ab.
          Du meinst also das ich den gesamten String (BSH.Common.EnumType.DoorState.Open)
          respektive
          (BSH.Common.EnumType.DoorState.Closed) im Code Abfragen muss.
          Sorry für die laienhaften Fragen aber bin da echt ein Noob auf dem Gebiet 😉

          paul53 1 Reply Last reply Reply Quote 0
          • paul53
            paul53 @d3adycool last edited by paul53

            @d3adycool sagte: Du meinst also das ich den gesamten String (BSH.Common.EnumType.DoorState.Open) respektive (BSH.Common.EnumType.DoorState.Closed) im Code Abfragen muss.

            Ja, das ist der Wert des Datenpunktes. Etwa so:

            // Konfiguration
            const targetDevice = "homeconnect.0.014060394661007096";
            const doorStateId = `${targetDevice}.status.BSH_Common_Status_DoorState`;
            const programProgressId = `${targetDevice}.programs.active.options.BSH_Common_Option_ProgramProgress`;
            const alexaDevice1 = "alexa2.0.Echo-Devices.G2A0U204838204UE";
            const alexaDevice2 = "alexa2.0.Echo-Devices.G090U610902505SE";
            
            // Funktion zum Senden einer Nachricht an Alexa
            function sendAlexaMessage(message) {
                setState(alexaDevice1 + '.Commands.speak', message);
                setState(alexaDevice2 + '.Commands.speak', message);
            }
             
            // Hauptfunktion
            on(doorStateId, function(dp) {
                const programProgress = getState(programProgressId).val;
                if (dp.state.val === "BSH.Common.EnumType.DoorState.Open" && programProgress === 100) {
                    // Prüfe, ob die Uhrzeit zwischen 21:00 und 08:00 Uhr liegt
                        if (compareTime('8:00', '21:00', 'between')) {
                            sendAlexaMessage("Spülmaschine ist fertig");
                        }
                    }
            });
            

            Enthält "ProgramProgress" einen Prozentwert und ist vom Typ "Zahl" (number).

            D 1 Reply Last reply Reply Quote 0
            • D
              d3adycool @paul53 last edited by

              @paul53 said in Spülmaschinen Abfrage mit Ausgabe über Alexa Geräte:

              on(doorStateId, function(dp) { const programProgress = getState(programProgressId).val; if (dp.state.val === "BSH.Common.EnumType.DoorState.Open" && dp.oldState.val === "BSH.Common.EnumType.DoorState.Closed" && programProgress === 100) { // Prüfe, ob die Uhrzeit zwischen 21:00 und 08:00 Uhr liegt if (compareTime('8:00', '21:00', 'not between')) { sendAlexaMessage("Spülmaschine ist fertig"); } }

              sofern ich das sehen kann ist das ein reiner Zahlenwert.

              Verstehe ich das richtig, dass ich den Codeschnippsel

              // Hauptfunktion
              function checkSpuelmaschine() {
                  try {
                      const currentDoorState = getState(doorStateId).val;
                      const programProgress = getState(programProgressId).val;
              
                      // Nur reagieren, wenn sich der Türzustand von geschlossen auf geöffnet ändert und der Programmfortschritt bei 100% liegt
                      if (currentDoorState === "Open" && lastDoorState === "Closed" && programProgress === 100) {
                          // Prüfe, ob die Uhrzeit zwischen 21:00 und 08:00 Uhr liegt
                          if (!isBetweenHours(21, 8)) {
                              sendAlexaMessage("Spülmaschine ist fertig");
                          }
                      }
              
                      // Aktuellen Türzustand speichern
                      lastDoorState = currentDoorState;
                  } catch (error) {
                      log.error(`Fehler beim Überprüfen der Spülmaschine: ${error}`);
                  }
              }
              

              mit deinem hier ersetzen soll, damit es läuft ?!

              Das ist der Wert aus den Objekten
              2024-09-12 19_33_02-objects - raspberrypi.png

              paul53 1 Reply Last reply Reply Quote 0
              • paul53
                paul53 @d3adycool last edited by

                @d3adycool sagte: ersetzen soll, damit es läuft ?!

                Ja, nur hab ich keine Ahnung, ob die Alexa-Funktion so funktioniert.

                D 1 Reply Last reply Reply Quote 0
                • D
                  d3adycool @paul53 last edited by

                  @paul53 wie müsste man es denn machen das sie spricht.
                  Vermutlich alles ummodeln

                  1 Reply Last reply Reply Quote 0
                  • paul53
                    paul53 @d3adycool last edited by paul53

                    @d3adycool sagte: Der Hintergrund warum ich den Programmfortschritt abgfrage ist da es keinen Wert gibt der mir sagt ob die Spülmaschine fertig ist oder nicht.

                    Genügt der Programmfortschritt nicht, um "Spülmaschine ist fertig" festzustellen?

                    on({id: programProgressId, change: 'gt', val: 100}, function() {
                        if (compareTime('8:00', '21:00', 'between')) {
                            sendAlexaMessage("Spülmaschine ist fertig");
                        }
                    });
                    
                    1 Reply Last reply Reply Quote 0
                    • paul53
                      paul53 last edited by paul53

                      @d3adycool sagte: wie müsste man es denn machen das sie spricht.

                      Wie bereits geschrieben: Von Alexa habe ich keine Ahnung. Es gibt eine Beschreibung zum Adapter.
                      Habe oben den Programm-Code angepasst.

                      1 Reply Last reply Reply Quote 0
                      • sigi234
                        sigi234 Forum Testing Most Active @d3adycool last edited by

                        @d3adycool

                        Nimm mal diesen DP als Ansage:

                        alexa2.0.Echo-Devices.XXXXXXXXXXXX.Commands.speak
                        
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        535
                        Online

                        31.9k
                        Users

                        80.2k
                        Topics

                        1.3m
                        Posts

                        3
                        10
                        328
                        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