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. Skripten / Logik
  4. JavaScript
  5. Bitte um Hilfe bei MQTT zerlegen

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

Bitte um Hilfe bei MQTT zerlegen

Scheduled Pinned Locked Moved JavaScript
3 Posts 2 Posters 566 Views 2 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.
  • K Offline
    K Offline
    Klaus-Anders
    wrote on last edited by
    #1

    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

    paul53P 1 Reply Last reply
    0
    • K Klaus-Anders

      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

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

      @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});
          });
      });
      

      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

      K 1 Reply Last reply
      1
      • paul53P 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 Offline
        K Offline
        Klaus-Anders
        wrote on last edited by
        #3

        @paul53
        Vielen Dank, das funzt.

        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

        737

        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