Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Bitte um Hilfe bei MQTT zerlegen

    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

    Bitte um Hilfe bei MQTT zerlegen

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

      Hallo,
      ich habe Probleme beim zerlegen von einem Mqtt String.
      Der von hier verwendete Script zeigt keine Fehler.
      Es werden aber keine Datenpunkte angelegt.
      Ich kapier das einfach nicht, liegt wohl am Alter.

      hier mal der Script

      const JSPath = '0_userdata.0'/Example state/ // JS- Pfad
      const parsedStatesPath = JSPath + ".Pelletofen" // Pfad fuer geparste States
      const zigbee2mqttJsonPath = 'mqtt.0.service'/service/
      let IDs = [];

      $("[id=" + zigbee2mqttJsonPath + ".*]").each(function (id) {
      IDs.push(id)
      })

      on({id: IDs, change: "ne"}, function (obj) {
      let JsonObj = JSON.parse(obj.state.val)
      Object.keys(JsonObj).forEach(function(key){
      if (getState(obj.id.replace(zigbee2mqttJsonPath, parsedStatesPath)).notExist){
      createState(obj.id.replace(zigbee2mqttJsonPath, parsedStatesPath) + '.' + key, JsonObj[key], {read: true, write: true, type: typeof(JsonObj[key]), name: '' , desc: ''},function(){
      setState(obj.id.replace(zigbee2mqttJsonPath, parsedStatesPath) + '.' + key, JsonObj[key])
      })
      }else {
      setState(obj.id.replace(zigbee2mqttJsonPath, parsedStatesPath) + '.' + key, JsonObj[key])
      };
      })
      })

      1e7c0bb4-09ed-4202-b495-ddb2916ab141-grafik.png

      729b6c1c-7fd2-47b8-a763-dd8b4881d129-grafik.png

      Vilen Dank schonmal im voraus.
      Klaus

      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @Klaus-Anders last edited by paul53

        @klaus-anders
        Den Javascript-Code bitte in Code tags einbetten, da so nicht lesbar.

        Code_tags.JPG

        Wolltest Du die Datenpunkte nicht unter "0_userdata.0.Pelletofen" anlegen?

        const JSPath = '0_userdata.0'; // JS- Pfad
        const parsedStatesPath = JSPath + ".Pelletofen."; // Pfad fuer geparste States
        const idJSON = 'mqtt.0.service';
        
        on(idJSON, function (dp) {
            let JsonObj = JSON.parse(dp.state.val);
            Object.keys(JsonObj).forEach(function(key) {
                if(existsState(parsedStatesPath + key)) setState(parsedStatesPath + key, JsonObj[key], true);
                else createState(parsedStatesPath + key, JsonObj[key], {read: true, write: false, type: typeof JsonObj[key], name: key});
            });
        });
        
        K 1 Reply Last reply Reply Quote 1
        • K
          Klaus-Anders @paul53 last edited by

          @paul53
          Vielen Dank, das funzt.

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

          Support us

          ioBroker
          Community Adapters
          Donate

          849
          Online

          31.8k
          Users

          80.0k
          Topics

          1.3m
          Posts

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