auf Anraten von Sascha (dodi666) gibt es jetzt einen eigenen Thread für mein S.USV Skript.
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.
! // 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);
! }