Skip to content

JavaScript

Hilfe für Skripterstellung mit JavaScript

2.5k Topics 48.9k Posts

NEWS

  • [Vorlage] HP Drucker Füllstände (Javascript).

    52
    2
    2 Votes
    52 Posts
    6k Views
    J
    @jwedenig War ein Browser Problem, funktioniert!! DankeDir
  • Windows 10 in den Ruhezustand

    7
    0 Votes
    7 Posts
    706 Views
    blue231181B
    @djmarc75 und @Gaspode Danke für eure Antworten. GetAdmin habe ich bereits seit ein paar Wochen im Einsatz, leider muss ich hier alle paar Tage den Adapter neu starten da die Verbindung abbricht. Ich versuche es damit weiter evtl mit einem Neustart des Adapters 1x am Tag Vielen Dank
  • ChatGPT für JavaScript (text in mp3, Ausgabe auf Alexa)

    1
    0 Votes
    1 Posts
    343 Views
    No one has replied
  • Aufruf exec aus JavaScript und Übergabe Parameter

    javascript
    4
    0 Votes
    4 Posts
    389 Views
    mickymM
    @mitch Ich habs Dir doch unten gezeigt - wenn der komplette String/Parameter des exec Befehls in doppelten Anführungszeichen steht, dann müssen ALLE doppelten Anführungszeichen innerhalb des Übergabeparameters mit Backslash maskiert werden.
  • Datenpunkt aus xml

    39
    0 Votes
    39 Posts
    1k Views
    paul53P
    @australien sagte: Not Found - GET https://registry.npmjs.org/frequest-promise-native Wozu dient das NPM-Modul. Du benötigst es? Folgende Warnungen sollten bereinigt werden: getState "mqtt.1.SmartHome.SmartMeter.tele.SENSOR" not found (3) You are assigning a string to the state "0_userdata.0.NSPanel.1.Berry_Driver.currentVersion" which expects a number State "0_userdata.0.SolarFrontier.DC_Current" not found
  • javascript fehlermeldung

    16
    0 Votes
    16 Posts
    809 Views
    GlasfaserG
    @oliverio sagte in javascript fehlermeldung: Hab den TE also mit dir verwechselt Alles gut :)
  • async / await - Verständnisfrage

    5
    0 Votes
    5 Posts
    226 Views
    liv-in-skyL
    @bahnuhr wollte mal ein wenig spielen - habe das in chatgpt eingegeben - kannst es ja mal testen [image: 1683348820511-image-083.png] Spoiler async function input_lautstaerke() { return new Promise((resolve, reject) => { stand_alt_Input = getState('musiccast.0.' + MC_ID + '.main.input').val; if (logging) log('Input_Lautstärke setzen: stand_alt_Input = ' + stand_alt_Input); // prüfen input if (stand_alt_Input != "server") setState('musiccast.0.' + MC_ID + '.main.input', 'server'); // Lautstärke stand_alt_Lautstaerke = getState('musiccast.0.' + MC_ID + '.main.volume').val; if (logging) log('Input_Lautstärke setzen: stand_alt_Lautstaerke = ' + stand_alt_Lautstaerke); setState('musiccast.0.' + MC_ID + '.main.volume', Ansage_Lautstaerke); if (logging) log('Input_Lautstärke setzen: Lautstärke gesetzt auf = ' + Ansage_Lautstaerke); resolve(); }); } man kann da auch gut lernen und ausprobieren indem man rücksprache hält - muss natürlich immer getestet werden, da noch in der entwicklung beispiel: frage: schreibe eine javascript function die hintereiander 3 andere funktionen mit await aufruft. die 3 anderen functionen sollen mit axios.get je einen wert von einer webseite holen - die drei funktionen sollen jeweils als eigenständige function definiert sein antwort: Spoiler async function getData() { try { const value1 = await getValue1(); const value2 = await getValue2(); const value3 = await getValue3(); return [value1, value2, value3]; } catch (error) { console.error(error); return null; } } async function getValue1() { try { const response = await axios.get('https://example.com/value1'); const value = response.data * 10 + 5; const result = value > 10; return result; } catch (error) { console.error(error); return null; } } async function getValue2() { try { const response = await axios.get('https://example.com/value2'); const result = response.data > 20; return result; } catch (error) { console.error(error); return null; } } async function getValue3() { try { const response = await axios.get('https://example.com/value3'); const result = response.data.toUpperCase(); return result; } catch (error) { console.error(error); return null; } } vilelleicht interessieren dich solche spielereien - ansonsten einfach überlesen :-)
  • JavaScript zum Auslesen der Tibber API?

    51
    0 Votes
    51 Posts
    8k Views
    K
    Ich habe einen Tibber-Account und einen Deye Wechselrichter. Tibber bietet für diesen WR leider kein Power-Up an. Kann man über die API die WR-Live-Daten zu Tibber senden?
  • Einbinden von Bibliotheken

    3
    0 Votes
    3 Posts
    366 Views
    D
    @mcu Ah! Danke. Das war's wohl. Aber ich habe es inzwischen hinbekommen (mit Hilfe dieses Threads über Alexa mit ChatGPT zu reden. Wahnsinn! Endlich bekommt man gescheite Antworten! Gruss Ralf
  • full zigbee2tasmota integration

    3
    0 Votes
    3 Posts
    773 Views
    R
    Ok, I finally had time to find a solution. Thanks to chatGPT :-) The zigbee2tasmota device is connected to a "regular" mqtt client in iobroker (not the sonoff adapter). When a zigbee message arrives it gets forwarded via mqtt to my iobroker as a json string. My script parses that json and creates separate states for each of the key:value pairs in the json. For sending commands I automatically add an additional state "PowerSet" to devices that have a "Power" state. When I update the PowerSet state, a script creates a json string and writes it into the "mqtt.0.cmnd.ZigbeeGateway.ZbSend" state (see https://tasmota.github.io/docs/Zigbee/#sending-device-commands) The advantage of this approach is that I have nothing to do on the iobroker side when I add new zigbee devices, they are handled automatically. That's it :-) Seems to work well so far. Here's the script in case anyone has a similar problem with zigbee2tasmota: // ############## user config // where the mqtt messages arrive const zigbee2tasmotaSensorObjectId = 'mqtt.0.tele.ZigbeeGateway.SENSOR'; // where the states of the zigbee devices should appear const zbBaseFolder = '0_userdata.0.zigbee2tasmota'; // ZbSend state, see https://tasmota.github.io/docs/Zigbee/#sending-device-commands const zbsendObjId = 'mqtt.0.cmnd.ZigbeeGateway.ZbSend'; // ############## end user config const regexPowerSetStr = `${zbBaseFolder}\\..*PowerSet$`; const regexPowerSet = new RegExp(regexPowerSetStr); // receive on(zigbee2tasmotaSensorObjectId, (obj) => { const jsonString = obj.state.val; const jsonData = JSON.parse(jsonString); // log(`Received JSON string: ${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; // custom handling of special data types if (key.toLowerCase() == 'time') { value = new Date(obj); log("found time") } // Check if the state already exists. If it does, just update the value. // If it does not exist (-> new zigbee device), 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}`); // create additional state to set a new value that will be sent to the zigbee device. // If I use the normal "Power" state, I am afraid it will trigger the zbSend command // everytime it gets updated from the zigbee device itself. if (stateName.endsWith("Power")) { let powerSetStateName = stateName + "Set" createState(powerSetStateName, !!value, { name: key + "Set", type: "boolean", role: "value", read: true, write: true }); log(`Created state ${powerSetStateName}`); } // potentially add more custom handling for dimmer values, etc } else { setState(stateName, value); } // log(`set state ${parent}.${key} with value ${value}`); } } } createObjectsRecursively(zbBaseFolder, jsonData); }); // send power on/off on(regexPowerSet, (obj) => { const objId = obj.id; // probably regex is not needed and we can just take .Device or .Name // Define a regular expression to match the substring between "ZbReceived" and "PowerSet" const regex = /ZbReceived\.(.*?)\.PowerSet/; // Use the regular expression to extract the substring const match = objId.match(regex); if (match) { const zbname = match[1]; let newValue = obj.state.val; let zbsendstring = "\{\"Device\": \"" + zbname + "\"\,\"Send\"\:\{\"Power\"\: "+newValue+"\}}" log("zbsend: " + zbsendstring) setState(zbsendObjId, zbsendstring) } else { log(`The substring between "ZbReceived" and "PowerSet" not found in ${objId}`); } }); PS: sending zigbee commands is only supported for power on/off. I don't have any zigbee devices that have dimmer or hue values or anything else. I guess the script can be adapted to work with those kind of devices, too.
  • Tasmota Firmware update per Script

    javascript
    4
    0 Votes
    4 Posts
    507 Views
    bahnuhrB
    So, hat sich erledigt. Habe es mit einem privaten ota-Server, wie beschrieben auf der tasmota Seite, gelöst.
  • Optimierung eines Anwesenheit-Scriptes

    javascript
    4
    0 Votes
    4 Posts
    347 Views
    R
    @michihorn schon mal dran gedacht, die devices als Listen zu definieren und dann über die einzelnen elemente der Liste zu loopen? // nicht so const id_Michi = "tr-064.0.devices.S20-FE-von-Michael" const id_Heike = "tr-064.0.devices.S20-FE-von-Heike" const id_Noel = "tr-064.0.devices.IPhone-Noel" on({ id: id_Michi, change: 'any', val: false }, function (dp) { setState(id_AWMichi, false) if (dp.state.val == true) { setState(id_AWMichi, true) } }); on({ id: id_Heike, change: 'any', val: false }, function (dp) { setState(id_AWStute, false) if (dp.state.val == true) { setState(id_AWStute, true) } }); on({ id: id_Noel, change: 'any', val: false }, function (dp) { setState(id_AWNoel, false) if (dp.state.val == true) { setState(id_AWNoel, true) } }); // sondern so var deviceList = [ { device: "tr-064.0.devices.Michael-Handy", user: "Michael", type: "tr-064" }, { device: "tr-064.0.devices.Heike-Handy", user: "Heike", type: "tr-064" }, { device: "tr-064.0.devices.IPhone-Noel", user: "Noel", type: "tr-064" } ]; for (var i = 0; i < deviceList.length; i++) { if deviceList[i].type == "tr-064" { on({ id: deviceList[i].device, change: "any", val: false }, function (dp) { setState(id_AWNoel, false) if (dp.state.val == true) { setState(id_AWNoel, true) } }); } }; Hat den Vorteil, dass du den Code nicht ändern musst, falls mal ein Handy dazukommt.
  • SetInterval

    7
    0 Votes
    7 Posts
    663 Views
    L
    @paul53 habe den JS Adapter neu installiert. Die verlorenen Datenpunkte neu angelegt. Diese Meldung: javascript.0 2023-04-28 16:11:49.357 error setInterval function() { ist weg EDIT: irgend etwas hat sich beim Backup einspielen noch eingeschlichen: Der Statuus des Adapters stand nicht mehr auf "debug". Jetzt wird auch die Konsole wieder geloggt. Und "setInterval" funktioniert ohnehin wieder.
  • if Problem

    5
    0 Votes
    5 Posts
    347 Views
    CodierknechtC
    @jones1975 Vergleiche werden in JS mit == notiert ... wie in @paul53 's Beispielen schön zu sehen.
  • Helium API per GET abrufen (incl. User-Agent)

    33
    0 Votes
    33 Posts
    5k Views
    T
    Hat jemand zufällig schon eine Lösung für die neue API erarbeitet?
  • 99+ errors in 50msec!

    15
    0 Votes
    15 Posts
    443 Views
    L
    @homoran Keine Ahnung ob das zusammenhängt aber ich kann so ein Phänomen bestätigen. Muss jetzt erst mal selber schauen was passiert ist. Mein Log von gestern ist 800 MB groß und von heute schon über 1GB. Problem nach Update Node 18.15.0 auf 18.16.0 Gruß//Lucky
  • [gelöst]: Wie bringt man den Status in eine IF-Abfrage?

    9
    0 Votes
    9 Posts
    530 Views
    OliverIOO
    @badsnoopy667 sagte in [gelöst]: Wie bringt man den Status in eine IF-Abfrage?: Versuch doch mal: if (Einspeisung <= 100 && getState("daikin.0.control.power") == true) { // some code here } dann sollte chatGPT mal über truthy und falsy was lesen. getState gibt ein Objekt zurück wenn das objekt existiert ist es true also ist der 2.Teil immer wahr https://developer.mozilla.org/en-US/docs/Glossary/Truthy https://developer.mozilla.org/en-US/docs/Glossary/Falsy aber wahrscheinlich weiß chatgpt auch nicht was die funktion zurück
  • Ordnerwechsel (Monat) und Erzeugung eines neuen Datenpunktes

    7
    0 Votes
    7 Posts
    240 Views
    A
    @anka_ibb Alles soweit OK. War nur ein Test, deshalb einmal kWh und QM. Aber mit der Ergänzung von Codierknecht klappt es so wie ich es mir vorstelle wunderbar. Mit Sourceanalytic tauchen bei mir immer Minuswerte am nachfolgenden Tag auf. Kam plötzlich. Arbeite da mit Tasmota geflashten Messsteckdosen. Von heute auf morgen passten die Werte nicht mehr. Am System wurde nichts verändert. Deshalb kein SA. Vielen Dank an Alle für die Unterstützung und Tips.
  • Alias Werte Multiplizieren/ runden

    5
    2
    0 Votes
    5 Posts
    515 Views
    paul53P
    @mading sagte: Wie kann ich den aktuellen Aktienwert mit einer Zahl und mit dem USD zu € Datenpunkt multiplizieren? Nur per Skript. Der Alias kann nur einen Datenpunkt referenzieren (außer getrennte DP für Lesen und Schreiben).
  • JS-MQTT DP eines Bildes (JFIF) in Datei schreiben (jpg)

    javascript
    41
    0 Votes
    41 Posts
    6k Views
    Rob_inR
    @rob_in said in JS-MQTT DP eines Bildes (JFIF) in Datei schreiben (jpg): For months I have been using a an MQTT topic change trigger to send an image (via Telegram) that was fetched via HTTP from http://frigate/api/myCam/latest.jpg?bbox=1 Works well, but... I have just done a lot of work adding new cameras and configuration to Frigate and want to take advantage of it's MQTT image publishing. It seems silly to fetch something via HTTP when an image can be pushed via MQTT is all. Surely there is an easy solution? So why can I not find it? :( Having messed around with this a bit have discovered I was doing it correctly in the first place. Turns out that images published through MQTT are not what I want anyhow so best ignored. Doh! See: https://github.com/blakeblackshear/frigate/issues/6241

388

Online

32.6k

Users

82.2k

Topics

1.3m

Posts