Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. caco3000

    NEWS

    • Wir empfehlen: Node.js 22.x

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 4
    • Best 0
    • Groups 1

    caco3000

    @caco3000

    Starter

    0
    Reputation
    3
    Profile views
    4
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    caco3000 Follow
    Starter

    Latest posts made by caco3000

    • RE: Lay-Z-Spa Wifi Control

      AI machts möglich habe mir den Code reparieren lassen.```

      const ID = '0_userdata.0.LazySpa';
      const MQTTINSTANCE = 0;
      const debug = true;
      
      // Definition der zu erstellenden Datenpunkte
      const STATES = [
          {
              _id: 'LCK',
              type: 'state',
              common: { name: 'lock', type: 'boolean', role: 'indicator.lock', read: true, write: false, desc: 'Lazy spa lock' },
              native: {}
          },
          {
              _id: 'PWR',
              type: 'state',
              common: { name: 'power', type: 'boolean', role: 'switch.power', read: true, write: true, desc: 'Lazy spa power' },
              native: {}
          },
          {
              _id: 'UNT',
              type: 'state',
              common: { name: 'unit', type: 'number', role: 'value', read: true, write: true, max: 1, desc: 'Lazy spa unit', states: { 0: 'Farenheit', 1: 'Celsius' } },
              native: {}
          },
          {
              _id: 'AIR',
              type: 'state',
              common: { name: 'bubbles', type: 'boolean', role: 'switch.light', read: true, write: true, desc: 'Lazy spa bubbles state' },
              native: {}
          },
          {
              _id: 'GRN',
              type: 'state',
              common: { name: 'Heating green', type: 'boolean', role: 'indicator', read: true, write: false, desc: 'Reached target temp.' },
              native: {}
          },
          {
              _id: 'RED',
              type: 'state',
              common: { name: 'Heating red', type: 'boolean', role: 'indicator', read: true, write: false, desc: 'Not reached target temp.' },
              native: {}
          },
          {
              _id: 'FLT',
              type: 'state',
              common: { name: 'pump', type: 'boolean', role: 'switch.pump', read: true, write: true, desc: 'Pump state' },
              native: {}
          },
          {
              _id: 'HEATER',
              type: 'state',
              common: { name: 'heater', type: 'boolean', role: 'switch.heater', read: true, write: true, desc: 'Heater state' },
              native: {}
          },
          {
              _id: 'TGT',
              type: 'state',
              common: { name: 'target temp', type: 'number', role: 'level.temperature', min: 20, max: 40, step: 1, read: true, write: true, desc: 'Target temp.' },
              native: {}
          },
          {
              _id: 'TMP',
              type: 'state',
              common: { name: 'temp', type: 'number', role: 'value.temperature', read: true, write: false, unit: '°C', desc: 'Current temp.' },
              native: {}
          },
      ];
      
      /**
       * Sendet Befehle an den Spa via MQTT.
       * @param {object} obj Das Objekt vom "on"-Trigger.
       */
      async function stateChange(obj) {
          const state = obj.id.split('.').pop();
          let value = obj.state.val;
          if (debug) log(`Change detected for '${state}'. Sending command.`);
      
          let cmd, val;
      
          switch (state) {
              case 'UNT': cmd = 1; val = value; break;
              case 'TGT': cmd = 0; val = value; break;
              case 'AIR': cmd = 2; val = value ? 1 : 0; break;
              case 'HEATER': cmd = 3; val = value ? 1 : 0; break;
              case 'FLT': cmd = 4; val = value ? 1 : 0; break;
              default:
                  if (debug) log(`No action defined for state change of: ${state}`, 'warn');
                  return;
          }
      
          const mqttCommand = `{"CMD":${cmd},"VALUE":${val},"XTIME":0,"INTERVAL":0}`;
          await setStateAsync(`mqtt.${MQTTINSTANCE}.layzspa.command`, mqttCommand, false);
          if (debug) log(`Sent command for '${state}': ${mqttCommand}`);
      }
      
      /**
       * Verarbeitet eingehende Status-Updates vom Spa.
       * @param {string} jsonString Der JSON-String von der MQTT-Nachricht.
       */
      async function setLazyStates(jsonString) {
          let states;
          try {
              states = JSON.parse(jsonString);
          } catch (e) {
              log(`Error parsing JSON from MQTT: ${jsonString}. Error: ${e.stack}`, 'error');
              return;
          }
      
          for (const [key, value] of Object.entries(states)) {
              const stateDef = STATES.find(s => s._id === key);
              if (stateDef) {
                  let stateValue = (stateDef.common.type === 'boolean') ? (value === 1) : value;
                  await setStateAsync(`${ID}.${key}`, stateValue, true);
              }
          }
      
          const isHeaterOn = (states.GRN === 1 || states.RED === 1);
          await setStateAsync(`${ID}.HEATER`, isHeaterOn, true);
      }
      
      /**
       * Hauptfunktion zur Initialisierung des Skripts.
       */
      async function main() {
          // 1. Datenpunkte erstellen oder sicherstellen, dass sie existieren
          for (const stateObject of STATES) {
              const id = `${ID}.${stateObject._id}`;
              if (!(await getObjectAsync(id))) {
                  if (debug) log(`Creating state: ${id}`);
                  await createStateAsync(id, stateObject.common);
              }
      
              // 2. Trigger für schreibbare Datenpunkte erstellen
              if (stateObject.common.write) {
                  on({ id: id, change: "any", ack: false }, async (obj) => {
                      try {
                          if (obj.state) {
                              await stateChange(obj);
                          }
                      } catch (e) {
                          log(`Error in stateChange trigger for ${id}: ${e.stack}`, 'error');
                      }
                  });
              }
          }
      
          // 3. Trigger für eingehende MQTT-Nachrichten
          on({ id: `mqtt.${MQTTINSTANCE}.layzspa.message`, change: "ne" }, async (obj) => {
              try {
                  if (obj.state && obj.state.val) {
                      if (debug) log(`Received MQTT message: ${obj.state.val}`);
                      await setLazyStates(obj.state.val);
                  }
              } catch (e) {
                  log(`Error in MQTT message handler: ${e.stack}`, 'error');
              }
          });
      
          log("LazySpa script started and all triggers are active.");
      }
      
      // Skriptausführung starten und alle Fehler abfangen.
      try {
          main();
      } catch (e) {
          log(`A critical error occurred during script initialization: ${e.stack}`, 'error');
      }
      
      posted in Hardware
      caco3000
      caco3000
    • RE: Lay-Z-Spa Wifi Control

      Bei mir kommt jetzt im Script folgender Fehler

      javascript.0	18:55:30.845	error	script.js.Lay_Z_Spa: script.js.Lay_Z_Spa:1
      javascript.0	18:55:30.845	error	at script.js.Lay_Z_Spa:1:1
      

      und in Log von IO Broker kommt folgendes:

      javascript.0
      2025-08-06 18:52:04.102	error	at Script.runInContext (node:vm:149:12)
      
      javascript.0
      2025-08-06 18:52:04.102	error	at script.js.Lay_Z_Spa:1:1
      
      javascript.0
      2025-08-06 18:52:04.102	error	SyntaxError: Identifier 'log' has already been declared
      
      javascript.0
      2025-08-06 18:52:04.102	error	script.js.Lay_Z_Spa: script.js.Lay_Z_Spa:1
      

      Screenshot 2025-08-06 185250.png Screenshot 2025-08-06 185417.png

      Wer kann mir sagen was mt einmal nicht mehr stimmt bis jetzt lief alles

      Mod-Edit
      Code-Tags gesetzt

      posted in Hardware
      caco3000
      caco3000
    • RE: Lay-Z-Spa Wifi Control

      Wie bekomm ich es hin das ich z.b. die TGT setzten kann ?

      Einfach nur den Wert bei 0userdate bei TGT eingetragen wird zwar dieses ({"CMD":0,"VALUE":37,"XTIME":0,"INTERVAL":0}) bei Mqtt ins Command geschrieben. Aber nicht übermittel.

      posted in Hardware
      caco3000
      caco3000
    • RE: Lay-Z-Spa Wifi Control

      Hi,
      Könnt ihr mir sagen was ich tun muss dass der Befehl auch via mqtt wieder zurückgeschickt wird?
      Bei Objekten- 0 Userdata gebe ich bei TGT 37 als Ziel temp. Und lasse den hacken bei bestätigt raus. Dann auf wert setzten.

      Schon wird bei mytt-layzspa-command geschrieben mit :
      {"CMD":0,"VALUE":37,"XTIME":0,"INTERVAL":0}

      Erscheint allerdings in roter Schrift.

      Geh ich jetzt manuell auf command nehme den den Befehl so wie er steht und setzt den hacken bei bestätigt und sende den Wert. Dann geht es , der Lay z Spa übernimmt ihn .

      Was mach ich falsch ?

      posted in Hardware
      caco3000
      caco3000
    Community
    Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
    The ioBroker Community 2014-2023
    logo