Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Skript zum Auslesen der S.USV

    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

    Skript zum Auslesen der S.USV

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

      Hallo,

      auf Anraten von Sascha (dodi666) gibt es jetzt einen eigenen Thread für mein S.USV Skript.

      Unter www.s-usv.com sind verschiedene Varianten der "S.USV Pi uninterrupted power supply" erhältlich.

      Dies sind Aufsteckplatinen für den Raspberry Pi, die eine unterbrechungsfreie Stromversorgung ermöglichen und insbesondere auch ein Wiederanlaufen bei Rückkehr des Stomnetzes erlauben.

      Zur Ansteuerung der S.USV wird ein Daemon installiert, der sich um das Herunterfahren (auch zeitgesteuert) kümmert.

      Dazu gibt es ein Program susv, mit dessen Hilfe man verschiedene Einstellungen vornehmen kann und vor allem auch den aktuellen Status abfragen kann. Letzteres macht dieses Skript und erzeugt aus dem Status eine Reihe von Datenpunkten:

      3241_susv_datenpunkte.gif

      Hier nun das 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);
      ! }

      Liebe Grüße,

      Ralf

      1 Reply Last reply Reply Quote 0
      • Dirk Peter
        Dirk Peter last edited by

        Hallo,

        habe das Skript auf meinem Tinker S mit Armbian 5.67 installiert. Bekomme aber folgende Fehler:

        javascript.0 | 2018-12-18 17:55:26.118 | info | Start javascript script.js.usv

        javascript.0 | 2018-12-18 17:55:26.147 | info | script.js.usv: registered 0 subscriptions and 0 schedules

        javascript.0 | 2018-12-18 17:56:26.191 | info | script.js.usv: Error: Command failed: /opt/susvd/susv -status

        javascript.0 | 2018-12-18 17:56:26.191 | info | Unable to open I2C device: Permission denied

        Die Abfrage der Zustände funktioniert aber ohne Probleme mit den gleichen Befehlen.

        root@tinkerboard:~# /opt/susvd/susv -status


        • S.USV solutions *

        • http://www.s-usv.com *

        • Model: Tinker *

        • Firmware Version: 2.60 *

        • Software Version: 2.40 *

        • Hardware Version: 2.1 *

        • Mail notification: Disabled *

        • Timed Boot: Disabled *

        • Boot time: 00:00:00 *

        • Timed Shutdown: Disabled *

        • Shutdown time: 00:00:00 *

        • Tue Dec 18 12:29:26 2018 *


        • Powering Source: Primary *

        • Charging circuit: ONLINE *

        • Charging current: 300 mA *

        • Voltage in: 4.99 V *

        • Battery capacity: 100.00% *

        • Battery voltage: 4.20V *

        • Power Battery: 000.00 mA *

        • Power Extern: 408.00 mA *

        • Shutdown timer: -1 *

        • Autostart: enabled *

        • Sleep timer: 1 *


        Hat einer eine Idee, wie ich das Skript zum laufen bekomme? Hat es vielleicht mit den Rechten zu tun?

        Danke im Vorraus,

        Liebe Grüße

        Dirk

        1 Reply Last reply Reply Quote 0
        • X
          xbow42 last edited by

          ich bin nicht der Linuxexperte, aber ich würde mal sagen ja.

          Der Benutzer unter dem das iobroker-skipt läuft hat nicht da Recht für den Zugriff auf das i2c-device der SUSV-Platine.

          Probier mal im Code die Zeile zu ändern.

          exec('sudo susv -status', function(err, stdout, stderr) {
          

          evtl hilft auch das consolenkomando

          sudo usermod -G i2c http
          

          wobei http ggf. durch den iobroker-Benutzernamen ersetzt werden muss.

          1 Reply Last reply Reply Quote 0
          • Dirk Peter
            Dirk Peter last edited by

            Hallo xbow42,

            danke für deine Antwort.

            Es hat aber leider nichts gebracht. Im Befehl exec( … ) darf sudo nicht verwendet werden und

            sudo usermod -G i2c http

            hat auch nichts gebracht.

            Trotzdem Danke

            1 Reply Last reply Reply Quote 0
            • Dirk Peter
              Dirk Peter last edited by

              Hallo,

              Lösung für Rechteproblem mit i²c:

              sudo chmod 666 /dev/i2c-1

              auf dem Terminal eingeben und die Abfrage läuft auch unter ASUS Tinker mit S.USV und pivccu, HomeMatic, ioBroker

              Danke für das Skript

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

                Liebes Forum,

                nicht dass mein Skript viele Fragen aufgeworfen hätte, aber der guten Ordnung halber möchte ich euch trotzdem mitteilen dass ich ab sofort keine großartige Hilfe mehr geben kann.

                Die Batterie meines SUSV ist schon wieder defekt und diesmal hat es auch die Platine erwischt. Da ich sowieso schon ewig keinen Stromausfall mehr hatte und das Ding doch recht teuer ist, werde ich es nicht ersetzen. Ich kann also nichts mehr testen.

                Liebe Grüße, nachträglich frohe Weihnachten und einen guten Rutsch!
                Ralf

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

                Support us

                ioBroker
                Community Adapters
                Donate

                719
                Online

                31.8k
                Users

                80.0k
                Topics

                1.3m
                Posts

                3
                6
                1096
                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