Fresh start - excluded large ROM JSON files
This commit is contained in:
29
scripts/get-battery-levels.ps1
Normal file
29
scripts/get-battery-levels.ps1
Normal file
@@ -0,0 +1,29 @@
|
||||
$token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJmM2QzZWU1NGQyMWI0NGVkYWJmZGE4OGFiMTE3OTQ0MyIsImlhdCI6MTc2OTYxMzM0MiwiZXhwIjoyMDg0OTczMzQyfQ.L5atWZ-zyn-gA7QELxzRXoMnVilyz338hApOuL5MFas"
|
||||
$baseUrl = "http://192.168.0.39:8123/api/states/"
|
||||
$sensors = @(
|
||||
"sensor.front_door_battery",
|
||||
"sensor.pantry_door_sensor_battery",
|
||||
"sensor.garage_entrance_door_battery",
|
||||
"sensor.office_door_sensor_battery",
|
||||
"sensor.master_closet_door_sensor_battery",
|
||||
"sensor.shower_door_battery",
|
||||
"sensor.hue_motion_sensor_2_battery",
|
||||
"sensor.hue_motion_sensor_3_battery",
|
||||
"sensor.motion_sensor_battery_state",
|
||||
"sensor.pir_battery",
|
||||
"sensor.guest_bath_motion_battery",
|
||||
"sensor.master_bath_motion_battery",
|
||||
"sensor.office_motion_battery",
|
||||
"sensor.master_pooper_battery"
|
||||
)
|
||||
|
||||
foreach ($sensor in $sensors) {
|
||||
try {
|
||||
$r = Invoke-WebRequest -Uri ($baseUrl + $sensor) -Headers @{Authorization="Bearer " + $token} -TimeoutSec 3
|
||||
$s = $r.Content | ConvertFrom-Json
|
||||
$unit = if ($s.attributes.unit_of_measurement) { $s.attributes.unit_of_measurement } else { "-" }
|
||||
Write-Host "$($sensor): $($s.state) $unit"
|
||||
} catch {
|
||||
Write-Host "$sensor - ERROR"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user