Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. source does not exist for "read" function

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    source does not exist for "read" function

    This topic has been deleted. Only users with topic management privileges can see it.
    • Thomas Braun
      Thomas Braun Most Active @Homoran last edited by

      Das 'Konvertier'-Skript:

      // where the mqtt messages arrive
      
      const mqttDatenpunktObjectId = 'mqtt.0.solix.site.Stromstausee.scenInfo';
      
      // where the states should appear
      
      const userDataFolder = '0_userdata.0.solix';
      
       
      
      // ############## end user config
      
       
      
      // receive
      
      on(mqttDatenpunktObjectId, (obj) => {
        // log(JSON.stringify(obj.state.val))
        const jsonString = obj.state.val;
      
        const jsonData = JSON.parse(jsonString);
      
       
      
        function createObjectsRecursively(parent, data) {
      
          for (const key in data) {
      
            const obj = data[key];
      
            const stateName = `${parent}.${key}`;
      
           
      
            if (typeof obj === 'object') {
      
              createObjectsRecursively(stateName, obj);
      
            } else {
      
             let value = obj;  
      
       
      
              // Check if the state already exists. If it does, just update the value.
      
              // If it does not exist create the states.
      
              if (!existsState(stateName)) {
      
                // If the state does not exist, create it and set the value
      
                createState(stateName, value, {
      
                  name: key,
      
                  type: typeof value,
      
                  role: "value",
      
                  read: true,
      
                  write: true
      
                });
      
                log(`Created state ${stateName}`);
      
                
      
              } else {
                // log(stateName + ': ' + value)
                setState(stateName, value, true);
      
              }
      
            }
      
          }
      
        }
      
         createObjectsRecursively(userDataFolder, jsonData);
      
      });
      
      mickym 1 Reply Last reply Reply Quote 0
      • mickym
        mickym Most Active @Thomas Braun last edited by mickym

        @thomas-braun sagte in source does not exist for "read" function:

                type: typeof value,
        

        das stellt das immer wieder zurück. Es kann ja sein, dass im Objekt ein Komma anstelle eines Dezimalpunktes steht und schon kann dieses Skript nicht funktionieren.

        Wie gesagt ich würde als schnelle Massnahme - ohne hier lange im Script rumzusuchen oder warum das Skript immer wieder umstellt, im Alias direkt das Objekt aus

        mqtt.0.solix.site.Stromstausee.scenInfo
        

        auslesen. Das sind ja alles Infos, die vorher nicht da waren und ich bin davon ausgegangen, dass das so direkt aus mosquitto kommt, was es aber nicht tut.

        Also poste lieber mal das Objekt und dann extrahieren wir das im Alias.

        Thomas Braun 2 Replies Last reply Reply Quote 0
        • Thomas Braun
          Thomas Braun Most Active @mickym last edited by

          @mickym

          Danke, hab da keinen Bock mehr drauf dran herumzufrickeln.
          Das bleibt jetzt so. Steht halt im echart statt xy% 0,xy%

          mickym 1 Reply Last reply Reply Quote 0
          • mickym
            mickym Most Active @Thomas Braun last edited by

            @thomas-braun Was ist den schlimm dieses Objekt zu posten, also den Wert von

            mqtt.0.solix.site.Stromstausee.scenInfo
            

            Aber wenn Du keine Lust hast, dann halt nicht.

            Thomas Braun 1 Reply Last reply Reply Quote 0
            • Thomas Braun
              Thomas Braun Most Active @mickym last edited by

              @mickym sagte in source does not exist for "read" function:

              Es kann ja sein, dass im Objekt ein Komma anstelle eines Dezimalpunktes steht

              Das könnte sogar sein. Im rohen JSON steht der Wert mit Dezimalpunkt drin, nicht mit Komma.
              Möglich, das es von Anker bei einem Update geändert wurde. Bis vor ein paar Tagen hat das nämlich so funktioniert und ich habe da selber nix verändert.

              mickym 1 Reply Last reply Reply Quote 0
              • mickym
                mickym Most Active @Thomas Braun last edited by

                @thomas-braun sagte in source does not exist for "read" function:

                Das könnte sogar sein. Im rohen JSON steht der Wert mit Dezimalpunkt drin, nicht mit Komma.

                Na also war doch meine Vermutung richtig. Also musst du das Komma durch einen Punkt ersetzen und dann kann man es im Alias richtig verwenden. Deswegen poste halt das Objekt - das Skript wird Dir das niemals lösen, da eine Zahl mit einem Dezimalkomma immer als String erkannt wird.

                1 Reply Last reply Reply Quote 0
                • Thomas Braun
                  Thomas Braun Most Active @mickym last edited by Thomas Braun

                  @mickym sagte in source does not exist for "read" function:

                  Was ist den schlimm dieses Objekt zu posten,

                  Nix.

                  {"home_info":{"home_name":"Home","home_img":"","charging_power":"0.00","power_unit":"W"},"solar_list":[],"pps_info":{"pps_list":[],"total_charging_power":"0.00","power_unit":"W","total_battery_power":"0.00","updated_time":"","pps_status":0},"statistics":[{"type":"1","total":"289.00","unit":"kwh"},{"type":"2","total":"288.13","unit":"kg"},{"type":"3","total":"115.60","unit":"€"}],"topology_type":"1","solarbank_info":{"solarbank_list":[{"device_pn":"A17C0","device_sn":"AZB6Y60D40400300","device_name":"Solarbank E1600","device_img":"https://public-aiot-fra-prod.s3.dualstack.eu-central-1.amazonaws.com/anker-power/public/product/2024/05/10/iot-admin/FycLLqjHpYf0Bdab/20230719-144818.png","battery_power":"71","bind_site_status":"","charging_power":"61","power_unit":"W","charging_status":"1","status":"1","wireless_type":"1","main_version":"","photovoltaic_power":"61","output_power":"61","create_time":1721841629,"set_load_power":"","sub_package_num":0,"output_cutoff_data":10,"is_display":true,"bat_charge_power":"0"}],"total_charging_power":"0","power_unit":"W","charging_status":"0","total_battery_power":"0.71","updated_time":"2025-02-01 16:17:55","total_photovoltaic_power":"61","total_output_power":"61.00","display_set_power":false,"battery_discharge_power":"0","ac_power":"0","to_home_load":"0","is_display_data":true,"solar_power_1":"0","solar_power_2":"0","solar_power_3":"0","solar_power_4":"0","other_input_power":"0","micro_inverter_power":"61","micro_inverter_power_limit":"0","micro_inverter_low_power_limit":"0","grid_to_battery_power":"0","pei_heating_power":"0","backup_info":{"start_time":0,"end_time":0,"full_time":0}},"retain_load":"150W","scene_mode":0,"home_load_power":"0","updated_time":"01-01-0001 00:00:00","power_site_type":2,"site_id":"a26d801a-afc6-45c0-bb93-ab80ab3bcc29","powerpanel_list":[],"grid_info":null,"is_downgrade":false,"error_code":0,"smart_plug_info":null,"feature_switch":null,"other_loads_power":"0","priority_discharge_switch":0,"display_priority_discharge_tips":0,"priority_discharge_upgrade_devices":"","style_id":0,"is_show_priority_discharge":1}
                  

                  "total_battery_power":"0.71" dürfte die Ursache sein.

                  mickym paul53 2 Replies Last reply Reply Quote 0
                  • mickym
                    mickym Most Active @Thomas Braun last edited by

                    Um welchen Wert handelt es sich - ich hab das mal schön formatiert:

                    {
                      "home_info": {
                        "home_name": "Home",
                        "home_img": "",
                        "charging_power": "0.00",
                        "power_unit": "W"
                      },
                      "solar_list": [],
                      "pps_info": {
                        "pps_list": [],
                        "total_charging_power": "0.00",
                        "power_unit": "W",
                        "total_battery_power": "0.00",
                        "updated_time": "",
                        "pps_status": 0
                      },
                      "statistics": [
                        {
                          "type": "1",
                          "total": "289.00",
                          "unit": "kwh"
                        },
                        {
                          "type": "2",
                          "total": "288.13",
                          "unit": "kg"
                        },
                        {
                          "type": "3",
                          "total": "115.60",
                          "unit": "€"
                        }
                      ],
                      "topology_type": "1",
                      "solarbank_info": {
                        "solarbank_list": [
                          {
                            "device_pn": "A17C0",
                            "device_sn": "AZV6Y60D30400300",
                            "device_name": "Solarbank E1600",
                            "device_img": "https://public-aiot-fra-prod.s3.dualstack.eu-central-1.amazonaws.com/anker-power/public/product/2024/05/10/iot-admin/FycLLqjHpYf0Bdab/20230719-144818.png",
                            "battery_power": "71",
                            "bind_site_status": "",
                            "charging_power": "61",
                            "power_unit": "W",
                            "charging_status": "1",
                            "status": "1",
                            "wireless_type": "1",
                            "main_version": "",
                            "photovoltaic_power": "61",
                            "output_power": "61",
                            "create_time": 1721841629,
                            "set_load_power": "",
                            "sub_package_num": 0,
                            "output_cutoff_data": 10,
                            "is_display": true,
                            "bat_charge_power": "0"
                          }
                        ],
                        "total_charging_power": "0",
                        "power_unit": "W",
                        "charging_status": "0",
                        "total_battery_power": "0.71",
                        "updated_time": "2025-02-01 16:17:55",
                        "total_photovoltaic_power": "61",
                        "total_output_power": "61.00",
                        "display_set_power": false,
                        "battery_discharge_power": "0",
                        "ac_power": "0",
                        "to_home_load": "0",
                        "is_display_data": true,
                        "solar_power_1": "0",
                        "solar_power_2": "0",
                        "solar_power_3": "0",
                        "solar_power_4": "0",
                        "other_input_power": "0",
                        "micro_inverter_power": "61",
                        "micro_inverter_power_limit": "0",
                        "micro_inverter_low_power_limit": "0",
                        "grid_to_battery_power": "0",
                        "pei_heating_power": "0",
                        "backup_info": {
                          "start_time": 0,
                          "end_time": 0,
                          "full_time": 0
                        }
                      },
                      "retain_load": "150W",
                      "scene_mode": 0,
                      "home_load_power": "0",
                      "updated_time": "01-01-0001 00:00:00",
                      "power_site_type": 2,
                      "site_id": "a26d801a-afc6-45c0-bb93-cb80eb3bcc29",
                      "powerpanel_list": [],
                      "grid_info": null,
                      "is_downgrade": false,
                      "error_code": 0,
                      "smart_plug_info": null,
                      "feature_switch": null,
                      "other_loads_power": "0",
                      "priority_discharge_switch": 0,
                      "display_priority_discharge_tips": 0,
                      "priority_discharge_upgrade_devices": "",
                      "style_id": 0,
                      "is_show_priority_discharge": 1
                    }
                    

                    Es scheint mir das zu sein - und da sind alle Werte Strings

                    f9933a98-40f9-4b71-9dfe-8feee08661b9-image.png

                    einen Augenblick bitte.

                    1 Reply Last reply Reply Quote 0
                    • mickym
                      mickym Most Active last edited by mickym

                      So dann probiere mal in der Konvertierungsfunktion für den Alias folgendes:

                      Number(JSON.parse(val).solarbank_info.total_battery_power) *100
                      
                      1 Reply Last reply Reply Quote 0
                      • paul53
                        paul53 @Thomas Braun last edited by

                        @thomas-braun sagte: "total_battery_power":"0.71" dürfte die Ursache sein.

                        Das ist nicht die Ursache, denn es findet bei Multiplikation eine implizite Wandlung statt:

                        JS_Multiplikation_String.JPG

                        mickym 1 Reply Last reply Reply Quote 0
                        • mickym
                          mickym Most Active @paul53 last edited by

                          @paul53 sagte in source does not exist for "read" function:

                          @thomas-braun sagte: "total_battery_power":"0.71" dürfte die Ursache sein.

                          Das ist nicht die Ursache, denn es findet bei Multiplikation eine implizite Wandlung statt:

                          JS_Multiplikation_String.JPG

                          Das mag zwar richtig sein, aber der Typ wird ja über das Skript festgelegt - zumindest ist es die Ursache, dass immer wieder auf String umgeschaltet wird und das erzeugt ja die Fehlermeldung. Die Konvertierung spielt dabei ja noch keine Rolle.

                          Thomas Braun 1 Reply Last reply Reply Quote 0
                          • Thomas Braun
                            Thomas Braun Most Active @mickym last edited by

                            Das wird eher mehr als weniger...

                            2025-02-01 16:36:56.126  - error: history.0 (857) source in "alias.0.0_userdata.0.solix.solarbank_info.total_battery_power" does not exist for "read" function: "Number(JSON.parse(val).solarbank_info.total_battery_power) *100 "
                            2025-02-01 16:36:56.129  - error: javascript.0 (888) source in "alias.0.0_userdata.0.solix.solarbank_info.total_battery_power" does not exist for "read" function: "Number(JSON.parse(val).solarbank_info.total_battery_power) *100 "
                            2025-02-01 16:36:56.126  - error: admin.0 (846) Invalid read function for "alias.0.0_userdata.0.solix.solarbank_info.total_battery_power": "Number(JSON.parse(val).solarbank_info.total_battery_power) *100 " => Cannot read properties of undefined (reading 'total_battery_power')
                            2025-02-01 16:36:56.128  - error: awtrix-light.0 (1329) Invalid read function for "alias.0.0_userdata.0.solix.solarbank_info.total_battery_power": "Number(JSON.parse(val).solarbank_info.total_battery_power) *100 " => Cannot read properties of undefined (reading 'total_battery_power')
                            
                            
                            mickym 1 Reply Last reply Reply Quote 0
                            • mickym
                              mickym Most Active @Thomas Braun last edited by mickym

                              @thomas-braun so mit der internen Konvertierung klappt es

                              536c7e09-7946-4cde-a141-d4da907af8e6-image.png

                              JSON.parse(val).solarbank_info.total_battery_power *100
                              

                              gibt das in die Lesefunktion des Alias ein

                              2a2628c1-d68a-461a-ad94-cf5bd4d55ff3-image.png

                              Ich hab Dein ganzes Objekt in einen Datenpunkt geschrieben und dann im Alias extrahiert:

                              24230fa2-0da1-4c5a-96c4-a2bdcaf639fb-image.png

                              Thomas Braun 1 Reply Last reply Reply Quote 0
                              • Thomas Braun
                                Thomas Braun Most Active @mickym last edited by

                                @mickym sagte in source does not exist for "read" function:

                                Lesefunktion des Alias ein

                                Wo finde ich die denn?

                                mickym Homoran 2 Replies Last reply Reply Quote 0
                                • mickym
                                  mickym Most Active @Thomas Braun last edited by mickym

                                  @thomas-braun sagte in source does not exist for "read" function:

                                  @mickym sagte in source does not exist for "read" function:

                                  Lesefunktion des Alias ein

                                  Wo finde ich die denn?

                                  Na unter Objekte alias.0 solltest Du doch Deinen Alias finden, deswegen brauchst auch den Adapter nicht.

                                  und der hat einen weiteren Tab:

                                  1808100c-9e55-4f2e-ad19-c2df573e4706-image.png

                                  Du kannst auch versuchen - die ganze Funktion in Deinen Adapter einzutragen - aber ich bevorzuge halt direkt im Alias Datenpunkt. Du musst halt den Haken Konvertierungsfunktion benutzen anhaken.

                                  Thomas Braun 1 Reply Last reply Reply Quote 1
                                  • Thomas Braun
                                    Thomas Braun Most Active @mickym last edited by

                                    @mickym

                                    Funktioniert nicht. Wenn ich das im Alias als Konvertierung eintrage komm (NULL) dabei heraus.

                                    mickym 1 Reply Last reply Reply Quote 0
                                    • mickym
                                      mickym Most Active @Thomas Braun last edited by mickym

                                      Dann musst Du Schritt für Schritt vorgehen, hast Du denn auch den Alias auf Dein Objekt und nicht auf Deinen 0_userdata.0 datenpunkt zeigen lassen?

                                      Mach halt mal einen Screenshot von dem Aliastab

                                      Thomas Braun 1 Reply Last reply Reply Quote 0
                                      • Thomas Braun
                                        Thomas Braun Most Active @mickym last edited by Thomas Braun

                                        @mickym sagte in source does not exist for "read" function:

                                        Dann musst Du Schritt für Schritt vorgehen, hast Du denn auch den Alias auf Dein Objekt und nicht auf Deinen 0_userdata.0 datenpunkt zeigen lassen?

                                        Ich weiß es nicht. Das geht mir auch gerade so auf die Nerven, das bleibt jetzt so. Ist es halt falsch im Diagramm.

                                        mickym 1 Reply Last reply Reply Quote 0
                                        • mickym
                                          mickym Most Active @Thomas Braun last edited by

                                          @thomas-braun

                                          da muss Quelle rein: mqtt.0.solix.site.Stromstausee.scenInfo

                                          f76d3763-d0fd-411f-af61-6fd7c2011b28-image.png

                                          Also oben:

                                          mqtt.0.solix.site.Stromstausee.scenInfo
                                          

                                          und unten in der Konvertierung:

                                          JSON.parse(val).solarbank_info.total_battery_power *100
                                          
                                          Thomas Braun 1 Reply Last reply Reply Quote 0
                                          • Thomas Braun
                                            Thomas Braun Most Active @mickym last edited by

                                            @mickym sagte in source does not exist for "read" function:

                                            Danke, das funktioniert nun.
                                            Macht das Konstrukt natürlich insgesamt noch unübersichtlicher. Muss das vielleicht mal komplett überarbeiten.

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            970
                                            Online

                                            31.7k
                                            Users

                                            79.7k
                                            Topics

                                            1.3m
                                            Posts

                                            4
                                            52
                                            1086
                                            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