Skip to content
  • 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
Logo
  1. ioBroker Community Home
  2. Deutsch
  3. Entwicklung
  4. State auslesen in Adapterentwicklung

NEWS

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

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

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

State auslesen in Adapterentwicklung

Scheduled Pinned Locked Moved Entwicklung
state auslesenadapterentwicklunggetstate
22 Posts 3 Posters 1.4k Views 4 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.
  • R reutli

    @Schnup89

    Danke für Deine Antwort, aber das ist es leider auch nicht...

    Code:

    	onStateChange(id, state) {
    		if (state) {
    			let mid = id.split('.')[2];
    			let trigger = id.split('.').pop();
    			this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
    
    			if (trigger == 'command') { // wenn Befehl an Mower verändert wurde
    				const command = state.val;
    				const time = this.getState('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration').val;
    				this.log.info('Variablen für Funktionsaufruf : command: ' + command + ' time: ' + time + ' mid: ' + mid);
    				//this.await.sendCommand(command, time, mid);
    			}
    		} else {
    			// The state was deleted
    			this.log.info(`state ${id} deleted`);
    		}
    	}
    

    Fehler:

    husqvarna_mowers.0	2020-04-20 08:52:54.205	error	at processImmediate (internal/timers.js:456:21)
    husqvarna_mowers.0	2020-04-20 08:52:54.205	error	at Immediate.<anonymous> (/usr/local/iobroker/node_modules/iobroker.js-controller/lib/adapter.js:4855:34)
    husqvarna_mowers.0	2020-04-20 08:52:54.205	error	at HusqvarnaMowers.emit (events.js:311:20)
    husqvarna_mowers.0	2020-04-20 08:52:54.205	error	at HusqvarnaMowers.onStateChange (/usr/local/iobroker/node_modules/iobroker.husqvarna_mowers/main.js:521:107)
    husqvarna_mowers.0	2020-04-20 08:52:54.205	error	(71636) TypeError: Cannot read property 'val' of undefined
    husqvarna_mowers.0	2020-04-20 08:52:54.205	error	(71636) uncaught exception: Cannot read property 'val' of undefined
    

    und der State ist m.E. auch da und korrekter String:

    {
      "type": "state",
      "common": {
        "name": "Duration of Command",
        "def": "24",
        "type": "number",
        "role": "indicator",
        "read": true,
        "write": true
      },
      "native": {},
      "from": "system.adapter.husqvarna_mowers.0",
      "user": "system.user.admin",
      "ts": 1587365605661,
      "_id": "husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration",
      "acl": {
        "object": 1638,
        "state": 1638
      }
    }
    
    Schnup89S Offline
    Schnup89S Offline
    Schnup89
    wrote on last edited by
    #9

    @reutli sagte in State auslesen in Adapterentwicklung:

    husqvarna_mowers.0 2020-04-20 08:52:54.205 error (71636) TypeError: Cannot read property 'val' of undefined

    husqvarna_mowers.0	2020-04-20 08:52:54.205	error	(71636) TypeError: Cannot read property 'val' of undefined
    

    .val entfernen 🙂

    const time = this.getState('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration').val;
    // zu ->>>>
    const time = this.getState('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration');						
    
    R 1 Reply Last reply
    0
    • R reutli

      @Schnup89

      Danke für Deine Antwort, aber das ist es leider auch nicht...

      Code:

      	onStateChange(id, state) {
      		if (state) {
      			let mid = id.split('.')[2];
      			let trigger = id.split('.').pop();
      			this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
      
      			if (trigger == 'command') { // wenn Befehl an Mower verändert wurde
      				const command = state.val;
      				const time = this.getState('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration').val;
      				this.log.info('Variablen für Funktionsaufruf : command: ' + command + ' time: ' + time + ' mid: ' + mid);
      				//this.await.sendCommand(command, time, mid);
      			}
      		} else {
      			// The state was deleted
      			this.log.info(`state ${id} deleted`);
      		}
      	}
      

      Fehler:

      husqvarna_mowers.0	2020-04-20 08:52:54.205	error	at processImmediate (internal/timers.js:456:21)
      husqvarna_mowers.0	2020-04-20 08:52:54.205	error	at Immediate.<anonymous> (/usr/local/iobroker/node_modules/iobroker.js-controller/lib/adapter.js:4855:34)
      husqvarna_mowers.0	2020-04-20 08:52:54.205	error	at HusqvarnaMowers.emit (events.js:311:20)
      husqvarna_mowers.0	2020-04-20 08:52:54.205	error	at HusqvarnaMowers.onStateChange (/usr/local/iobroker/node_modules/iobroker.husqvarna_mowers/main.js:521:107)
      husqvarna_mowers.0	2020-04-20 08:52:54.205	error	(71636) TypeError: Cannot read property 'val' of undefined
      husqvarna_mowers.0	2020-04-20 08:52:54.205	error	(71636) uncaught exception: Cannot read property 'val' of undefined
      

      und der State ist m.E. auch da und korrekter String:

      {
        "type": "state",
        "common": {
          "name": "Duration of Command",
          "def": "24",
          "type": "number",
          "role": "indicator",
          "read": true,
          "write": true
        },
        "native": {},
        "from": "system.adapter.husqvarna_mowers.0",
        "user": "system.user.admin",
        "ts": 1587365605661,
        "_id": "husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration",
        "acl": {
          "object": 1638,
          "state": 1638
        }
      }
      
      J.A.R.V.I.S.J Offline
      J.A.R.V.I.S.J Offline
      J.A.R.V.I.S.
      Developer
      wrote on last edited by J.A.R.V.I.S.
      #10

      @reutli

      Versuch eines der folgenden. Das was du oben versuchst funktioniert nicht, das ist vom JS Adapter.

      Await/Async

      const state = await this.getStateAsync('Dein Dp');
      

      oder

      Callback

      this.getState('Dein Dp', (error, state) => {
      
      });
      

      Bin mir beim unteren gerade nicht sicher, welche Werte alle übergeben werden

      R 1 Reply Last reply
      0
      • Schnup89S Schnup89

        @reutli sagte in State auslesen in Adapterentwicklung:

        husqvarna_mowers.0 2020-04-20 08:52:54.205 error (71636) TypeError: Cannot read property 'val' of undefined

        husqvarna_mowers.0	2020-04-20 08:52:54.205	error	(71636) TypeError: Cannot read property 'val' of undefined
        

        .val entfernen 🙂

        const time = this.getState('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration').val;
        // zu ->>>>
        const time = this.getState('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration');						
        
        R Online
        R Online
        reutli
        wrote on last edited by
        #11

        @Schnup89

        Das habe ich auch bereits versucht.... dann bekomme ich zwar keinen Fehler, aber auch keinen Wert (time ist dann undefined):

        (71874) Variablen für Funktionsaufruf : command: Pause time: undefined mid: 6dcad25a-39f7-4baf-9f44-877302c35c1f
        

        BITTE BEACHTET DOCH DAS: https://forum.iobroker.net/topic/51555/hinweise-für-gute-forenbeiträge
        iobroker in Debian-VM auf Proxmox Server (Ryzen 7 / 32GB / 1TB NVMe SSD) als Master - mehrere Raspberry Pis (3+4) als Slaves. InfluxDB V2 und Grafana auf LXC.

        *Wer freundlich ist, dem wird freundlich geholfen *

        1 Reply Last reply
        0
        • J.A.R.V.I.S.J J.A.R.V.I.S.

          @reutli

          Versuch eines der folgenden. Das was du oben versuchst funktioniert nicht, das ist vom JS Adapter.

          Await/Async

          const state = await this.getStateAsync('Dein Dp');
          

          oder

          Callback

          this.getState('Dein Dp', (error, state) => {
          
          });
          

          Bin mir beim unteren gerade nicht sicher, welche Werte alle übergeben werden

          R Online
          R Online
          reutli
          wrote on last edited by
          #12

          @J-A-R-V-I-S sagte in State auslesen in Adapterentwicklung:

          Versuch eines der folgenden. Das was du oben versuchst funktioniert nicht, das ist vom JS Adapter.
          Await/Async
          const state = await this.getStateAsync('Dein Dp');

          Dann müsste ich eine komplette ASYNC Funktion aufbauen, weil ich ja in der 'OnStateChange' keinen await aufrufen kann?!

          BITTE BEACHTET DOCH DAS: https://forum.iobroker.net/topic/51555/hinweise-für-gute-forenbeiträge
          iobroker in Debian-VM auf Proxmox Server (Ryzen 7 / 32GB / 1TB NVMe SSD) als Master - mehrere Raspberry Pis (3+4) als Slaves. InfluxDB V2 und Grafana auf LXC.

          *Wer freundlich ist, dem wird freundlich geholfen *

          J.A.R.V.I.S.J 1 Reply Last reply
          0
          • R reutli

            @J-A-R-V-I-S sagte in State auslesen in Adapterentwicklung:

            Versuch eines der folgenden. Das was du oben versuchst funktioniert nicht, das ist vom JS Adapter.
            Await/Async
            const state = await this.getStateAsync('Dein Dp');

            Dann müsste ich eine komplette ASYNC Funktion aufbauen, weil ich ja in der 'OnStateChange' keinen await aufrufen kann?!

            J.A.R.V.I.S.J Offline
            J.A.R.V.I.S.J Offline
            J.A.R.V.I.S.
            Developer
            wrote on last edited by
            #13

            @reutli du kannst die einfach zu einer Async machen, indem du async davor schreibst.

            async onStateChange(id, state)
            
            R 1 Reply Last reply
            0
            • J.A.R.V.I.S.J J.A.R.V.I.S.

              @reutli du kannst die einfach zu einer Async machen, indem du async davor schreibst.

              async onStateChange(id, state)
              
              R Online
              R Online
              reutli
              wrote on last edited by
              #14

              @J-A-R-V-I-S

              Hi,

              nope leider nicht.
              Erhalte mit '.val' einen undefined bei 'time' (und ohne '.val' natürlich ein Object):

              (72098) Variablen für Funktionsaufruf : command: Pause time: undefined mid: 6dcad25a-39f7-4baf-9f44-877302c35c1f
              

              hier der code:

              	async onStateChange(id, state) {
              		if (state) {
              			let mid = id.split('.')[2];
              			let trigger = id.split('.').pop();
              			this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
              
              			if (trigger == 'command') { // wenn Befehl an Mower verändert wurde
              				const command = state.val;
              				const time = await this.getStateAsync('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration').val;
              				this.log.info('Variablen für Funktionsaufruf : command: ' + command + ' time: ' + time + ' mid: ' + mid);
              				//this.await.sendCommand(command, time, mid);
              			}
              		} else {
              			// The state was deleted
              			this.log.info(`state ${id} deleted`);
              		}
              	}
              

              BITTE BEACHTET DOCH DAS: https://forum.iobroker.net/topic/51555/hinweise-für-gute-forenbeiträge
              iobroker in Debian-VM auf Proxmox Server (Ryzen 7 / 32GB / 1TB NVMe SSD) als Master - mehrere Raspberry Pis (3+4) als Slaves. InfluxDB V2 und Grafana auf LXC.

              *Wer freundlich ist, dem wird freundlich geholfen *

              J.A.R.V.I.S.J 1 Reply Last reply
              0
              • R reutli

                @J-A-R-V-I-S

                Hi,

                nope leider nicht.
                Erhalte mit '.val' einen undefined bei 'time' (und ohne '.val' natürlich ein Object):

                (72098) Variablen für Funktionsaufruf : command: Pause time: undefined mid: 6dcad25a-39f7-4baf-9f44-877302c35c1f
                

                hier der code:

                	async onStateChange(id, state) {
                		if (state) {
                			let mid = id.split('.')[2];
                			let trigger = id.split('.').pop();
                			this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
                
                			if (trigger == 'command') { // wenn Befehl an Mower verändert wurde
                				const command = state.val;
                				const time = await this.getStateAsync('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration').val;
                				this.log.info('Variablen für Funktionsaufruf : command: ' + command + ' time: ' + time + ' mid: ' + mid);
                				//this.await.sendCommand(command, time, mid);
                			}
                		} else {
                			// The state was deleted
                			this.log.info(`state ${id} deleted`);
                		}
                	}
                
                J.A.R.V.I.S.J Offline
                J.A.R.V.I.S.J Offline
                J.A.R.V.I.S.
                Developer
                wrote on last edited by J.A.R.V.I.S.
                #15

                @reutli lass dir mal den ganzen State ausgeben, ohne .val.

                this.log.info(JSON.stringify(time));
                

                Und mach mal einen try/catch Block drum. Damit fängst du die möglichen Fehler ab.

                R 1 Reply Last reply
                0
                • J.A.R.V.I.S.J J.A.R.V.I.S.

                  @reutli lass dir mal den ganzen State ausgeben, ohne .val.

                  this.log.info(JSON.stringify(time));
                  

                  Und mach mal einen try/catch Block drum. Damit fängst du die möglichen Fehler ab.

                  R Online
                  R Online
                  reutli
                  wrote on last edited by
                  #16

                  @J-A-R-V-I-S sagte in State auslesen in Adapterentwicklung:

                  this.log.info(JSON.stringify(time));

                  jetzt bekomme ich Werte zurück:

                  (72271) {"val":"24","ack":true,"ts":1587366996004,"q":0,"from":"system.adapter.husqvarna_mowers.0","user":"system.user.admin","lc":1587295118488}
                  

                  Warum bekommen ich diesen nicht in die const?

                  BITTE BEACHTET DOCH DAS: https://forum.iobroker.net/topic/51555/hinweise-für-gute-forenbeiträge
                  iobroker in Debian-VM auf Proxmox Server (Ryzen 7 / 32GB / 1TB NVMe SSD) als Master - mehrere Raspberry Pis (3+4) als Slaves. InfluxDB V2 und Grafana auf LXC.

                  *Wer freundlich ist, dem wird freundlich geholfen *

                  J.A.R.V.I.S.J 1 Reply Last reply
                  0
                  • R reutli

                    @J-A-R-V-I-S sagte in State auslesen in Adapterentwicklung:

                    this.log.info(JSON.stringify(time));

                    jetzt bekomme ich Werte zurück:

                    (72271) {"val":"24","ack":true,"ts":1587366996004,"q":0,"from":"system.adapter.husqvarna_mowers.0","user":"system.user.admin","lc":1587295118488}
                    

                    Warum bekommen ich diesen nicht in die const?

                    J.A.R.V.I.S.J Offline
                    J.A.R.V.I.S.J Offline
                    J.A.R.V.I.S.
                    Developer
                    wrote on last edited by
                    #17

                    @reutli dann schreib es in eine neue Zeile;

                    const state = await this.getStateAsync('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration');
                    const time = state.val;	
                    
                    R 1 Reply Last reply
                    0
                    • J.A.R.V.I.S.J J.A.R.V.I.S.

                      @reutli dann schreib es in eine neue Zeile;

                      const state = await this.getStateAsync('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration');
                      const time = state.val;	
                      
                      R Online
                      R Online
                      reutli
                      wrote on last edited by reutli
                      #18

                      @J-A-R-V-I-S

                      ok, danke.
                      Jetzt bekomme ich einen Wert:

                      (72584) Variablen für Funktionsaufruf : command: Pause time: 24 mid: 6dcad25a-39f7-4baf-9f44-877302c35c1f
                      

                      mit dem Code:

                      async onStateChange(id, state) {
                      		if (state) {
                      			let mid = id.split('.')[2];
                      			let trigger = id.split('.').pop();
                      			this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
                      
                      			if (trigger == 'command') { // wenn Befehl an Mower verändert wurde
                      				const command = state.val;
                      				const state_check = await this.getStateAsync('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration');
                      				this.log.info(JSON.stringify(state_check));
                      				const time = state_check.val;
                      				this.log.info('Variablen für Funktionsaufruf : command: ' + command + ' time: ' + time + ' mid: ' + mid);
                      				//this.await.sendCommand(command, time, mid);
                      			}
                      		} else {
                      			// The state was deleted
                      			this.log.info(`state ${id} deleted`);
                      		}
                      	}
                      

                      Aber: Warum muss ich aus dem ganzen 'onStateChange' eine Async machen? Das habe ich nicht verstanden (und auch noch nirgendwo so gesehen....?

                      Ich frage noch anders: Wie muss ich sonst (außerhalb des 'on StateChange') dann einen State abfragen?

                      Sorry wenn ich so nachfrage, versuche eben zu lernen...

                      Danke!

                      PS: kannst Du mir für mein Beispiel ein sauberes "Try/Catch" zeigen, damit ich das korrekt in andere Bereich übernehmen kann? Habe hier schon einiges an Doku gelesen, aber noch nicht so ganz kapiert...

                      BITTE BEACHTET DOCH DAS: https://forum.iobroker.net/topic/51555/hinweise-für-gute-forenbeiträge
                      iobroker in Debian-VM auf Proxmox Server (Ryzen 7 / 32GB / 1TB NVMe SSD) als Master - mehrere Raspberry Pis (3+4) als Slaves. InfluxDB V2 und Grafana auf LXC.

                      *Wer freundlich ist, dem wird freundlich geholfen *

                      J.A.R.V.I.S.J 2 Replies Last reply
                      0
                      • R reutli

                        @J-A-R-V-I-S

                        ok, danke.
                        Jetzt bekomme ich einen Wert:

                        (72584) Variablen für Funktionsaufruf : command: Pause time: 24 mid: 6dcad25a-39f7-4baf-9f44-877302c35c1f
                        

                        mit dem Code:

                        async onStateChange(id, state) {
                        		if (state) {
                        			let mid = id.split('.')[2];
                        			let trigger = id.split('.').pop();
                        			this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
                        
                        			if (trigger == 'command') { // wenn Befehl an Mower verändert wurde
                        				const command = state.val;
                        				const state_check = await this.getStateAsync('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration');
                        				this.log.info(JSON.stringify(state_check));
                        				const time = state_check.val;
                        				this.log.info('Variablen für Funktionsaufruf : command: ' + command + ' time: ' + time + ' mid: ' + mid);
                        				//this.await.sendCommand(command, time, mid);
                        			}
                        		} else {
                        			// The state was deleted
                        			this.log.info(`state ${id} deleted`);
                        		}
                        	}
                        

                        Aber: Warum muss ich aus dem ganzen 'onStateChange' eine Async machen? Das habe ich nicht verstanden (und auch noch nirgendwo so gesehen....?

                        Ich frage noch anders: Wie muss ich sonst (außerhalb des 'on StateChange') dann einen State abfragen?

                        Sorry wenn ich so nachfrage, versuche eben zu lernen...

                        Danke!

                        PS: kannst Du mir für mein Beispiel ein sauberes "Try/Catch" zeigen, damit ich das korrekt in andere Bereich übernehmen kann? Habe hier schon einiges an Doku gelesen, aber noch nicht so ganz kapiert...

                        J.A.R.V.I.S.J Offline
                        J.A.R.V.I.S.J Offline
                        J.A.R.V.I.S.
                        Developer
                        wrote on last edited by
                        #19

                        @reutli der Try/Catch sieht wie folgt aus:

                        try {
                        /*
                        Hier all der Code bei dem Fehler abgefangen werden sollen.
                        Sollte ein Fehler geworfen werden, wird der Code, der im Try/Catch steht nicht weiter ausgeführt, Code nach dem Try/Catch wird aber weiter ausgeführt.
                        */
                        } catch(error) {
                            this.log.error(error);
                        }
                        
                        R 1 Reply Last reply
                        0
                        • R reutli

                          @J-A-R-V-I-S

                          ok, danke.
                          Jetzt bekomme ich einen Wert:

                          (72584) Variablen für Funktionsaufruf : command: Pause time: 24 mid: 6dcad25a-39f7-4baf-9f44-877302c35c1f
                          

                          mit dem Code:

                          async onStateChange(id, state) {
                          		if (state) {
                          			let mid = id.split('.')[2];
                          			let trigger = id.split('.').pop();
                          			this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
                          
                          			if (trigger == 'command') { // wenn Befehl an Mower verändert wurde
                          				const command = state.val;
                          				const state_check = await this.getStateAsync('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration');
                          				this.log.info(JSON.stringify(state_check));
                          				const time = state_check.val;
                          				this.log.info('Variablen für Funktionsaufruf : command: ' + command + ' time: ' + time + ' mid: ' + mid);
                          				//this.await.sendCommand(command, time, mid);
                          			}
                          		} else {
                          			// The state was deleted
                          			this.log.info(`state ${id} deleted`);
                          		}
                          	}
                          

                          Aber: Warum muss ich aus dem ganzen 'onStateChange' eine Async machen? Das habe ich nicht verstanden (und auch noch nirgendwo so gesehen....?

                          Ich frage noch anders: Wie muss ich sonst (außerhalb des 'on StateChange') dann einen State abfragen?

                          Sorry wenn ich so nachfrage, versuche eben zu lernen...

                          Danke!

                          PS: kannst Du mir für mein Beispiel ein sauberes "Try/Catch" zeigen, damit ich das korrekt in andere Bereich übernehmen kann? Habe hier schon einiges an Doku gelesen, aber noch nicht so ganz kapiert...

                          J.A.R.V.I.S.J Offline
                          J.A.R.V.I.S.J Offline
                          J.A.R.V.I.S.
                          Developer
                          wrote on last edited by
                          #20

                          @reutli sagte in State auslesen in Adapterentwicklung:

                          Ich frage noch anders: Wie muss ich sonst (außerhalb des 'on StateChange') dann einen State abfragen?

                          Entweder du machst es dort auch mit Async Methoden oder du verwendest die Möglichkeit mit Callbacks.

                          R 1 Reply Last reply
                          0
                          • J.A.R.V.I.S.J J.A.R.V.I.S.

                            @reutli der Try/Catch sieht wie folgt aus:

                            try {
                            /*
                            Hier all der Code bei dem Fehler abgefangen werden sollen.
                            Sollte ein Fehler geworfen werden, wird der Code, der im Try/Catch steht nicht weiter ausgeführt, Code nach dem Try/Catch wird aber weiter ausgeführt.
                            */
                            } catch(error) {
                                this.log.error(error);
                            }
                            
                            R Online
                            R Online
                            reutli
                            wrote on last edited by
                            #21

                            @J-A-R-V-I-S

                            Dann wäre mein try/catch so richtig, oder:

                            			try {
                            				if (trigger == 'command') { // wenn Befehl an Mower verändert wurde
                            					const command = state.val;
                            					const state_check = await this.getStateAsync('husqvarna_mowers.0.6dcad25a-39f7-4baf-9f44-877302c35c1f.Control.duration');
                            					this.log.info(JSON.stringify(state_check));
                            					const time = state_check.val;
                            					this.log.info('Variablen für Funktionsaufruf : command: ' + command + ' time: ' + time + ' mid: ' + mid);
                            					//this.await.sendCommand(command, time, mid);
                            				}
                            			} catch(e) {
                            				this.log.error(e);
                            			}
                            

                            BITTE BEACHTET DOCH DAS: https://forum.iobroker.net/topic/51555/hinweise-für-gute-forenbeiträge
                            iobroker in Debian-VM auf Proxmox Server (Ryzen 7 / 32GB / 1TB NVMe SSD) als Master - mehrere Raspberry Pis (3+4) als Slaves. InfluxDB V2 und Grafana auf LXC.

                            *Wer freundlich ist, dem wird freundlich geholfen *

                            1 Reply Last reply
                            0
                            • J.A.R.V.I.S.J J.A.R.V.I.S.

                              @reutli sagte in State auslesen in Adapterentwicklung:

                              Ich frage noch anders: Wie muss ich sonst (außerhalb des 'on StateChange') dann einen State abfragen?

                              Entweder du machst es dort auch mit Async Methoden oder du verwendest die Möglichkeit mit Callbacks.

                              R Online
                              R Online
                              reutli
                              wrote on last edited by
                              #22

                              @J-A-R-V-I-S sagte in State auslesen in Adapterentwicklung:

                              @reutli sagte in State auslesen in Adapterentwicklung:

                              Ich frage noch anders: Wie muss ich sonst (außerhalb des 'on StateChange') dann einen State abfragen?

                              Entweder du machst es dort auch mit Async Methoden oder du verwendest die Möglichkeit mit Callbacks.

                              ok, aber im 'OnStateChange' muss ich beim Async bleiben, oder wie wäre dort das callback-Szenario zu lösen?

                              BITTE BEACHTET DOCH DAS: https://forum.iobroker.net/topic/51555/hinweise-für-gute-forenbeiträge
                              iobroker in Debian-VM auf Proxmox Server (Ryzen 7 / 32GB / 1TB NVMe SSD) als Master - mehrere Raspberry Pis (3+4) als Slaves. InfluxDB V2 und Grafana auf LXC.

                              *Wer freundlich ist, dem wird freundlich geholfen *

                              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

                              736

                              Online

                              32.4k

                              Users

                              81.4k

                              Topics

                              1.3m

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

                              • Don't have an account? Register

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