Einbindung einer APC Back-UPS USV (USB) in Loxone
Dieser Artikel beschreibt die Einbindung einer APC Back-UPS Notstromversorgung in die Loxone-Visualisierung.
Voraussetzung
Voraussetzung ist ein Server, welcher die Umsetzung von USB auf IP macht.
Zum Beispiel ein LoxBerry mit dem APC-UPS Plugin.
Schritt-für-Schritt-Anleitung
Zuerst muss ein Server aufgesetzt werden, welcher über USB an die unterbrechungsfreie Stromversorgung (USV) angeschlossen wird.
Wenn ein LoxBerry mit dem APC-UPS Plugin verwendet wird, entfällt Schritt 1 - dies wäre dann die Installation des Plugins auf dem LoxBerry inkl. Neustart.
Ich habe einen Raspberry Pi verwendet, da ich diesen sowieso habe und er noch andere Dinge tut, die Loxone nicht selbst kann.
Zur Raspbian Grundinstallation schreibe ich hier daher nichts, da es dazu genügend Tutorials im Netz gibt.
Also das Paket installiert:Installation des APC UPS Däemon
sudo apt-get install apcupsdJetzt die Konfiguration anpassen - hier ist meine:
/etc/apcupsd/apcupsd.conf
UPSNAME Back-UPS UPSCABLE usb UPSTYPE usb LOCKFILE /var/lock SCRIPTDIR /etc/apcupsd PWRFAILDIR /etc/apcupsd NOLOGINDIR /etc ONBATTERYDELAY 2 BATTERYLEVEL 5 MINUTES 3 TIMEOUT 0 ANNOY 300 ANNOYDELAY 60 NOLOGON disable KILLDELAY 0 NETSERVER on NISIP 0.0.0.0 NISPORT 3551 EVENTSFILE /var/log/apcupsd.events EVENTSFILEMAX 10 UPSCLASS standalone UPSMODE disable STATTIME 0 STATFILE /var/log/apcupsd.status LOGSTATS off DATATIME 0Mit den folgenden Kommandos kann man den Daemon starten und den Status auslesen:
USV-Status auslesen
service apcupsd restart service apcupsd statusAuf dem oben konfigurierten
NISPort 3551ist die USV nun vom Miniserver aus ansprechbar.Jetzt habe ich in der Loxone Config ein Programmbaustein eingefügt und die Ausgänge verbunden:
Das Programm sieht wie folgt aus - in Zeile 12 ist der Hostname
raspberry.piund derPortgegebenenfalls durch eigene Werte zu ersetzen :Loxone-Programm
char* p,*pS; char* cStatus; char* cBattdate; char* cModel; char szBuffer[1500]; int nLen; int bOnline = 0; double dCharge,dLoad,dLinev,dTimeleft,dBattv,dTonbatt,dCumonbatt,dOutputv; //printf("Starting USV APC BackUPS 1500 watch"); while(TRUE) { STREAM* stream = stream_create("/dev/tcp/192.168.178.254/3551",0,0); if (stream != NULL) { szBuffer[0] = 0; szBuffer[1] = 6; stream_write(stream,szBuffer,2); stream_flush(stream); stream_write(stream,"status",6); stream_flush(stream); nLen = stream_read(stream,szBuffer,2,1000); nLen = stream_read(stream,szBuffer,sizeof(szBuffer) - 1,1000); stream_close(stream); szBuffer[nLen] = 0; szBuffer[nLen + 1] = 0; //printf("APC BufferLen=%d",nLen); pS = szBuffer; while(*pS) { //MODEL : UPS model derived from UPS information p = strstr(pS,"MODEL :"); if (p != NULL) { cModel = strstrskip(p,"MODEL : "); //printf("APC Model=%s",cModel); setoutputtext(0,cModel); } //STATUS : UPS status (online, charging, on battery etc) p = strstr(pS,"STATUS :"); if (p != NULL) { cStatus = strstrskip(p,"STATUS : "); //printf("APC Status=%s",cStatus); setoutputtext(1,cStatus); p = strstr(pS,"ONLINE"); if (p != NULL) setoutput(0,0); else setoutput(0,1); } //LINEV : Current input line voltage p = strstr(pS,"LINEV :"); if (p != NULL) { dLinev = batof(p + 11); setoutput(1,dLinev); //printf("APC Linev=%f",dLinev); } //LOADPCT : Percentage of UPS load capacity used as estimated by UPS p = strstr(pS,"LOADPCT :"); if (p != NULL) { dLoad = batof(p + 11); setoutput(2,dLoad); //printf("APC Load=%f",dLoad); } //BCHARGE : Current battery capacity charge percentage p = strstr(pS,"BCHARGE :"); if (p != NULL) { dCharge = batof(p + 11); setoutput(3,dCharge); //printf("APC Bcharge=%f",dCharge); } //TIMELEFT: Remaining runtime left on battery as estimated by the UPS p = strstr(pS,"TIMELEFT :"); if (p != NULL) { dTimeleft = batof(p + 11); setoutput(4,dTimeleft); //printf("APC Timeleft=%f",dTimeleft); } //BATTV : Current battery voltage p = strstr(pS,"BATTV :"); if (p != NULL) { dBattv = batof(p + 11); setoutput(5,dBattv); //printf("APC Battv=%f",dBattv); } //TONBATT :Seconds currently on battery p = strstr(pS,"TONBATT :"); if (p != NULL) { dTonbatt = batof(p + 11); setoutput(6,dTonbatt); //printf("APC Tonbatt=%f",dTonbatt); } //CUMONBATT : Cumulative seconds on battery since apcupsd startup p = strstr(pS,"CUMONBATT:"); if (p != NULL) { dCumonbatt = batof(p + 11); setoutput(7,dCumonbatt); } //BATTDATE: Date battery last replaced (if set) p = strstr(pS,"BATTDATE :"); if (p != NULL) { cBattdate = strstrskip(p,"BATTDATE : "); //printf("APC Battdate=%s",cBattdate); setoutputtext(2,cBattdate); } //OUTPUTV: Output voltage p = strstr(pS,"OUTPUTV :"); if (p != NULL) { dOutputv = batof(p + 11); setoutput(8,dOutputv); } pS += (strlen(pS) + 1); } sleeps(15); } else { //printf("APC no connection"); sleeps(15); // wait 15 seconds } }Hier die Loxone-Konfig-Datei zum Download:
Die Zeilen mit
printferzeugen eine Ausgabe im Log-Tab der Loxone Config (ganz unten) und können im Produktivbetrieb mit einem vorangestellten//auskommentiert werden.Fertig sieht es dann so aus:
Getestet mit Loxone Config 7.3.2.24, Raspbian 7.8 und APC Back-UPS (UPS=Uninterruptible Power Supply)