-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpowermon.ps1
33 lines (28 loc) · 1.02 KB
/
powermon.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Start-Transcript -path c:\windows\temp\powermon.log
write-host "Starting $(Get-Date -Format G)"
$batt = Get-WmiObject -Class Win32_Battery
#1 means on battery, 2 on ac power
If ($batt.BatteryStatus -like '1') {
'PowerStatus: On_Battery'
}
elseif ($batt.BatteryStatus -like '2') {
'PowerStatus: AC_Power'
}
$switchIP = "192.168.1.99"
#Sonoff S20 relay is on GPIO 12
#If charge is larger than 100, it means it is full/on ac power
if ($batt.EstimatedChargeRemaining -lt '100') {
'EstimatedChargeRemaining: ' + $batt.EstimatedChargeRemaining + '%'
if ($batt.EstimatedChargeRemaining -lt '40') {
$rv = Invoke-WebRequest -Uri "http://$switchIP/control?cmd=GPIO,12,1"
} else {
if ($batt.EstimatedChargeRemaining -gt '75') {
$rv = Invoke-WebRequest -Uri "http://$switchIP/control?cmd=GPIO,12,0"
}
}
} else {
'EstimatedChargeRemaining: 100%; Turning off charger...'
$rv = Invoke-WebRequest -Uri "http://$switchIP/control?cmd=GPIO,12,0"
}
write-host "Done $(Get-Date -Format G)"
Stop-Transcript