Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. [gelöst] Daten der S.USV auslesen - Fehler im Skript

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    [gelöst] Daten der S.USV auslesen - Fehler im Skript

    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      Beowolf last edited by Beowolf

      Ich habe das Skript aus diesem Beitrag eingefügt.

      https://www.forum.iobroker.net/topic/15963/skript-zum-auslesen-der-s-usv

      Leider kann ich nicht in dem Beitrag eine Frage stellen. Es kommt immer wieder die Meldung, "Es scheint als hättest du die Verbindung zu ioBroker Community verloren, bitte warte während wir versuchen sie wieder aufzubauen."

      Deshalb jetzt hier die Frage.

      Es steht in der Log-Fenster von ioBroker immer dieser Fehler:

      2.4.2019, 16:41:46.983	[error]: javascript.0 ReferenceError: v10010 is not defined
          at script.js.common.Ausgabewerte_für_die_SUSV:183:22
          at Array.forEach (<anonymous>:null:null)
          at script.js.common.Ausgabewerte_für_die_SUSV:95:8
          at ChildProcess.exithandler (child_process.js:267:7)
          at emitTwo (events.js:126:13)
          at ChildProcess.emit (events.js:214:7)
          at maybeClose (internal/child_process.js:925:16)
          at Socket.stream.socket.on (internal/child_process.js:346:11)
          at emitOne (events.js:116:13)
          at Socket.emit (events.js:211:7)
      
      2.4.2019, 16:41:46.986	[info ]: javascript.0 Stop script script.js.common.Ausgabewerte_für_die_SUSV
      2.4.2019, 16:41:47.071	[error]: Caught by controller[0]:     at script.js.common.Ausgabewerte_für_die_SUSV:183:22
      2.4.2019, 16:41:47.072	[error]: Caught by controller[0]:     at script.js.common.Ausgabewerte_für_die_SUSV:95:8
      

      Das ist das zugehörige Skript

      // Script to drive the S.USV Pi uninterrupted power supply
      // See http://www.s-usv.de for details.
      // NOTE: This script uses the S.USV demon and client software
      // (available on same website) so you must install it before.
      // Version 1.3, October 2018, Ralf Schaefer
      // –----------- Configuration variables -------------
      var PollTime = 60; // how often will we poll the usv (in sec)
      var susv = '/opt/susvd/susv'; // where is the susv client executable
      var idUSV = 'USV.'; // prefix for object tree
      var logLevel = 0; // set to 1 for some logging messages
      // ------------- Do not modify below this point -------------
      var idModel = idUSV + 'Model';
      var idFirmware = idUSV + 'FirmwareVersion';
      var idSoftware = idUSV + 'SoftwareVersion';
      var idHardware = idUSV + 'HardwareVersion';
      var idMailNotification = idUSV + 'MailNotification';
      var idTimedBoot = idUSV + 'TimedBoot';
      var idBootTime = idUSV + 'BootTime';
      var idTimedShutdown = idUSV + 'TimedShutdown';
      var idShutdownTime = idUSV + 'ShutdownTime';
      var idSUSVOK = idUSV + 'SUSVOK';
      var idMainsOk = idUSV + 'MainsOK';
      var idPoweringSource = idUSV + 'PoweringSource';
      var idChargingCircuit = idUSV + 'ChargingCircuit';
      var idCharging = idUSV + 'Charging';
      var idVoltageIn = idUSV + 'VoltageIn';
      var idVoltageInDeviation = idUSV + 'VoltageInDeviation';
      var idBatteryCapacity = idUSV + 'BatteryCapacity';
      var idBatteryVoltage = idUSV + 'BatteryVoltage';
      var idPowerBattery = idUSV + 'PowerBattery';
      var idVISBatteryLevel = idUSV + 'BatteryLevel';
      var idShutdownTimer = idUSV + 'ShutdownTimer';
      var idAutostart = idUSV + 'Autostart';
      var idSleepTimer = idUSV + 'SleepTimer';
      createState(idModel, 0, { name: 'Model', type: 'string' }); // 'Basic', '???''
      createState(idFirmware, 0, { name: 'Firmware version', type: 'string' }); // '2.61'
      createState(idSoftware, 0, { name: 'Software version', type: 'string' }); // '2.40'
      createState(idHardware, 0, { name: 'Hardware version', type: 'string' }); // '2.1'
      createState(idMailNotification, 0, { name: 'Mail notification', type: 'boolean' });
      createState(idTimedBoot, 0, { name: 'Timed boot', type: 'boolean' }); // 'HH:mm:ss'
      createState(idBootTime, 0, { name: 'Boot time', type: 'string' });
      createState(idTimedShutdown, 0, { name: 'Timed shutdown', type: 'boolean' });
      createState(idShutdownTime, 0, { name: 'Shutdown time', type: 'string' }); // 'HH:mm:ss'
      createState(idSUSVOK, 0, { name: 'Zugriff auf SUSV ok', type: 'boolean' });
      createState(idMainsOk, false, { name: 'Netz vorhanden', type: 'boolean' }); // true if PoweringSource != 'Battery'
      createState(idPoweringSource, '', { name: 'Energiequelle', type: 'string' }); // 'Primary', 'Battery'
      createState(idChargingCircuit, '', { name: 'Batterielader', type: 'string' }); // 'ONLINE', 'OFFLINE'
      createState(idCharging, false, { name: 'Akku wird geladen', type: 'boolean' }); // true if battery is charged
      createState(idVoltageIn, 0, { name: 'Eingangsspannung', type: 'number', min: 0, max: 5.5, unit: 'V' });
      createState(idVoltageInDeviation, 0, { name: 'Abweichung Eingangsspannung', type: 'number', min: -20, max: 20, unit: "%" }); // deviation from 5.00V
      createState(idBatteryCapacity, 0, { name: 'Verbleibende Akkukapazitaet', type: 'number', min: 0, max: 100, unit: "%" });
      createState(idBatteryVoltage, 0, { name: 'Akkuspannung', type: 'number', min: 0, max: 5.5, unit: 'V' });
      createState(idPowerBattery, 0, { name: 'Batteriestrom', type: 'number', min: 0, max: 2000, unit: 'mA' }); // 0 if PoweringSource != 'Battery'
      createState(idVISBatteryLevel, 0, { name: 'Batterielevel (0..4 für VIS)', type: 'number', min: 0, max: 4 }); // can be used in VIS to switch icons
      createState(idShutdownTimer, 0, { name: 'Shutdown timer', type: 'number' }); //
      createState(idAutostart, false, { name: 'Autostart', type: 'boolean' }); // 'enabled' ??
      createState(idSleepTimer, 0, { name: 'Sleep timer', type: 'number' }); //
      // Backup variables - we want to call setState only on value changes
      var vModel = null;
      var vFirmware = null;
      var vSoftware = null;
      var vHardware = null;
      var vMailNotification = null;
      var vTimedBoot = null;
      var vBootTime = null;
      var vTimedShutdown = null;
      var vShutdownTime = null;
      var vMainsOk = null;
      var vPoweringSource = null;
      var vChargingCircuit = null;
      var vCharging = null;
      var vVoltageIn = null;
      var vVoltageInDeviation = null;
      var vBatteryCapacity = null;
      var vBatteryVoltage = null;
      var vPowerBattery = null;
      var vVISBatteryLevel = null;
      var vShutdownTimer = null;
      var vAutostart = null;
      var vSleepTimer = null;
      function GetUSVStatus() {
      var SWVersion = '';
      exec(susv + ' -status', function(err, stdout, stderr) {
      if (err) {
      log(err + ': ' + stdout);
      setState(idSUSVOK, false, true);
      return;
      }
      else
      {
      // Unlike other values we set the state always, to have a recent time stamp
      setState(idSUSVOK, true, true);
      }
      stdout = stdout.split('\n');
      stdout.forEach(function(line) {
      var v;
      if (contains(line, 'Model:'))
      {
      v = snip(line, ' ');
      if (vModel !== v)
      setState(idModel, vModel = v, true);
      }
      else if (contains(line, 'Firmware Version'))
      {
      v = snip(line, ' ');
      if (vFirmware !== v)
      setState(idFirmware, vFirmware = v, true);
      }
      else if (contains(line, 'Software Version'))
      {
      v = snip(line, ' ');
      if (v !== '2.20' && v !== '2.33' && v !== '2.40')
      log('Unexpected software version ' + v + ', possibly not all values are correctly identified.')
      if (vSoftware !== v)
      setState(idSoftware, vSoftware = v, true);
      }
      else if (contains(line, 'Hardware Version'))
      {
      v = snip(line, ' ');
      if (vHardware !== v)
      setState(idHardware, vHardware = v, true);
      }
      else if (contains(line, 'Mail notification'))
      {
      v = snip(line, ' ');
      v = (v == 'Enabled');
      if (vMailNotification !== v)
      setState(idMailNotification, vMailNotification = v, true);
      }
      else if (contains(line, 'Timed Boot'))
      {
      v = snip(line, ' ');
      v = (v == 'Enabled');
      if (vTimedBoot !== v)
      setState(idTimedBoot, vTimedBoot = v, true);
      }
      else if (contains(line, 'Boot time'))
      {
      v = snip(line, ' ');
      if (vBootTime !== v)
      setState(idBootTime, vBootTime = v, true);
      }
      else if (contains(line, 'Timed Shutdown'))
      {
      v = snip(line, ' ');
      v = (v == 'Enabled');
      if (vTimedShutdown !== v)
      setState(idTimedShutdown, vTimedShutdown = v, true);
      }
      else if (contains(line, 'Shutdown time:'))
      {
      v = snip(line, ' ');
      if (vShutdownTime !== v)
      setState(idShutdownTime, vShutdownTime = v, true);
      }
      else if (contains(line, 'Powering Source'))
      {
      v = snip(line, ' ');
      if (logLevel)
      log('PowerSource v=' + v);
      if (vPoweringSource !== v)
      setState(idPoweringSource, vPoweringSource = v, true);
      v = (v != 'Battery');
      if (logLevel)
      log('MainOK v=' + v);
      if (vMainsOk !== v)
      setState(idMainsOk, vMainsOk = v, true);
      }
      else if (contains(line, 'Charging circuit'))
      {
      v = snip(line, ' ');
      if (vChargingCircuit !== v)
      setState(idChargingCircuit, vChargingCircuit = v, true);
      v = (v != 'OFFLINE');
      if (vCharging !== v)
      setState(idCharging, vCharging = v, true);
      }
      else if (contains(line, 'Voltage in'))
      {
      v = parseFloat(snip(line, ' V'));
      if (vVoltageIn !== v)
      setState(idVoltageIn, vVoltageIn = v, true);
      v = Math.round((v-5)/v10010)/10;
      if (vVoltageInDeviation !== v)
      setState(idVoltageInDeviation, vVoltageInDeviation = v, true);
      }
      else if (contains(line, 'Battery capacity'))
      {
      v = parseInt(snip(line, '%'));
      if (vBatteryCapacity !== v)
      setState(idBatteryCapacity, vBatteryCapacity = v, true);
      v = Math.round(parseInt(v) / 25); // 0..100% --> 0..4
      if (vVISBatteryLevel !== v)
      setState(idVISBatteryLevel, vVISBatteryLevel = v, true);
      }
      else if (contains(line, 'Battery voltage'))
      {
      v = parseFloat(snip(line, 'V'));
      if (vBatteryVoltage !== v)
      setState(idBatteryVoltage, vBatteryVoltage = v, true);
      }
      else if (contains(line, 'Power Battery'))
      {
      v = parseFloat(snip(line, ' mA'));
      if (vPowerBattery !== v)
      setState(idPowerBattery, vPowerBattery = v, true);
      }
      else if (contains(line, 'Shutdown timer'))
      {
      v = parseInt(snip(line, ' '));
      if (vShutdownTimer !== v)
      setState(idShutdownTimer, vShutdownTimer = v, true);
      }
      else if (contains(line, 'Autostart'))
      {
      v = snip(line, ' ');
      v = (v == 'enabled');
      if (vAutostart !== v)
      setState(idAutostart, vAutostart = v, true);
      }
      else if (contains(line, 'Sleep timer'))
      {
      v = parseFloat(snip(line, ' '));
      if (vSleepTimer !== v)
      setState(idSleepTimer, vSleepTimer = v, true);
      }
      });
      });
      }
      setInterval(GetUSVStatus, PollTime * 1000);
      // Return true if needle is found in hay, false otherwise
      function contains(hay, needle) {
      return hay.indexOf(needle) > -1;
      }
      // snip out everything between the colon and the specified end tag.
      // Example:
      // snip('* Battery capacity: 69.60% *', '%') => '69.60'
      function snip(line, endtag) {
      var idx = line.indexOf(':');
      if (idx < 1)
      return '';
      line = line.substring(idx + 2);
      idx = line.indexOf(endtag);
      if (idx < 1)
      return '';
      return line.substring(0, idx);
      }
      

      Kann mir dabei jemand helfen?

      Grüße
      Manfred

      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @Beowolf last edited by paul53

        @Beowolf sagte:

        v = Math.round((v-5)/v10010)/10;

        Ändere mal Zeile 183 in

        v = Math.round((v-5)*200)/10;
        
        1 Reply Last reply Reply Quote 0
        • B
          Beowolf last edited by

          Danke. Jetzt funktioniert es.

          paul53 1 Reply Last reply Reply Quote 0
          • paul53
            paul53 @Beowolf last edited by

            @Beowolf sagte:

            Jetzt funktioniert es

            Dann markiere bitte das Thema als [gelöst].

            1 Reply Last reply Reply Quote 0
            • inline
              inline last edited by

              Hallo,

              ich bin der Author des Originalbeitrags

              [https://www.forum.iobroker.net/topic/15963/skript-zum-auslesen-der-s-usv]

              und würde gerne den Fehler dort beheben. Leider bekommem auch ich eine Meldung "Es scheint als hättest du die Verbindung zu ioBroker Community verloren, bitte warte während wir versuchen sie wieder aufzubauen." wenn ich auf den Beitrag gehen.

              Kann mir hier jemand helfen?

              Danke
              Ralf

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

              Support us

              ioBroker
              Community Adapters
              Donate

              418
              Online

              31.8k
              Users

              80.0k
              Topics

              1.3m
              Posts

              javascript
              3
              5
              414
              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