Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. (Gelöst) Zeichenkette in Zahl umwandeln (Aqara/Deconz/Vibrationssensor/Winkel)

    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

    (Gelöst) Zeichenkette in Zahl umwandeln (Aqara/Deconz/Vibrationssensor/Winkel)

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

      parseInt("5,-80,3".split(",")[1])

      split nacht aus dem string ein array indem es das , als trennkennzeichen interpretiert.
      Ergebnis sind 3 Elemente mit index 0,1 und 2
      Das 2.Element hat also den index 1
      das zur sicherheit nochmal als Zahl interpretiert.
      Falls hier auch Fließkommazahlen kommen können dann ersetzen mit parseFloat

      M 1 Reply Last reply Reply Quote 0
      • M
        muckel @OliverIO last edited by

        @OliverW
        Danke für den Input.
        Leider ist das Ergebnis nicht so wie gewünscht. Ich mache sicher etwas falsch.

        Blockly generiert folgenden Code:

        /**

        • Beschreibe diese Funktion …
          */
          function etwas_tun() {
          parseInt("deconz.0.Sensors.34.orientation".split(",")[1])
          return 1;
          }

        on({id: 'deconz.0.Sensors.34.orientation', change: "ne"}, function (obj) {
        var value = obj.state.val;
        var oldValue = obj.oldState.val;
        if (etwas_tun() < -20) {
        console.log((etwas_tun()));
        setState("javascript.0.Garage"/Garage/, 'Geschlossen', true);
        } else if (etwas_tun() > 0) {
        console.log((etwas_tun()));
        setState("javascript.0.Garage"/Garage/, 'Offen', true);
        }
        });

        Hast du eine Idee in Blockly?

        paul53 OliverIO T 3 Replies Last reply Reply Quote 0
        • paul53
          paul53 @muckel last edited by paul53

          @muckel sagte:

          Idee in Blockly?

          Blockly_Text3Werte_nach_Zahl.JPG

          Wert ist eine Eigenschaft des Triggerdatenpunktes (unter Blöcke Trigger).

          M 1 Reply Last reply Reply Quote 0
          • OliverIO
            OliverIO @muckel last edited by

            @muckel Blockly ist nicht so meins.
            Aber @paul53 hat glaub ich das in blockly umgesetzt

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

              @paul53

              Hallo Paul! Danke für deine Unterstützung. Ich habe dein Blockly nachgebaut.
              Leider bekomme ich bei Bewegung des Sensors immer folgenden Fehler:

              23:35:24.428 error javascript.0 at Object.<anonymous> (script.js.Garage_Offen_Zu:7:57)

              paul53 1 Reply Last reply Reply Quote 0
              • M
                muckel @OliverIO last edited by

                @OliverW
                Danke trotzdem. 🙂

                1 Reply Last reply Reply Quote 0
                • T
                  tim3trick @muckel last edited by

                  @muckel Deine Funktion "etwas_tun" erzeugt den Wert und returned dann 1.
                  Soll das so?

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

                    @muckel sagte:

                    script.js.Garage_Offen_Zu:7:57

                    Poste bitte den Javascript-Code ohne die letzte Zeile in Code tags.

                    M 1 Reply Last reply Reply Quote 0
                    • M
                      muckel @tim3trick last edited by

                      @tim3trick
                      Nein, das soll es natürlich nicht.
                      Paul hat glaube ich den richtigen Ansatz, aber etwas funktioniert noch nicht so richtig.
                      Oder ich habe im Blockly Mist gebaut.

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

                        @paul53

                        var Winkel;
                        
                        
                        on({id: 'deconz.0.Sensors.34.orientation', change: "ne"}, function (obj) {
                          var value = obj.state.val;
                          var oldValue = obj.oldState.val;
                          Winkel = parseFloat(((obj.state ? obj.state.val : "").split(',')[1]));
                          if (Winkel < -20) {
                            console.log(Winkel);
                            setState("javascript.0.Garage"/*Garage*/, 'Geschlossen', true);
                          } else if (Winkel > 0) {
                            console.log(Winkel);
                            setState("javascript.0.Garage"/*Garage*/, 'Offen', true);
                          }
                        });
                        

                        edit: sorry, finger waren schneller als das hirn.

                        T paul53 2 Replies Last reply Reply Quote 0
                        • T
                          tim3trick @muckel last edited by

                          @muckel sollte obj.state nicht gesetzt sein, nimmt er den Leerstring, splitted ihn nach Komma und nimmt das zweite Element des Arrays, um das nach Float zu Parsen. Es gibt aber kein zweites Element, entweder ist das schon der Fehler, oder zumindest ein potentieller Bug.

                          Alternative: als "Else" nimmst du "0,0,0"

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

                            @muckel .split(',') kann nicht auf den Wert des Datenpunktes angewendet werden. Füge mal vor setze Winkel einen debug output Wert ein. Was erscheint dann im Log ?

                            M T 2 Replies Last reply Reply Quote 0
                            • M
                              muckel @paul53 last edited by

                              @paul53

                              undefined 😞

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

                                @muckel sagte:

                                undefined

                                Du hast an debug output eine Variable Wert übergeben ? Es muss die Eigenschaft Wert des Triggerdatenpunktes sein.

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

                                  @paul53
                                  wie recht du hast:

                                  23:58:27.903 info javascript.0 script.js.Garage_Offen_Zu: 7,-80,7

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

                                    @paul53 interessehalber, wieso nicht?

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

                                      @muckel sagte:

                                      7,-80,7

                                      Das sieht eigentlich gut aus, garantiert aber nicht, dass der Datenpunkt tatsächlich einen String enthält. Logge mal den Typ von Wert (unter Konvertierung).

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

                                        @paul53
                                        00:04:59.382 info javascript.0 script.js.Garage_Offen_Zu: object

                                        {
                                        "from": "system.adapter.deconz.0",
                                        "user": "system.user.admin",
                                        "ts": 1556892868113,
                                        "common": {
                                        "name": "Garagentor orientation",
                                        "type": "string",
                                        "read": true,
                                        "write": false
                                        },
                                        "native": {},
                                        "acl": {
                                        "object": 1636,
                                        "owner": "system.user.admin",
                                        "ownerGroup": "system.group.administrator",
                                        "state": 1636
                                        },
                                        "_id": "deconz.0.Sensors.34.orientation",
                                        "type": "state"
                                        }

                                        paul53 2 Replies Last reply Reply Quote 0
                                        • T
                                          tim3trick last edited by

                                          Oder wir schummeln und casten den Wert implizit mit (""+obj.state.val) der implizite Cast bei console scheint ja zu klappen

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

                                            @muckel sagte:

                                            object

                                            Dann enthält er schon ein Array und muss nicht mehr gesplittet werden. Damit vereinfacht sich die Umwandlung:
                                            setze Winkel auf nach Zahl in der Liste Wert nimm das 2. Element.

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            618
                                            Online

                                            31.8k
                                            Users

                                            80.0k
                                            Topics

                                            1.3m
                                            Posts

                                            blockly
                                            5
                                            32
                                            2748
                                            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