Hallo!
Sry, die Mailbenachrichtung ist irgendwo untergegangen.
Ich hab das derzeit relativ kompliziert gelöst, aber es funktioniert.
Als erstes legst du eine Datei batLog.sh mit diesem Inhalt an.
akku=$(/usr/sbin/ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.0f", $10/$5 * 100)}')
cCapacity=$(/usr/sbin/ioreg -n AppleSmartBattery -r | awk 'BEGIN { ORS = ":" } /"CurrentCapacity"/{ print $3}')
mCapacity=$(/usr/sbin/ioreg -n AppleSmartBattery -r | awk 'BEGIN { ORS = ":" } /MaxCapacity/{ print $3}')
dCapacity=$(/usr/sbin/ioreg -n AppleSmartBattery -r | awk 'BEGIN { ORS = ":" } /DesignCapacity/{ print $3}')
temp=$(/usr/sbin/ioreg -n AppleSmartBattery -r | awk 'BEGIN { ORS = ":" } /Temperature/{ print $3/100}')
cycle=$(/usr/sbin/ioreg -n AppleSmartBattery -r | awk 'BEGIN { ORS = ":" } /CycleCount/{ print $3}')
charging=$(/usr/sbin/ioreg -n AppleSmartBattery -r | awk 'BEGIN { ORS = ":" } /IsCharging/{ print $3}')
fullyCharged=$(/usr/sbin/ioreg -n AppleSmartBattery -r | awk 'BEGIN { ORS = ":" } /FullyCharged/{ print $3}')
curl -k "http://IP:PORT/fhem?cmd=set%20macbookairTrigger%20$akku%20$charging%20$fullyCharged%20$cycle%20$cCapacity%20$mCapacity%20$dCapacity%20$temp"
IP und PORT musst du ersetzen.
In FHEM legst du dir 2 dummys und ein notify an.
define macbookair dummy
attr macbookair event-on-change-reading .*
attr macbookair stateFormat akku %
define macbookairTrigger dummy
define n_macbookairTrigger notify macbookairTrigger.* { macbookair($EVENT);; }
In deine 99_myUtils.pm kommt:
sub macbookair($){
my ($event) = @_;
my $device = "macbookair";
my $hash = $main::defs{$device};
my ($akku, $charging, $fullyCharged, $cycle, $cCapacity, $mCapacity, $dCapacity, $capacity, $temp );
my @split;
my @a = split( / /, $event );
$akku = $a[0];
@split = split(/:/, $a[1]);
$charging = $split[0];
@split = split(/:/, $a[2]);
$fullyCharged = $split[0];
@split = split(/:/, $a[3]);
$cycle = $split[0];
@split = split(/:/, $a[4]);
$cCapacity = $split[0];
@split = split(/:/, $a[5]);
$mCapacity = $split[0];
@split = split(/:/, $a[6]);
$dCapacity = $split[0];
@split = split(/:/, $a[7]);
$temp = $split[0];
$temp =~ s/,/./g;
$capacity = sprintf("%i", $mCapacity * 100 / $dCapacity);
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "akku", $akku );
readingsBulkUpdate($hash, "charging", $charging );
readingsBulkUpdate($hash, "fullyCharged", $fullyCharged );
readingsBulkUpdate($hash, "cycle", $cycle );
readingsBulkUpdate($hash, "currentCapacity", $cCapacity );
readingsBulkUpdate($hash, "maxCapacity", $mCapacity );
readingsBulkUpdate($hash, "designCapacity", $dCapacity );
readingsBulkUpdate($hash, "capacity", $capacity );
readingsBulkUpdate($hash, "temp", $temp );
readingsEndUpdate($hash, 1);
}
Jetzt muss nur noch ein CronJob eingerichtet werden, damit die batLog.sh regelmäßig aufgerufen wird. Dazu Terminal aufrufen und
crontab -e
eingeben und bestätigen.
Es öffnet sich eine neue Datei.
- Mit i kommt man in den insert-mode.
- Mit ESC wird dieser wieder verlassen.
- Mit :quit wird die Datei wieder geschlossen.
In diese Datei kommt zB
* * * * * sh /Pfad/zur/batLog.sh
Dieser Befehl ruft die batLog.sh jede Minute auf.
Anschließend sollten in dem macbookair dummy die Readings abgebildet sein.
Grüße