Skip to content
  • Home
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JavaScript
  5. [gelöst]Vergleich String mit State.val fehlerhaft

NEWS

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    8.8k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    13
    1
    2.2k

  • Neues Video "KI im Smart Home" - ioBroker plus n8n
    BluefoxB
    Bluefox
    16
    1
    3.4k

[gelöst]Vergleich String mit State.val fehlerhaft

Scheduled Pinned Locked Moved JavaScript
5 Posts 2 Posters 720 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nordstern19_72
    wrote on last edited by nordstern19_72
    #1

    Hallo Community,

    ich habe ein Problem mit einem Vergleich eines State.val mit einem String.
    Hier der Skriptteil, der nicht so funktioniert wie ich mir das vorstelle:

    function checkCommand (ZwayId, ZwayCommand){
        if(!existsState(ZwayId + '.id')){
            log('setDevices: ZwayId nicht vorhanden');
            return false;
        }else{
            let DeviceType = getState(ZwayId + '.deviceType');
            log('setDevices: typeof: ' + typeof(DeviceType.val));
            log('setDevices: Wert: ' + DeviceType.val);
            log('setDevices: Kommando: ' + ZwayCommand);
            
            if(DeviceType.val == 'switchBinary'){
                log('setDevices: Typ switchBinary erkannt');
                if (!regexSwitchBinary.test(ZwayCommand)){
                        log('setDevices: ZwayCommand nicht erlaubt');
                        return false;
                    }else{
                        log('setDevices: ZwayCommand erlaubt');
                        return true;
                }
            }
        }
        return false;
    }
    

    Der if in Zeile 11 wird nicht true, obwohl typeof(DeviceType.val) 'string' im Log ausgibt und der Wert auch 'switchBinary' ist.
    Wo ist mein Denkfehler?
    Bin für jeden Tipp dankbar...

    Gruß
    nordstern

    paul53P 1 Reply Last reply
    0
    • N nordstern19_72

      Hallo Community,

      ich habe ein Problem mit einem Vergleich eines State.val mit einem String.
      Hier der Skriptteil, der nicht so funktioniert wie ich mir das vorstelle:

      function checkCommand (ZwayId, ZwayCommand){
          if(!existsState(ZwayId + '.id')){
              log('setDevices: ZwayId nicht vorhanden');
              return false;
          }else{
              let DeviceType = getState(ZwayId + '.deviceType');
              log('setDevices: typeof: ' + typeof(DeviceType.val));
              log('setDevices: Wert: ' + DeviceType.val);
              log('setDevices: Kommando: ' + ZwayCommand);
              
              if(DeviceType.val == 'switchBinary'){
                  log('setDevices: Typ switchBinary erkannt');
                  if (!regexSwitchBinary.test(ZwayCommand)){
                          log('setDevices: ZwayCommand nicht erlaubt');
                          return false;
                      }else{
                          log('setDevices: ZwayCommand erlaubt');
                          return true;
                  }
              }
          }
          return false;
      }
      

      Der if in Zeile 11 wird nicht true, obwohl typeof(DeviceType.val) 'string' im Log ausgibt und der Wert auch 'switchBinary' ist.
      Wo ist mein Denkfehler?
      Bin für jeden Tipp dankbar...

      Gruß
      nordstern

      paul53P Offline
      paul53P Offline
      paul53
      wrote on last edited by
      #2

      @nordstern19_72
      Sieht alles richtig aus. Log ?

      Bitte verzichtet auf Chat-Nachrichten, denn die Handhabung ist grauenhaft !
      Produktiv: RPi 2 mit S.USV, HM-MOD-RPI und SLC-USB-Stick mit root fs

      N 1 Reply Last reply
      0
      • paul53P paul53

        @nordstern19_72
        Sieht alles richtig aus. Log ?

        N Offline
        N Offline
        nordstern19_72
        wrote on last edited by
        #3

        @paul53
        Ja, keine (roten) Fehler.

        Skript aktuell:

        function checkCommand (ZwayId, ZwayCommand){
            if(!existsState(ZwayId + '.id')){
                log('setDevices: ZwayId nicht vorhanden');
                return false;
            }else{
                let DeviceType = getState(ZwayId + '.deviceType');
                if(getState('ZwayDebug').val==1){
                    log('setDevices: typeof: ' + typeof(DeviceType.val));
                    log('setDevices: Wert: ' + DeviceType.val);
                    log('setDevices: Kommando: ' + ZwayCommand);
                }
                
                //if(DeviceType.val == 'switchBinary'){
                if(DeviceType.val == DeviceType.val){
                    if(getState('ZwayDebug').val==1){
                        log('setDevices: Typ switchBinary erkannt');
                    }
                    if (!regexSwitchBinary.test(ZwayCommand)){
                            log('setDevices: ZwayCommand nicht erlaubt');
                            return false;
                        }else{
                            if(getState('ZwayDebug').val==1){
                                log('setDevices: ZwayCommand erlaubt');
                            }
                            return true;
                    }
                }
            }
            return false;
        }
        

        Log:

        javascript.0	2020-01-22 19:52:35.856	info	(12468) script.js.common.setDevice: setDevices: Command: Ok: 200
        javascript.0	2020-01-22 19:52:35.708	info	(12468) script.js.common.setDevice: setDevices: ZwayCommand erlaubt
        javascript.0	2020-01-22 19:52:35.708	info	(12468) script.js.common.setDevice: setDevices: Typ switchBinary erkannt
        javascript.0	2020-01-22 19:52:35.707	info	(12468) script.js.common.setDevice: setDevices: Kommando: on
        javascript.0	2020-01-22 19:52:35.707	info	(12468) script.js.common.setDevice: setDevices: Wert: switchBinary
        javascript.0	2020-01-22 19:52:35.707	info	(12468) script.js.common.setDevice: setDevices: typeof: string
        javascript.0	2020-01-22 19:52:32.041	info	(12468) script.js.common.setDevice: registered 2 subscriptions and 0 schedules
        javascript.0	2020-01-22 19:52:32.037	info	(12468) Start javascript script.js.common.setDevice
        

        Habe das if mal 'gebrückt' für ein komplettes Log und um zu sehen, ob sonst alles funktioniert.

        paul53P 1 Reply Last reply
        0
        • N nordstern19_72

          @paul53
          Ja, keine (roten) Fehler.

          Skript aktuell:

          function checkCommand (ZwayId, ZwayCommand){
              if(!existsState(ZwayId + '.id')){
                  log('setDevices: ZwayId nicht vorhanden');
                  return false;
              }else{
                  let DeviceType = getState(ZwayId + '.deviceType');
                  if(getState('ZwayDebug').val==1){
                      log('setDevices: typeof: ' + typeof(DeviceType.val));
                      log('setDevices: Wert: ' + DeviceType.val);
                      log('setDevices: Kommando: ' + ZwayCommand);
                  }
                  
                  //if(DeviceType.val == 'switchBinary'){
                  if(DeviceType.val == DeviceType.val){
                      if(getState('ZwayDebug').val==1){
                          log('setDevices: Typ switchBinary erkannt');
                      }
                      if (!regexSwitchBinary.test(ZwayCommand)){
                              log('setDevices: ZwayCommand nicht erlaubt');
                              return false;
                          }else{
                              if(getState('ZwayDebug').val==1){
                                  log('setDevices: ZwayCommand erlaubt');
                              }
                              return true;
                      }
                  }
              }
              return false;
          }
          

          Log:

          javascript.0	2020-01-22 19:52:35.856	info	(12468) script.js.common.setDevice: setDevices: Command: Ok: 200
          javascript.0	2020-01-22 19:52:35.708	info	(12468) script.js.common.setDevice: setDevices: ZwayCommand erlaubt
          javascript.0	2020-01-22 19:52:35.708	info	(12468) script.js.common.setDevice: setDevices: Typ switchBinary erkannt
          javascript.0	2020-01-22 19:52:35.707	info	(12468) script.js.common.setDevice: setDevices: Kommando: on
          javascript.0	2020-01-22 19:52:35.707	info	(12468) script.js.common.setDevice: setDevices: Wert: switchBinary
          javascript.0	2020-01-22 19:52:35.707	info	(12468) script.js.common.setDevice: setDevices: typeof: string
          javascript.0	2020-01-22 19:52:32.041	info	(12468) script.js.common.setDevice: registered 2 subscriptions and 0 schedules
          javascript.0	2020-01-22 19:52:32.037	info	(12468) Start javascript script.js.common.setDevice
          

          Habe das if mal 'gebrückt' für ein komplettes Log und um zu sehen, ob sonst alles funktioniert.

          paul53P Offline
          paul53P Offline
          paul53
          wrote on last edited by
          #4

          @nordstern19_72
          Ergänze mal

                      log('setDevices: Länge: ' + DeviceType.val.length);
          

          Vielleicht hängt noch ein unsichtbares Zeichen dran ?

          Bitte verzichtet auf Chat-Nachrichten, denn die Handhabung ist grauenhaft !
          Produktiv: RPi 2 mit S.USV, HM-MOD-RPI und SLC-USB-Stick mit root fs

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nordstern19_72
            wrote on last edited by nordstern19_72
            #5

            Tatsächlich...

            javascript.0	2020-01-22 20:18:14.246	info	(12468) script.js.common.setDevice: setDevices: Länge: 13
            

            Ich probiere mal .trim()

            Edit:
            Funktioniert...

            Danke!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            Support us

            ioBroker
            Community Adapters
            Donate

            578

            Online

            32.4k

            Users

            81.5k

            Topics

            1.3m

            Posts
            Community
            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
            ioBroker Community 2014-2025
            logo
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Home
            • Recent
            • Tags
            • Unread 0
            • Categories
            • Unreplied
            • Popular
            • GitHub
            • Docu
            • Hilfe