Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. ioBroker Allgemein
    4. Text2command und javascript

    NEWS

    • Wir empfehlen: Node.js 22.x

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker goes Matter ... Matter Adapter in Stable

    Text2command und javascript

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

      Hallo iobroker-Gemeinde,

      ich habe ein Problem mit dem "External rules with javascript" vom github: https://github.com/ioBroker/ioBroker.text2command

      Wenn ich das Script einbaue und in dem Object javascript.0.textProcessor einen Text eingebe, z.B. Mist, dann erhalte ich im Log eine Fehlermeldung.

      javascript.0 2017-04-17 18:33:40.920 error at Object.parse (native)

      javascript.0 2017-04-17 18:33:40.920 error SyntaxError: Unexpected token M

      javascript.0 2017-04-17 18:33:40.912 error message javascript.0.textProcessor [object Object] Unexpected token M

      createState("textProcessor", '', function () {
        // text2command writes the value with ack=false. Change "any" is important too, to process repeated commands.
        on({id: "javascript.0.textProcessor", ack: false, change: 'any'}, function (obj) {
          var task = JSON.parse(obj.state.val);
      //    log (obj.state.val);
          if (task.command === "Test") {
            log ("Keywort gefunden","info");
             setState("javascript.0.textProcessor", 'Testnachricht empfangen.', true);
          } else {
              // let it process with predefined rules
              log ("Keywort nicht gefunden","info");
              setState("javascript.0.textProcessor", '', true);
          }
        });
      });
      

      Mir ist nicht klar, warum dieser Fehler entsteht. Ersetze ich task.command durch obj.state.val scheint es zu funktionieren, aber viele andere scheinen das Original zu nutzen.

      1 Reply Last reply Reply Quote 0
      • Bluefox
        Bluefox last edited by

        Diese Variable ist nicht für manuelle Bedienung.

        text2Command schriebt ein JSON Objekt rein. Du einfach Text.

        Modifiziere die Zeile:

        var task = JSON.parse(obj.state.val);
        

        auf

        var task = obj.state.val[0] === '{' ? JSON.parse(obj.state.val) : {command: obj.state.val};
        
        1 Reply Last reply Reply Quote 0
        • K
          Kamikaze last edited by

          Hallo Bluefox,

          vielen Dank für die schnelle Antwort. Hat prima funktioniert. Und mit deiner Erklärung kann ich auch zukünftig etwas anfangen.

          Problem gelöst.

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

          Support us

          ioBroker
          Community Adapters
          Donate
          FAQ Cloud / IOT
          HowTo: Node.js-Update
          HowTo: Backup/Restore
          Downloads
          BLOG

          841
          Online

          32.0k
          Users

          80.4k
          Topics

          1.3m
          Posts

          2
          3
          902
          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