Skip to content

JavaScript

Help for using JavaScript

24 Themen 152 Beiträge

NEWS

  • Modbus Register of Wallbox

    2
    0 Stimmen
    2 Beiträge
    151 Aufrufe
    mcm1957M
    @maxnomo Do you want to migrate to ioBroker? Do you have problems with the iobroker modbus adapter? This forum is NOT related to home assistent. So if you question relates to an home asisstent problme, please ask that some ha forum.
  • Dieses Thema wurde gelöscht!

    0
    0 Stimmen
    0 Beiträge
    22 Aufrufe
    Niemand hat geantwortet
  • Script editor not working (again^2)

    4
    0 Stimmen
    4 Beiträge
    454 Aufrufe
    mcm1957M
    @mguc If no matching issue exists, please create one. @bluefox FYI
  • [Question] restart causes empty values are written

    javascript
    14
    0 Stimmen
    14 Beiträge
    1k Aufrufe
    E
    @asgothian Okay, I just found the history adapter writes null at start and stop. I deactivated that. I still had all those null entries though, which messed up with certain plotting routines. I also wrote a script which goes through all objects (incl. 3 level of nesting according to the doc) and removes items in a certain timeframe of 1 minute. Here's the code: // 21-10-2024. Works perfectly!! // To see log entries, set log level of javascript instance to silly var startTimestamp = new Date('2023-12-14T09:40:00.000'); var endTimestamp = new Date(startTimestamp.getTime() + 1*60000); //log(startTimestamp.toISOString()) //log(endTimestamp.toISOString()) $('0_userdata.0.Haus.*').each(function(id) { //log(id.toString()) //var currentElement = $(this); //console.log(currentElement); sendTo('history.0', 'deleteRange', [{ id: id.toString(), start: startTimestamp, end: endTimestamp }]); });
  • JavaScript adapter wont detect modbus-serial

    18
    1
    0 Stimmen
    18 Beiträge
    2k Aufrufe
    Jack 3J
    @fastfoot 2024-07-09 09:07:46.559 - error: modbus.0 (604) Socket Error 2024-07-09 09:07:46.564 - error: modbus.0 (604) Client in error state. 2024-07-09 09:07:46.564 - warn: modbus.0 (604) On error: {"errno":-4039,"code":"ETIMEDOUT","syscall":"connect","address":"131.246.75.233","port":5020} 2024-07-09 09:07:46.592 - error: modbus.1 (12848) Socket Error 2024-07-09 09:07:46.601 - error: modbus.1 (12848) Client in error state. 2024-07-09 09:07:46.601 - warn: modbus.1 (12848) On error: {"errno":-4078,"code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":502} 2024-07-09 09:08:47.615 - error: modbus.1 (12848) Socket Error 2024-07-09 09:08:47.615 - error: modbus.1 (12848) Client in error state. 2024-07-09 09:08:47.615 - warn: modbus.1 (12848) On error: {"errno":-4078,"code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":502} 2024-07-09 09:09:08.775 - error: modbus.0 (604) Socket Error 2024-07-09 09:09:08.775 - error: modbus.0 (604) Client in error state. 2024-07-09 09:09:08.775 - warn: modbus.0 (604) On error: {"errno":-4039,"code":"ETIMEDOUT","syscall":"connect","address":"131.246.75.233","port":5020} 2024-07-09 09:09:12.133 - info: admin.0 (5516) ==> Connected system.user.admin from ::1 2024-07-09 09:09:12.221 - error: host.PCRT49 cannot call visUtils: Not exists 2024-07-09 09:09:18.930 - info: admin.0 (5516) ==> Connected system.user.admin from ::1 2024-07-09 09:09:21.197 - info: javascript.0 (12652) Start JavaScript script.js.Test (Javascript/js) 2024-07-09 09:09:21.206 - error: javascript.0 (12652) script.js.Test compile failed: at script.js.Test:4 is that what you mean?
  • problem during boot with schedule command in the script

    5
    0 Stimmen
    5 Beiträge
    607 Aufrufe
    HomoranH
    @hschief sagte in problem during boot with schedule command in the script: .... more english speaker the German speaker :rolling_on_the_floor_laughing: [image: 1713351548138-screenshot_20240417-125840_firefox.jpg] das sind die Installationen und im forum istcdie Luft noch viel dünner
  • Script editor not working (again)

    5
    1
    0 Stimmen
    5 Beiträge
    642 Aufrufe
    M
    @mcm57 This bug was fixed.
  • PoC: JSON State Mapper for the ioBroker Javascript Engine

    javascript
    1
    1
    0 Stimmen
    1 Beiträge
    405 Aufrufe
    Niemand hat geantwortet
  • Get Connected User name from script

    1
    0 Stimmen
    1 Beiträge
    257 Aufrufe
    Niemand hat geantwortet
  • [Unsolved but satisfied] For loop inside for loop

    16
    0 Stimmen
    16 Beiträge
    1k Aufrufe
    M
    So I decided to drop the loop inside loop as the arrays were not synchronising. The time to troubleshoot would be more than the loop would save me time from programming the full code bit by bit. Just for future reference if someone wants to do the same: The "First_Run" bit is to fill the PLC DB so it doesn't overwrite the actual settings with an empty DB. async function SyncSetpoint() { var Heater = getObject("enum.functions.HeatingUp.setpoint").common.members; var PLC = getObject("enum.functions.PlcHeatingUp.setpoint").common.members; for(let i = 0; i < Heater.length; i++) { on(PLC[i], function (dp) { if(dp.state.c != scriptName) setState(Heater[i], dp.state.val); return; }); on(Heater[i], function (dp) { if(dp.state.c != scriptName) setState(PLC[i], dp.state.val); }); await wait(1000); } } async function SyncProfile() { var Heater = getObject("enum.functions.HeatingUp.profile").common.members; var PLC = getObject("enum.functions.PlcHeatingUp.profile").common.members; for(let i = 0; i < Heater.length; i++) { on(PLC[i], function (dp) { if(dp.state.c != scriptName) setState(Heater[i], dp.state.val); return; }); on(Heater[i], function (dp) { if(dp.state.c != scriptName) setState(PLC[i], dp.state.val); }); await wait(1000); } } async function SyncBoost() { var Heater = getObject("enum.functions.HeatingUp.boost").common.members; var PLC = getObject("enum.functions.PlcHeatingUp.boost").common.members; for(let i = 0; i < Heater.length; i++) { on(PLC[i], function (dp) { if(dp.state.c != scriptName) setState(Heater[i], dp.state.val); return; }); on(Heater[i], function (dp) { if(dp.state.c != scriptName) setState(PLC[i], dp.state.val); }); await wait(1000); } } async function SyncBoostTime() { var Heater = getObject("enum.functions.HeatingUp.boostTime").common.members; var PLC = getObject("enum.functions.PlcHeatingUp.boostTime").common.members; for(let i = 0; i < Heater.length; i++) { on(PLC[i], function (dp) { if(dp.state.c != scriptName) setState(Heater[i], dp.state.val); return; }); on(Heater[i], function (dp) { if(dp.state.c != scriptName) setState(PLC[i], dp.state.val); }); await wait(1000); } } function SyncActualTemp() { var Heater = getObject("enum.functions.HeatingUp.actual").common.members; var PLC = getObject("enum.functions.PlcHeatingUp.actual").common.members; for(let i = 0; i < Heater.length; i++) { on(Heater[i], function (dp) { if(dp.state.c != scriptName) setState(PLC[i], dp.state.val); }); } } function SyncActualHum() { var Heater = getObject("enum.functions.HeatingUp.hum").common.members; var PLC = getObject("enum.functions.PlcHeatingUp.hum").common.members; for(let i = 0; i < Heater.length; i++) { on(Heater[i], function (dp) { if(dp.state.c != scriptName) setState(PLC[i], dp.state.val); }); } } function SyncWinStat() { var connStatHeater = getObject("enum.functions.HeatingUp.connStatWin").common.members; var connStatPLC = getObject("enum.functions.PlcHeatingUp.connStatWin").common.members; var winStatHeater = getObject("enum.functions.HeatingUp.winStat").common.members; var winStatPLC = getObject("enum.functions.PlcHeatingUp.winStat").common.members; var batStatHeater = getObject("enum.functions.HeatingUp.batStatWin").common.members; var batStatPLC = getObject("enum.functions.PlcHeatingUp.batStatWin").common.members; for(let i = 0; i < connStatPLC.length; i++) { on(connStatHeater[i], function (dp) { if(dp.state.c != scriptName) setState(connStatPLC[i], dp.state.val); }); if (getState(connStatHeater[i]).val != true) { on(winStatHeater[i], function (dp) { if(dp.state.c != scriptName) setState(winStatPLC[i], dp.state.val); }); on(batStatHeater[i], function (dp) { if(dp.state.c != scriptName) setState(batStatPLC[i], dp.state.val); }); } } } function SyncThermStat() { var connStatHeater = getObject("enum.functions.HeatingUp.connStatTherm").common.members; var connStatPLC = getObject("enum.functions.PlcHeatingUp.connStatTherm").common.members; var batStatHeater = getObject("enum.functions.HeatingUp.batStatTherm").common.members; var batStatPLC = getObject("enum.functions.PlcHeatingUp.batStatTherm").common.members; for(let i = 0; i < connStatPLC.length; i++) { on(connStatHeater[i], function (dp) { if(dp.state.c != scriptName) setState(connStatPLC[i], dp.state.val); }); if (getState(connStatHeater[i]).val != true) { on(batStatHeater[i], function (dp) { if(dp.state.c != scriptName) setState(batStatPLC[i], dp.state.val); }); } } } function SyncRadStat() { var connStatHeater = getObject("enum.functions.HeatingUp.connStatRad").common.members; var connStatPLC = getObject("enum.functions.PlcHeatingUp.connStatRad").common.members; var batStatHeater = getObject("enum.functions.HeatingUp.batStatRad").common.members; var batStatPLC = getObject("enum.functions.PlcHeatingUp.batStatRad").common.members; for(let i = 0; i < connStatPLC.length; i++) { on(connStatHeater[i], function (dp) { if(dp.state.c != scriptName) setState(connStatPLC[i], dp.state.val); }); if (getState(connStatHeater[i]).val != true) { on(batStatHeater[i], function (dp) { if(dp.state.c != scriptName) setState(batStatPLC[i], dp.state.val); }); } } } //function SyncOnStart() { on({id: "s7.2.DBs.DB5.First_Run"/*First_Run*/, change: "ne"}, async function (obj) { var SPHeater = getObject("enum.functions.HeatingUp.setpoint").common.members; var SPPLC = getObject("enum.functions.PlcHeatingUp.setpoint").common.members; var TempHeater = getObject("enum.functions.HeatingUp.actual").common.members; var TempPLC = getObject("enum.functions.PlcHeatingUp.actual").common.members; var HumHeater = getObject("enum.functions.HeatingUp.hum").common.members; var HumPLC = getObject("enum.functions.PlcHeatingUp.hum").common.members; var ProfileHeater = getObject("enum.functions.HeatingUp.profile").common.members; var ProfilePLC = getObject("enum.functions.PlcHeatingUp.profile").common.members; var BoostHeater = getObject("enum.functions.HeatingUp.boost").common.members; var BoostPLC = getObject("enum.functions.PlcHeatingUp.boost").common.members; var BoostTimeHeater = getObject("enum.functions.HeatingUp.boostTime").common.members; var BoostTimePLC = getObject("enum.functions.PlcHeatingUp.boostTime").common.members; var WinStatHeater = getObject("enum.functions.HeatingUp.winStat").common.members; var WinStatPLC = getObject("enum.functions.PlcHeatingUp.winStat").common.members; var batStatRadHeater = getObject("enum.functions.HeatingUp.batStatRad").common.members; var batStatRadPLC = getObject("enum.functions.PlcHeatingUp.batStatRad").common.members; var connStatRadHeater = getObject("enum.functions.HeatingUp.connStatRad").common.members; var connStatRadPLC = getObject("enum.functions.PlcHeatingUp.connStatRad").common.members; var batStatThermHeater = getObject("enum.functions.HeatingUp.batStatTherm").common.members; var batStatThermPLC = getObject("enum.functions.PlcHeatingUp.batStatTherm").common.members; var connStatThermHeater = getObject("enum.functions.HeatingUp.connStatTherm").common.members; var connStatThermPLC = getObject("enum.functions.PlcHeatingUp.connStatTherm").common.members; let value = obj.state.val; let oldValue = obj.oldState.val; if (getState("s7.2.DBs.DB5.First_Run").val == true) { for(let i = 0; i < SPHeater.length; i++) { setStateDelayed(SPPLC[i], getState(SPHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false); setStateDelayed(TempPLC[i], getState(TempHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false); setStateDelayed(HumPLC[i], getState(HumHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false); setStateDelayed(ProfilePLC[i], getState(ProfileHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false); setStateDelayed(BoostPLC[i], getState(BoostHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false); setStateDelayed(BoostTimePLC[i], getState(BoostTimeHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false); }; for(let i = 0; i < WinStatHeater.length; i++) { setStateDelayed(WinStatPLC[i], getState(WinStatHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false); }; for(let i = 0; i < batStatRadHeater.length; i++) { setStateDelayed(batStatRadPLC[i], getState(batStatRadHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false); setStateDelayed(connStatRadPLC[i], getState(connStatRadHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false); }; for(let i = 0; i < batStatThermHeater.length; i++) { setStateDelayed(batStatThermPLC[i], getState(batStatThermHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false); setStateDelayed(connStatThermPLC[i], getState(connStatThermHeater[i]).val, false, parseInt(((0) || "").toString(), 10), false); }; await wait(3000); setStateDelayed("s7.2.DBs.DB5.First_Run", false, false, parseInt(((0) || "").toString(), 10), false); } }); SyncSetpoint(); SyncProfile(); SyncBoost(); SyncBoostTime(); SyncActualHum(); SyncWinStat(); SyncThermStat(); SyncRadStat(); So thanks @paul53 but I gave up and took the less beautiful way out :wink:
  • npm package in iobroker js engine nutzen

    3
    0 Stimmen
    3 Beiträge
    642 Aufrufe
    L
    @oliverio said in npm package in iobroker js engine nutzen: b des JavaScript Adapters installiert und kann i Vielen Dank @OliverIO - das hat geholfen :-)
  • setTimeout() keeps running on script stop.

    4
    0 Stimmen
    4 Beiträge
    1k Aufrufe
    paul53P
    @j1s2e3 sagte: The first question is, if timeout should keep running if the sarting script is stopped? Whether it's a bug or a feature. It's a bug in your javascript instance. Restart the instance or ioBroker.
  • [Vorlage] Script: JSON-->Datenpunkte mit sync

    javascript monitoring
    3
    1 Stimmen
    3 Beiträge
    1k Aufrufe
    A
    @oliverio Gute Ideen, das behalte ich mal im Hinterkopf...
  • [gelöst] setState funktioniert nicht bei Device ?

    14
    0 Stimmen
    14 Beiträge
    1k Aufrufe
    Great SUNG
    @paul53 Hach ja... Und ich dachte beim bauen des Scripts, dass es createState und createStateAsync gibt, weil createState das Objekt direkt erzeugt und man damit danach arbeiten kann... Das genau war die Lösung!!! Vielen lieben Dank für den Hint mit dem Callback.
  • Check if an element contains a class in JavaScript?

    3
    0 Stimmen
    3 Beiträge
    790 Aufrufe
    OliverIOO
    @roshan-sharma better is to use jquery https://api.jquery.com/hasclass/ var test = $("#test"); if ($(test).hasClass("class1")) { $(test).html("I have class1"); } if ($(test).hasClass("class2")) { $(test).html("I have class2"); } jquery is in vis already loaded
  • using iobroker.socket-client in a NodeJs project

    6
    0 Stimmen
    6 Beiträge
    924 Aufrufe
    T
    @bluefox The API seems straightforwards enough; a couple of questions though: How do I unsubscribe? - I didn't see a command for that Can I do a "Bulk" subscribe - i.e. ask for a list of states?
  • [Entwicklung] TypeScript: Kleine Fragen, schnelle Antworten

    5
    0 Stimmen
    5 Beiträge
    781 Aufrufe
    AcguaA
    @alcalzone Hi! Vielen Dank für deine Antwort und auch die Beispiele! Sehr hilfreich und beantwortet alle Fragen. Hab jetzt am Anfang schon mega Lust in TS was zu entwickeln statt in plain JS, weil ich damit endlich viel sauberer arbeiten kann usw. und mir einiges an weniger Fehler etc. erwarte. Ich bin in Begriff, einen ersten Adapter zu schreiben, und diesen halt gleich in TS und nicht JS.
  • Zeitstempel entfernen

    20
    0 Stimmen
    20 Beiträge
    2k Aufrufe
    M
    @paul53 said in Zeitstempel entfernen: setState(idSysvar, parseFloat(dp.state.val.split(' ')[1])); Aus dem Hinweis gestern Zeile 9: habe ich geschlossen. das nur der Befehl in Zeike 9 gehört. Das es zweimal gesetzt werden muss habe ich falsch verstanden. Ich senke demütig mein Haupt und bitte um Entschuldigung mp24
  • Performancn-Einbussen bei mehrfachem Submit?

    javascript
    4
    0 Stimmen
    4 Beiträge
    509 Aufrufe
    paul53P
    @homecineplexx sagte: die länge so eines Scripts ist dann eigentlich wirklich ziemlich egal...wird nur unübersichtlicher So ist es.
  • time of the last change of a data point.

    9
    0 Stimmen
    9 Beiträge
    2k Aufrufe
    F
    @paul53 hi Paul Thank you for quick response. it works this is my code thank you for helping: (two different formats for testing) // --- sensor.neulcT = (new Date(msg.payload[i].lc)).toLocaleTimeString(); sensor.neulc = (new Date(msg.payload[i].lc)).toLocaleString(); // ---

384

Online

32.4k

Benutzer

81.5k

Themen

1.3m

Beiträge